diff --git a/src/libstore/include/nix/store/globals.hh b/src/libstore/include/nix/store/globals.hh index 439416fc00c..f4014e7b8fd 100644 --- a/src/libstore/include/nix/store/globals.hh +++ b/src/libstore/include/nix/store/globals.hh @@ -735,29 +735,6 @@ public: duplicate files. )"}; - Setting envKeepDerivations{ - this, - false, - "keep-env-derivations", - R"( - If `false` (default), derivations are not stored in Nix user - environments. That is, the derivations of any build-time-only - dependencies may be garbage-collected. - - If `true`, when you add a Nix derivation to a user environment, the - path of the derivation is stored in the user environment. Thus, the - derivation isn't garbage-collected until the user environment - generation is deleted (`nix-env --delete-generations`). To prevent - build-time-only dependencies from being collected, you should also - turn on `keep-outputs`. - - The difference between this option and `keep-derivations` is that - this one is “sticky”: it applies to any user environment created - while this option was enabled, while `keep-derivations` only applies - at the moment the garbage collector is run. - )", - {"env-keep-derivations"}}; - Setting sandboxMode{ this, #ifdef __linux__ @@ -1423,15 +1400,6 @@ public: true, // document default Xp::ConfigurableImpureEnv}; - Setting upgradeNixStorePathUrl{ - this, - "https://github.com/NixOS/nixpkgs/raw/master/nixos/modules/installer/tools/nix-fallback-paths.nix", - "upgrade-nix-store-path-url", - R"( - Used by `nix upgrade-nix`, the URL of the file that contains the - store paths of the latest Nix release. - )"}; - Setting warnLargePathThreshold{ this, 0, diff --git a/src/nix/nix-env/nix-env.cc b/src/nix/nix-env/nix-env.cc index 31aa2b3f2cd..8047fd30593 100644 --- a/src/nix/nix-env/nix-env.cc +++ b/src/nix/nix-env/nix-env.cc @@ -5,6 +5,7 @@ #include "nix/expr/eval.hh" #include "nix/expr/get-drvs.hh" #include "nix/store/globals.hh" +#include "nix/util/config-global.hh" #include "nix/store/names.hh" #include "nix/store/profiles.hh" #include "nix/store/path-with-outputs.hh" @@ -34,6 +35,39 @@ using namespace nix; using std::cout; +/** + * Settings related to Nix user environments. + */ +struct EnvSettings : Config +{ + Setting keepDerivations{ + this, + false, + "keep-env-derivations", + R"( + If `false` (default), derivations are not stored in Nix user + environments. That is, the derivations of any build-time-only + dependencies may be garbage-collected. + + If `true`, when you add a Nix derivation to a user environment, the + path of the derivation is stored in the user environment. Thus, the + derivation isn't garbage-collected until the user environment + generation is deleted (`nix-env --delete-generations`). To prevent + build-time-only dependencies from being collected, you should also + turn on `keep-outputs`. + + The difference between this option and `keep-derivations` is that + this one is "sticky": it applies to any user environment created + while this option was enabled, while `keep-derivations` only applies + at the moment the garbage collector is run. + )", + {"env-keep-derivations"}}; +}; + +EnvSettings envSettings; + +static GlobalConfig::Register rSettings(&envSettings); + typedef enum { srcNixExprDrvs, srcNixExprs, srcStorePaths, srcProfile, srcAttrPath, srcUnknown } InstallSourceType; struct InstallSourceInfo @@ -546,7 +580,7 @@ installDerivations(Globals & globals, const Strings & args, const Path & profile if (globals.dryRun) return; - if (createUserEnv(*globals.state, allElems, profile, settings.envKeepDerivations, lockToken)) + if (createUserEnv(*globals.state, allElems, profile, envSettings.keepDerivations, lockToken)) break; } } @@ -657,7 +691,7 @@ static void upgradeDerivations(Globals & globals, const Strings & args, UpgradeT if (globals.dryRun) return; - if (createUserEnv(*globals.state, newElems, globals.profile, settings.envKeepDerivations, lockToken)) + if (createUserEnv(*globals.state, newElems, globals.profile, envSettings.keepDerivations, lockToken)) break; } } @@ -716,7 +750,7 @@ static void opSetFlag(Globals & globals, Strings opFlags, Strings opArgs) checkSelectorUse(selectors); /* Write the new user environment. */ - if (createUserEnv(*globals.state, installedElems, globals.profile, settings.envKeepDerivations, lockToken)) + if (createUserEnv(*globals.state, installedElems, globals.profile, envSettings.keepDerivations, lockToken)) break; } } @@ -799,7 +833,7 @@ static void uninstallDerivations(Globals & globals, Strings & selectors, Path & if (globals.dryRun) return; - if (createUserEnv(*globals.state, workingElems, profile, settings.envKeepDerivations, lockToken)) + if (createUserEnv(*globals.state, workingElems, profile, envSettings.keepDerivations, lockToken)) break; } } diff --git a/src/nix/upgrade-nix.cc b/src/nix/upgrade-nix.cc index ae1fe2b37d8..2dedb53c76a 100644 --- a/src/nix/upgrade-nix.cc +++ b/src/nix/upgrade-nix.cc @@ -9,10 +9,33 @@ #include "nix/store/names.hh" #include "nix/util/executable-path.hh" #include "nix/store/globals.hh" +#include "nix/util/config-global.hh" #include "self-exe.hh" using namespace nix; +/** + * Settings related to upgrading Nix itself. + */ +struct UpgradeSettings : Config +{ + /** + * The URL of the file that contains the store paths of the latest Nix release. + */ + Setting storePathUrl{ + this, + "https://github.com/NixOS/nixpkgs/raw/master/nixos/modules/installer/tools/nix-fallback-paths.nix", + "upgrade-nix-store-path-url", + R"( + Used by `nix upgrade-nix`, the URL of the file that contains the + store paths of the latest Nix release. + )"}; +}; + +UpgradeSettings upgradeSettings; + +static GlobalConfig::Register rSettings(&upgradeSettings); + struct CmdUpgradeNix : MixDryRun, StoreCommand { std::filesystem::path profileDir; @@ -31,7 +54,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand .longName = "nix-store-paths-url", .description = "The URL of the file that contains the store paths of the latest Nix release.", .labels = {"url"}, - .handler = {&(std::string &) settings.upgradeNixStorePathUrl}, + .handler = {&(std::string &) upgradeSettings.storePathUrl}, }); } @@ -156,7 +179,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand Activity act(*logger, lvlInfo, actUnknown, "querying latest Nix version"); // FIXME: use nixos.org? - auto req = FileTransferRequest(parseURL(settings.upgradeNixStorePathUrl.get())); + auto req = FileTransferRequest(parseURL(upgradeSettings.storePathUrl.get())); auto res = getFileTransfer()->download(req); auto state = std::make_unique(LookupPath{}, store, fetchSettings, evalSettings);