globals.hh 6.6 KB

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