| 1 | #include "config.h"
|
| 2 |
|
| 3 | #include "globals.hh"
|
| 4 | #include "util.hh"
|
| 5 |
|
| 6 | #include <map>
|
| 7 | #include <format>
|
| 8 |
|
| 9 | namespace nix {
|
| 10 |
|
| 11 |
|
| 12 | |
| 13 | The socket is in a directory to allow you to control access to the
|
| 14 | build daemon by setting the mode/ownership of the directory
|
| 15 | appropriately. (This wouldn't work on the socket itself since it
|
| 16 | must be deleted and recreated on startup.)
|
| 17 | #define DEFAULT_SOCKET_PATH "/daemon-socket/socket"
|
| 18 |
|
| 19 |
|
| 20 | Settings::Settings()
|
| 21 | {
|
| 22 | keepFailed = false;
|
| 23 | keepGoing = false;
|
| 24 | tryFallback = false;
|
| 25 | buildVerbosity = lvlError;
|
| 26 | maxBuildJobs = 1;
|
| 27 | buildCores = 1;
|
| 28 | readOnlyMode = false;
|
| 29 | thisSystem = SYSTEM;
|
| 30 | maxSilentTime = 3600;
|
| 31 | buildTimeout = 3600 * 24;
|
| 32 | useBuildHook = true;
|
| 33 | printBuildTrace = false;
|
| 34 | multiplexedBuildOutput = false;
|
| 35 | reservedSize = 8 * 1024 * 1024;
|
| 36 | fsyncMetadata = true;
|
| 37 | useSQLiteWAL = true;
|
| 38 | syncBeforeRegistering = false;
|
| 39 | useSubstitutes = true;
|
| 40 | useChroot = false;
|
| 41 | impersonateLinux26 = false;
|
| 42 | keepLog = true;
|
| 43 | logCompression = COMPRESSION_GZIP;
|
| 44 | maxLogSize = 0;
|
| 45 | cacheFailure = false;
|
| 46 | pollInterval = 5;
|
| 47 | checkRootReachability = false;
|
| 48 | gcKeepOutputs = false;
|
| 49 | gcKeepDerivations = true;
|
| 50 | autoOptimiseStore = false;
|
| 51 | envKeepDerivations = false;
|
| 52 | lockCPU = getEnv("NIX_AFFINITY_HACK", "1") == "1";
|
| 53 | showTrace = false;
|
| 54 | useHostLoopback = true;
|
| 55 | slirp4netns = SLIRP4NETNS;
|
| 56 | allowASLR = false;
|
| 57 | }
|
| 58 |
|
| 59 |
|
| 60 | void Settings::processEnvironment()
|
| 61 | {
|
| 62 | nixStore = canonPath(getEnv("NIX_STORE_DIR", getEnv("NIX_STORE", NIX_STORE_DIR)));
|
| 63 | nixLogDir = canonPath(getEnv("GUIX_LOG_DIRECTORY", NIX_LOG_DIR));
|
| 64 | nixStateDir = canonPath(getEnv("GUIX_STATE_DIRECTORY", NIX_STATE_DIR));
|
| 65 | nixDBPath = getEnv("GUIX_DATABASE_DIRECTORY", nixStateDir + "/db");
|
| 66 | nixConfDir = canonPath(getEnv("GUIX_CONFIGURATION_DIRECTORY", GUIX_CONFIGURATION_DIRECTORY));
|
| 67 | nixBinDir = canonPath(getEnv("NIX_BIN_DIR", NIX_BIN_DIR));
|
| 68 | nixDaemonSocketFile = canonPath(nixStateDir + DEFAULT_SOCKET_PATH);
|
| 69 | guixProgram = canonPath(getEnv("GUIX", nixBinDir + "/guix"));
|
| 70 | }
|
| 71 |
|
| 72 |
|
| 73 | void Settings::set(const string & name, const string & value)
|
| 74 | {
|
| 75 | settings[name] = value;
|
| 76 | }
|
| 77 |
|
| 78 |
|
| 79 | string Settings::get(const string & name, const string & def)
|
| 80 | {
|
| 81 | auto i = settings.find(name);
|
| 82 | if (i == settings.end()) return def;
|
| 83 | return i->second;
|
| 84 | }
|
| 85 |
|
| 86 |
|
| 87 | Strings Settings::get(const string & name, const Strings & def)
|
| 88 | {
|
| 89 | auto i = settings.find(name);
|
| 90 | if (i == settings.end()) return def;
|
| 91 | return tokenizeString<Strings>(i->second);
|
| 92 | }
|
| 93 |
|
| 94 |
|
| 95 | bool Settings::get(const string & name, bool def)
|
| 96 | {
|
| 97 | bool res = def;
|
| 98 | _get(res, name);
|
| 99 | return res;
|
| 100 | }
|
| 101 |
|
| 102 | int Settings::get(const string & name, int def)
|
| 103 | {
|
| 104 | int res = def;
|
| 105 | _get(res, name);
|
| 106 | return res;
|
| 107 | }
|
| 108 |
|
| 109 |
|
| 110 | void Settings::update()
|
| 111 | {
|
| 112 | _get(tryFallback, "build-fallback");
|
| 113 | _get(maxBuildJobs, "build-max-jobs");
|
| 114 | _get(buildCores, "build-cores");
|
| 115 | _get(thisSystem, "system");
|
| 116 | _get(multiplexedBuildOutput, "multiplexed-build-output");
|
| 117 | _get(maxSilentTime, "build-max-silent-time");
|
| 118 | _get(buildTimeout, "build-timeout");
|
| 119 | _get(reservedSize, "gc-reserved-space");
|
| 120 | _get(fsyncMetadata, "fsync-metadata");
|
| 121 | _get(useSQLiteWAL, "use-sqlite-wal");
|
| 122 | _get(syncBeforeRegistering, "sync-before-registering");
|
| 123 | _get(useSubstitutes, "build-use-substitutes");
|
| 124 | _get(buildUsersGroup, "build-users-group");
|
| 125 | _get(useChroot, "build-use-chroot");
|
| 126 | _get(impersonateLinux26, "build-impersonate-linux-26");
|
| 127 | _get(keepLog, "build-keep-log");
|
| 128 | |
| 129 | _get(maxLogSize, "build-max-log-size");
|
| 130 | _get(cacheFailure, "build-cache-failure");
|
| 131 | _get(pollInterval, "build-poll-interval");
|
| 132 | _get(checkRootReachability, "gc-check-reachability");
|
| 133 | _get(gcKeepOutputs, "gc-keep-outputs");
|
| 134 | _get(gcKeepDerivations, "gc-keep-derivations");
|
| 135 | _get(autoOptimiseStore, "auto-optimise-store");
|
| 136 | _get(envKeepDerivations, "env-keep-derivations");
|
| 137 | }
|
| 138 |
|
| 139 |
|
| 140 | void Settings::_get(string & res, const string & name)
|
| 141 | {
|
| 142 | SettingsMap::iterator i = settings.find(name);
|
| 143 | if (i == settings.end()) return;
|
| 144 | res = i->second;
|
| 145 | }
|
| 146 |
|
| 147 |
|
| 148 | void Settings::_get(bool & res, const string & name)
|
| 149 | {
|
| 150 | SettingsMap::iterator i = settings.find(name);
|
| 151 | if (i == settings.end()) return;
|
| 152 | if (i->second == "true") res = true;
|
| 153 | else if (i->second == "false") res = false;
|
| 154 | else throw Error(std::format("configuration option `{}' should be either `true' or `false', not `{}'",
|
| 155 | name, i->second));
|
| 156 | }
|
| 157 |
|
| 158 |
|
| 159 | void Settings::_get(StringSet & res, const string & name)
|
| 160 | {
|
| 161 | SettingsMap::iterator i = settings.find(name);
|
| 162 | if (i == settings.end()) return;
|
| 163 | res.clear();
|
| 164 | Strings ss = tokenizeString<Strings>(i->second);
|
| 165 | res.insert(ss.begin(), ss.end());
|
| 166 | }
|
| 167 |
|
| 168 | void Settings::_get(Strings & res, const string & name)
|
| 169 | {
|
| 170 | SettingsMap::iterator i = settings.find(name);
|
| 171 | if (i == settings.end()) return;
|
| 172 | res = tokenizeString<Strings>(i->second);
|
| 173 | }
|
| 174 |
|
| 175 |
|
| 176 | template<class N> void Settings::_get(N & res, const string & name)
|
| 177 | {
|
| 178 | SettingsMap::iterator i = settings.find(name);
|
| 179 | if (i == settings.end()) return;
|
| 180 | if (!string2Int(i->second, res))
|
| 181 | throw Error(std::format("configuration setting `{}' should have an integer value", name));
|
| 182 | }
|
| 183 |
|
| 184 |
|
| 185 | string Settings::pack()
|
| 186 | {
|
| 187 | string s;
|
| 188 | for (auto& i : settings) {
|
| 189 | if (i.first.find('\n') != string::npos ||
|
| 190 | i.first.find('=') != string::npos ||
|
| 191 | i.second.find('\n') != string::npos)
|
| 192 | throw Error("invalid option name/value");
|
| 193 | s += i.first; s += '='; s += i.second; s += '\n';
|
| 194 | }
|
| 195 | return s;
|
| 196 | }
|
| 197 |
|
| 198 |
|
| 199 | }
|