Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions src/libstore/include/nix/store/globals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -735,29 +735,6 @@ public:
duplicate files.
)"};

Setting<bool> 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> sandboxMode{
this,
#ifdef __linux__
Expand Down Expand Up @@ -1423,15 +1400,6 @@ public:
true, // document default
Xp::ConfigurableImpureEnv};

Setting<std::string> 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<uint64_t> warnLargePathThreshold{
this,
0,
Expand Down
42 changes: 38 additions & 4 deletions src/nix/nix-env/nix-env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -34,6 +35,39 @@
using namespace nix;
using std::cout;

/**
* Settings related to Nix user environments.
*/
struct EnvSettings : Config
{
Setting<bool> 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
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
27 changes: 25 additions & 2 deletions src/nix/upgrade-nix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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;
Expand All @@ -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},
});
}

Expand Down Expand Up @@ -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<EvalState>(LookupPath{}, store, fetchSettings, evalSettings);
Expand Down
Loading