14 /* The default location of the daemon socket, relative to nixStateDir.
15 The socket is in a directory to allow you to control access to the
16 Nix daemon by setting the mode/ownership of the directory
17 appropriately. (This wouldn't work on the socket itself since it
18 must be deleted and recreated on startup.) */
19 #define DEFAULT_SOCKET_PATH "/daemon-socket/socket"
30 buildVerbosity
= lvlError
;
38 printBuildTrace
= false;
39 reservedSize
= 8 * 1024 * 1024;
42 syncBeforeRegistering
= false;
43 useSubstitutes
= true;
45 useSshSubstituter
= false;
46 impersonateLinux26
= false;
52 checkRootReachability
= false;
53 gcKeepOutputs
= false;
54 gcKeepDerivations
= true;
55 autoOptimiseStore
= false;
56 envKeepDerivations
= false;
57 lockCPU
= getEnv("NIX_AFFINITY_HACK", "1") == "1";
59 enableImportNative
= false;
63 void Settings::processEnvironment()
65 nixStore
= canonPath(getEnv("NIX_STORE_DIR", getEnv("NIX_STORE", NIX_STORE_DIR
)));
66 nixDataDir
= canonPath(getEnv("NIX_DATA_DIR", NIX_DATA_DIR
));
67 nixLogDir
= canonPath(getEnv("NIX_LOG_DIR", NIX_LOG_DIR
));
68 nixStateDir
= canonPath(getEnv("NIX_STATE_DIR", NIX_STATE_DIR
));
69 nixDBPath
= getEnv("NIX_DB_DIR", nixStateDir
+ "/db");
70 nixConfDir
= canonPath(getEnv("GUIX_CONFIGURATION_DIRECTORY", GUIX_CONFIGURATION_DIRECTORY
));
71 nixLibexecDir
= canonPath(getEnv("NIX_LIBEXEC_DIR", NIX_LIBEXEC_DIR
));
72 nixBinDir
= canonPath(getEnv("NIX_BIN_DIR", NIX_BIN_DIR
));
73 nixDaemonSocketFile
= canonPath(nixStateDir
+ DEFAULT_SOCKET_PATH
);
77 void Settings::loadConfFile()
79 Path settingsFile
= (format("%1%/%2%") % nixConfDir
% "nix.conf").str();
80 if (!pathExists(settingsFile
)) return;
81 string contents
= readFile(settingsFile
);
85 while (pos
< contents
.size()) {
87 while (pos
< contents
.size() && contents
[pos
] != '\n')
88 line
+= contents
[pos
++];
91 string::size_type hash
= line
.find('#');
92 if (hash
!= string::npos
)
93 line
= string(line
, 0, hash
);
95 vector
<string
> tokens
= tokenizeString
<vector
<string
> >(line
);
96 if (tokens
.empty()) continue;
98 if (tokens
.size() < 2 || tokens
[1] != "=")
99 throw Error(format("illegal configuration line `%1%' in `%2%'") % line
% settingsFile
);
101 string name
= tokens
[0];
103 vector
<string
>::iterator i
= tokens
.begin();
105 settings
[name
] = concatStringsSep(" ", Strings(i
, tokens
.end())); // FIXME: slow
110 void Settings::set(const string
& name
, const string
& value
)
112 settings
[name
] = value
;
113 overrides
[name
] = value
;
117 string
Settings::get(const string
& name
, const string
& def
)
119 auto i
= settings
.find(name
);
120 if (i
== settings
.end()) return def
;
125 Strings
Settings::get(const string
& name
, const Strings
& def
)
127 auto i
= settings
.find(name
);
128 if (i
== settings
.end()) return def
;
129 return tokenizeString
<Strings
>(i
->second
);
133 bool Settings::get(const string
& name
, bool def
)
140 int Settings::get(const string
& name
, int def
)
148 void Settings::update()
150 _get(tryFallback
, "build-fallback");
151 _get(maxBuildJobs
, "build-max-jobs");
152 _get(buildCores
, "build-cores");
153 _get(thisSystem
, "system");
154 _get(maxSilentTime
, "build-max-silent-time");
155 _get(buildTimeout
, "build-timeout");
156 _get(reservedSize
, "gc-reserved-space");
157 _get(fsyncMetadata
, "fsync-metadata");
158 _get(useSQLiteWAL
, "use-sqlite-wal");
159 _get(syncBeforeRegistering
, "sync-before-registering");
160 _get(useSubstitutes
, "build-use-substitutes");
161 _get(buildUsersGroup
, "build-users-group");
162 _get(useChroot
, "build-use-chroot");
163 _get(impersonateLinux26
, "build-impersonate-linux-26");
164 _get(keepLog
, "build-keep-log");
165 _get(compressLog
, "build-compress-log");
166 _get(maxLogSize
, "build-max-log-size");
167 _get(cacheFailure
, "build-cache-failure");
168 _get(pollInterval
, "build-poll-interval");
169 _get(checkRootReachability
, "gc-check-reachability");
170 _get(gcKeepOutputs
, "gc-keep-outputs");
171 _get(gcKeepDerivations
, "gc-keep-derivations");
172 _get(autoOptimiseStore
, "auto-optimise-store");
173 _get(envKeepDerivations
, "env-keep-derivations");
174 _get(sshSubstituterHosts
, "ssh-substituter-hosts");
175 _get(useSshSubstituter
, "use-ssh-substituter");
176 _get(logServers
, "log-servers");
177 _get(enableImportNative
, "allow-unsafe-native-code-during-evaluation");
178 _get(useCaseHack
, "use-case-hack");
180 string subs
= getEnv("NIX_SUBSTITUTERS", "default");
181 if (subs
== "default") {
182 substituters
.clear();
184 if (getEnv("NIX_OTHER_STORES") != "")
185 substituters
.push_back(nixLibexecDir
+ "/nix/substituters/copy-from-other-stores.pl");
187 substituters
.push_back(nixLibexecDir
+ "/nix/substituters/download-using-manifests.pl");
188 substituters
.push_back(nixLibexecDir
+ "/nix/substituters/download-from-binary-cache.pl");
189 if (useSshSubstituter
)
190 substituters
.push_back(nixLibexecDir
+ "/nix/substituters/download-via-ssh");
192 substituters
= tokenizeString
<Strings
>(subs
, ":");
196 void Settings::_get(string
& res
, const string
& name
)
198 SettingsMap::iterator i
= settings
.find(name
);
199 if (i
== settings
.end()) return;
204 void Settings::_get(bool & res
, const string
& name
)
206 SettingsMap::iterator i
= settings
.find(name
);
207 if (i
== settings
.end()) return;
208 if (i
->second
== "true") res
= true;
209 else if (i
->second
== "false") res
= false;
210 else throw Error(format("configuration option `%1%' should be either `true' or `false', not `%2%'")
215 void Settings::_get(StringSet
& res
, const string
& name
)
217 SettingsMap::iterator i
= settings
.find(name
);
218 if (i
== settings
.end()) return;
220 Strings ss
= tokenizeString
<Strings
>(i
->second
);
221 res
.insert(ss
.begin(), ss
.end());
224 void Settings::_get(Strings
& res
, const string
& name
)
226 SettingsMap::iterator i
= settings
.find(name
);
227 if (i
== settings
.end()) return;
228 res
= tokenizeString
<Strings
>(i
->second
);
232 template<class N
> void Settings::_get(N
& res
, const string
& name
)
234 SettingsMap::iterator i
= settings
.find(name
);
235 if (i
== settings
.end()) return;
236 if (!string2Int(i
->second
, res
))
237 throw Error(format("configuration setting `%1%' should have an integer value") % name
);
241 string
Settings::pack()
244 foreach (SettingsMap::iterator
, i
, settings
) {
245 if (i
->first
.find('\n') != string::npos
||
246 i
->first
.find('=') != string::npos
||
247 i
->second
.find('\n') != string::npos
)
248 throw Error("illegal option name/value");
249 s
+= i
->first
; s
+= '='; s
+= i
->second
; s
+= '\n';
255 void Settings::unpack(const string
& pack
) {
256 Strings lines
= tokenizeString
<Strings
>(pack
, "\n");
257 foreach (Strings::iterator
, i
, lines
) {
258 string::size_type eq
= i
->find('=');
259 if (eq
== string::npos
)
260 throw Error("illegal option name/value");
261 set(i
->substr(0, eq
), i
->substr(eq
+ 1));
266 Settings::SettingsMap
Settings::getOverrides()
272 const string nixVersion
= PACKAGE_VERSION
;