globals.hh 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 internal helper programs are stored. */
  38. Path nixLibexecDir;
  39. /* The directory where the main programs are stored. */
  40. Path nixBinDir;
  41. /* File name of the socket the daemon listens to. */
  42. Path nixDaemonSocketFile;
  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. /* The substituters. There are programs that can somehow realise
  79. a store path without building, e.g., by downloading it or
  80. copying it from a CD. */
  81. Paths substituters;
  82. /* Whether to use build hooks (for distributed builds). Sometimes
  83. users want to disable this from the command-line. */
  84. bool useBuildHook;
  85. /* Whether buildDerivations() should print out lines on stderr in
  86. a fixed format to allow its progress to be monitored. Each
  87. line starts with a "@". The following are defined:
  88. @ build-started <drvpath> <outpath> <system> <logfile> <pid>
  89. @ build-failed <drvpath> <outpath> <exitcode> <error text>
  90. @ build-succeeded <drvpath> <outpath>
  91. @ substituter-started <outpath> <substituter>
  92. @ substituter-failed <outpath> <exitcode> <error text>
  93. @ substituter-succeeded <outpath>
  94. Best combined with --no-build-output, otherwise stderr might
  95. conceivably contain lines in this format printed by the
  96. builders. */
  97. bool printBuildTrace;
  98. /* When true, 'buildDerivations' prefixes lines coming from builders so
  99. that clients know exactly which line comes from which builder, and
  100. which line comes from the daemon itself. The prefix for data coming
  101. from builders is "log:PID:LEN:DATA" where PID uniquely identifies the
  102. builder (PID is given in "build-started" traces.) */
  103. bool multiplexedBuildOutput;
  104. /* Amount of reserved space for the garbage collector
  105. (/nix/var/nix/db/reserved). */
  106. off_t reservedSize;
  107. /* Whether SQLite should use fsync. */
  108. bool fsyncMetadata;
  109. /* Whether SQLite should use WAL mode. */
  110. bool useSQLiteWAL;
  111. /* Whether to call sync() before registering a path as valid. */
  112. bool syncBeforeRegistering;
  113. /* Whether to use substitutes. */
  114. bool useSubstitutes;
  115. /* The Unix group that contains the build users. */
  116. string buildUsersGroup;
  117. /* Whether to build in chroot. */
  118. bool useChroot;
  119. /* Whether to impersonate a Linux 2.6 machine on newer kernels. */
  120. bool impersonateLinux26;
  121. /* Whether to store build logs. */
  122. bool keepLog;
  123. /* Whether to compress logs. */
  124. enum CompressionType logCompression;
  125. /* Maximum number of bytes a builder can write to stdout/stderr
  126. before being killed (0 means no limit). */
  127. unsigned long maxLogSize;
  128. /* Whether to cache build failures. */
  129. bool cacheFailure;
  130. /* How often (in seconds) to poll for locks. */
  131. unsigned int pollInterval;
  132. /* Whether to check if new GC roots can in fact be found by the
  133. garbage collector. */
  134. bool checkRootReachability;
  135. /* Whether the garbage collector should keep outputs of live
  136. derivations. */
  137. bool gcKeepOutputs;
  138. /* Whether the garbage collector should keep derivers of live
  139. paths. */
  140. bool gcKeepDerivations;
  141. /* Whether to automatically replace files with identical contents
  142. with hard links. */
  143. bool autoOptimiseStore;
  144. /* Whether to add derivations as a dependency of user environments
  145. (to prevent them from being GCed). */
  146. bool envKeepDerivations;
  147. /* Whether to lock the Nix client and worker to the same CPU. */
  148. bool lockCPU;
  149. /* Whether to show a stack trace if Nix evaluation fails. */
  150. bool showTrace;
  151. private:
  152. SettingsMap settings, overrides;
  153. void _get(string & res, const string & name);
  154. void _get(bool & res, const string & name);
  155. void _get(StringSet & res, const string & name);
  156. void _get(Strings & res, const string & name);
  157. template<class N> void _get(N & res, const string & name);
  158. };
  159. // FIXME: don't use a global variable.
  160. extern Settings settings;
  161. extern const string nixVersion;
  162. }