diff options
-rw-r--r-- | doc/manual/conf-file.xml | 20 | ||||
-rw-r--r-- | nix.conf.example | 29 | ||||
-rw-r--r-- | src/libstore/globals.cc | 19 | ||||
-rw-r--r-- | src/libstore/globals.hh | 2 | ||||
-rw-r--r-- | src/libstore/store.cc | 6 |
5 files changed, 62 insertions, 14 deletions
diff --git a/doc/manual/conf-file.xml b/doc/manual/conf-file.xml index 629dd3bac788..9ff34324f20f 100644 --- a/doc/manual/conf-file.xml +++ b/doc/manual/conf-file.xml @@ -52,6 +52,26 @@ env-keep-derivations = false </varlistentry> + <varlistentry id="conf-gc-reserved-space"><term><literal>gc-reserved-space</literal></term> + + <listitem><para>This option specifies how much space should be + reserved in normal use so that the garbage collector can run + succesfully. Since the garbage collector must perform Berkeley DB + transactions, it needs some disk space for itself. However, when + the disk is full, this space is not available, so the collector + would not be able to run precisely when it is most needed.</para> + + <para>For this reason, when Nix is run, it allocates a file + <filename>/nix/var/nix/db/reserved</filename> of the size + specified by this option. When the garbage collector is run, this + file is deleted before the Berkeley DB environment is opened. + This should give it enough room to proceed.</para> + + <para>The default is <literal>1048576</literal> (1 + MiB).</para></listitem> + + </varlistentry> + <varlistentry><term><literal>env-keep-derivations</literal></term> <listitem><para>If <literal>false</literal> (default), derivations diff --git a/nix.conf.example b/nix.conf.example index e2735d180760..97c6f4b15c05 100644 --- a/nix.conf.example +++ b/nix.conf.example @@ -11,7 +11,7 @@ # build time (e.g., the C compiler, or source tarballs downloaded from # the network). To prevent it from doing so, set this option to # `true'. -gc-keep-outputs = false +#gc-keep-outputs = false ### Option `gc-keep-derivations' @@ -26,7 +26,26 @@ gc-keep-outputs = false # store path was built), so by default this option is on. Turn it off # to safe a bit of disk space (or a lot if `gc-keep-outputs' is also # turned on). -gc-keep-derivations = true +#gc-keep-derivations = true + + +### Option `gc-reserved-space' +# +# This option specifies how much space should be reserved in normal +# use so that the garbage collector can run succesfully. Since the +# garbage collector must perform Berkeley DB transactions, it needs +# some disk space for itself. However, when the disk is full, this +# space is not available, so the collector would not be able to run +# precisely when it is most needed. +# +# For this reason, when Nix is run, it allocates a file +# /nix/var/nix/db/reserved of the size specified by this option. When +# the garbage collector is run, this file is deleted before the +# Berkeley DB environment is opened. This should give it enough room +# to proceed. +# +# The default is "1048576" (1 MiB). +#gc-reserved-space = 1048576 ### Option `env-keep-derivations' @@ -46,7 +65,7 @@ gc-keep-derivations = true # this one is `sticky': it applies to any user environment created # while this option was enabled, while `gc-keep-derivations' only # applies at the moment the garbage collector is run. -env-keep-derivations = false +#env-keep-derivations = false ### Option `build-allow-root' @@ -56,7 +75,7 @@ env-keep-derivations = false # performed under the `root' user. If `false', builds are performed # under one of the users listed in the `build-users' option (see # below). -build-allow-root = true +#build-allow-root = true ### Option `build-users' @@ -77,4 +96,4 @@ build-allow-root = true # # Example: # build-users = nix-builder-1 nix-builder-2 nix-builder-3 -build-users = +#build-users = diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc index a69bc0c30307..fc338892f22d 100644 --- a/src/libstore/globals.cc +++ b/src/libstore/globals.cc @@ -75,17 +75,22 @@ Strings querySetting(const string & name, const Strings & def) } -bool queryBoolSetting(const string & name, bool def) +string querySetting(const string & name, const string & def) { Strings defs; - if (def) defs.push_back("true"); else defs.push_back("false"); - + defs.push_back(def); + Strings value = querySetting(name, defs); if (value.size() != 1) - throw Error(format("configuration option `%1%' should be either `true' or `false', not a list") - % name); - - string v = value.front(); + throw Error(format("configuration option `%1%' should not be a list") % name); + + return value.front(); +} + + +bool queryBoolSetting(const string & name, bool def) +{ + string v = querySetting(name, def ? "true" : "false"); if (v == "true") return true; else if (v == "false") return false; else throw Error(format("configuration option `%1%' should be either `true' or `false', not `%2%'") diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh index cb199fd3692f..b5de709f7b54 100644 --- a/src/libstore/globals.hh +++ b/src/libstore/globals.hh @@ -56,6 +56,8 @@ extern bool readOnlyMode; Strings querySetting(const string & name, const Strings & def); +string querySetting(const string & name, const string & def); + bool queryBoolSetting(const string & name, bool def); diff --git a/src/libstore/store.cc b/src/libstore/store.cc index 25e2d6e36009..94c992f22936 100644 --- a/src/libstore/store.cc +++ b/src/libstore/store.cc @@ -82,12 +82,14 @@ void openDB(bool reserveSpace) try { Path reservedPath = nixDBPath + "/reserved"; - off_t reservedSize = 1024 * 1024; + string s = querySetting("gc-reserved-space", ""); + int reservedSize; + if (!string2Int(s, reservedSize)) reservedSize = 1024 * 1024; if (reserveSpace) { struct stat st; if (stat(reservedPath.c_str(), &st) == -1 || st.st_size != reservedSize) - writeFile(reservedPath, string(1024 * 1024, 'X')); + writeFile(reservedPath, string(reservedSize, 'X')); } else deletePath(reservedPath); |