globals.hh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. #pragma once
  2. #include "config.h"
  3. #include "types.hh"
  4. #include <map>
  5. #include <sys/types.h>
  6. namespace nix {
  7. enum CompressionType
  8. {
  9. COMPRESSION_NONE = 0,
  10. COMPRESSION_GZIP = 1
  11. #if HAVE_BZLIB_H
  12. , COMPRESSION_BZIP2 = 2
  13. #endif
  14. };
  15. struct Settings {
  16. typedef std::map<string, string> SettingsMap;
  17. Settings();
  18. void processEnvironment();
  19. void set(const string & name, const string & value);
  20. string get(const string & name, const string & def);
  21. Strings get(const string & name, const Strings & def);
  22. bool get(const string & name, bool def);
  23. int get(const string & name, int def);
  24. void update();
  25. string pack();
  26. SettingsMap getOverrides();
  27. /* The directory where we store sources and derived files. */
  28. Path nixStore;
  29. /* The directory where we log various operations. */
  30. Path nixLogDir;
  31. /* The directory where state is stored. */
  32. Path nixStateDir;
  33. /* The directory where we keep the SQLite database. */
  34. Path nixDBPath;
  35. /* The directory where configuration files are stored. */
  36. Path nixConfDir;
  37. /* The directory where the main programs are stored. */
  38. Path nixBinDir;
  39. /* File name of the socket the daemon listens to. */
  40. Path nixDaemonSocketFile;
  41. /* Absolute file name of the 'guix' program. */
  42. Path guixProgram;
  43. /* Whether to keep temporary directories of failed builds. */
  44. bool keepFailed;
  45. /* Whether to keep building subgoals when a sibling (another
  46. subgoal of the same goal) fails. */
  47. bool keepGoing;
  48. /* User and groud id of the client issuing the build request. Used to set
  49. the owner and group of the kept temporary directories of failed
  50. builds. */
  51. uid_t clientUid;
  52. gid_t clientGid;
  53. /* Whether, if we cannot realise the known closure corresponding
  54. to a derivation, we should try to normalise the derivation
  55. instead. */
  56. bool tryFallback;
  57. /* Verbosity level for build output. */
  58. Verbosity buildVerbosity;
  59. /* Maximum number of parallel build jobs. 0 means unlimited. */
  60. unsigned int maxBuildJobs;
  61. /* Number of CPU cores to utilize in parallel within a build,
  62. i.e. by passing this number to Make via '-j'. 0 means that the
  63. number of actual CPU cores on the local host ought to be
  64. auto-detected. */
  65. unsigned int buildCores;
  66. /* Read-only mode. Don't copy stuff to the store, don't change
  67. the database. */
  68. bool readOnlyMode;
  69. /* The canonical system name, as returned by config.guess. */
  70. string thisSystem;
  71. /* The maximum time in seconds that a builer can go without
  72. producing any output on stdout/stderr before it is killed. 0
  73. means infinity. */
  74. time_t maxSilentTime;
  75. /* The maximum duration in seconds that a builder can run. 0
  76. means infinity. */
  77. time_t buildTimeout;
  78. /* Whether to use build hooks (for distributed builds). Sometimes
  79. users want to disable this from the command-line. */
  80. bool useBuildHook;
  81. /* Whether buildDerivations() should print out lines on stderr in
  82. a fixed format to allow its progress to be monitored. Each
  83. line starts with a "@". The following are defined:
  84. @ build-started <drvpath> <outpath> <system> <logfile> <pid>
  85. @ build-failed <drvpath> <outpath> <exitcode> <error text>
  86. @ build-succeeded <drvpath> <outpath>
  87. @ substituter-started <outpath> <substituter>
  88. @ substituter-failed <outpath> <exitcode> <error text>
  89. @ substituter-succeeded <outpath>
  90. Best combined with --no-build-output, otherwise stderr might
  91. conceivably contain lines in this format printed by the
  92. builders. */
  93. bool printBuildTrace;
  94. /* When true, 'buildDerivations' prefixes lines coming from builders so
  95. that clients know exactly which line comes from which builder, and
  96. which line comes from the daemon itself. The prefix for data coming
  97. from builders is "log:PID:LEN:DATA" where PID uniquely identifies the
  98. builder (PID is given in "build-started" traces.) */
  99. bool multiplexedBuildOutput;
  100. /* Amount of reserved space for the garbage collector
  101. (/nix/var/nix/db/reserved). */
  102. off_t reservedSize;
  103. /* Whether SQLite should use fsync. */
  104. bool fsyncMetadata;
  105. /* Whether SQLite should use WAL mode. */
  106. bool useSQLiteWAL;
  107. /* Whether to call sync() before registering a path as valid. */
  108. bool syncBeforeRegistering;
  109. /* Whether to use substitutes. */
  110. bool useSubstitutes;
  111. /* The Unix group that contains the build users. */
  112. string buildUsersGroup;
  113. /* Whether to build in chroot. */
  114. bool useChroot;
  115. /* Whether to impersonate a Linux 2.6 machine on newer kernels. */
  116. bool impersonateLinux26;
  117. /* Whether to store build logs. */
  118. bool keepLog;
  119. /* Whether to compress logs. */
  120. enum CompressionType logCompression;
  121. /* Maximum number of bytes a builder can write to stdout/stderr
  122. before being killed (0 means no limit). */
  123. unsigned long maxLogSize;
  124. /* Whether to cache build failures. */
  125. bool cacheFailure;
  126. /* How often (in seconds) to poll for locks. */
  127. unsigned int pollInterval;
  128. /* Whether to check if new GC roots can in fact be found by the
  129. garbage collector. */
  130. bool checkRootReachability;
  131. /* Whether the garbage collector should keep outputs of live
  132. derivations. */
  133. bool gcKeepOutputs;
  134. /* Whether the garbage collector should keep derivers of live
  135. paths. */
  136. bool gcKeepDerivations;
  137. /* Whether to automatically replace files with identical contents
  138. with hard links. */
  139. bool autoOptimiseStore;
  140. /* Whether to add derivations as a dependency of user environments
  141. (to prevent them from being GCed). */
  142. bool envKeepDerivations;
  143. /* Whether to lock the Nix client and worker to the same CPU. */
  144. bool lockCPU;
  145. /* Whether to show a stack trace if Nix evaluation fails. */
  146. bool showTrace;
  147. private:
  148. SettingsMap settings, overrides;
  149. void _get(string & res, const string & name);
  150. void _get(bool & res, const string & name);
  151. void _get(StringSet & res, const string & name);
  152. void _get(Strings & res, const string & name);
  153. template<class N> void _get(N & res, const string & name);
  154. };
  155. // FIXME: don't use a global variable.
  156. extern Settings settings;
  157. extern const string nixVersion;
  158. }