1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-28 21:21:00 +01:00

Simplify nix develop "gathering derivation environment"

Before, had some funny logic with an unnecessary is CA enabled branch,
and erroneous use of the comma operator. Now, take advantage of the new
`Derivation::fillInOutputPaths` to fill in input addresses (and output
path env vars) in a much-more lightweight manner.

Also, fix `nix develop` on fixed-output derivations so that weird things
don't happen when we have that experimental feature enabled.

As a slight behavior change, if the original derivation was
content-addressing this one will be too, but I really don't think that
matters --- if anything, it is a slight improvement for users that have
already opted into content-addressing anyways.
This commit is contained in:
John Ericson 2025-11-24 23:27:00 -05:00
parent e91b7d1732
commit 801cb16131
2 changed files with 20 additions and 24 deletions

View file

@ -272,26 +272,24 @@ static StorePath getDerivationEnvironment(ref<Store> store, ref<Store> evalStore
drv.name += "-env"; drv.name += "-env";
drv.env.emplace("name", drv.name); drv.env.emplace("name", drv.name);
drv.inputSrcs.insert(std::move(getEnvShPath)); drv.inputSrcs.insert(std::move(getEnvShPath));
if (experimentalFeatureSettings.isEnabled(Xp::CaDerivations)) { for (auto & [outputName, output] : drv.outputs) {
for (auto & output : drv.outputs) { std::visit(
output.second = DerivationOutput::Deferred{}, drv.env[output.first] = hashPlaceholder(output.first); overloaded{
} [&](const DerivationOutput::InputAddressed &) {
} else { output = DerivationOutput::Deferred{};
for (auto & output : drv.outputs) { drv.env[outputName] = "";
output.second = DerivationOutput::Deferred{}; },
drv.env[output.first] = ""; [&](const DerivationOutput::CAFixed &) {
} output = DerivationOutput::Deferred{};
auto hashesModulo = hashDerivationModulo(*evalStore, drv, true); drv.env[outputName] = "";
},
for (auto & output : drv.outputs) { [&](const auto &) {
Hash h = hashesModulo.hashes.at(output.first); // Do nothing for other types (CAFloating, Deferred, Impure)
auto outPath = store->makeOutputPath(output.first, h, drv.name); },
output.second = DerivationOutput::InputAddressed{ },
.path = outPath, output.raw);
};
drv.env[output.first] = store->printStorePath(outPath);
}
} }
drv.fillInOutputPaths(*evalStore);
auto shellDrvPath = writeDerivation(*evalStore, drv); auto shellDrvPath = writeDerivation(*evalStore, drv);

View file

@ -280,8 +280,6 @@ assert (!(args ? inNixShell));
EOF EOF
nix-shell "$TEST_ROOT"/shell-ellipsis.nix --run "true" nix-shell "$TEST_ROOT"/shell-ellipsis.nix --run "true"
if [[ -z ${NIX_TESTS_CA_BY_DEFAULT:-} ]]; then # `nix develop` should also work with fixed-output derivations
# `nix develop` should also work with fixed-output derivations # shellcheck disable=SC2016
# shellcheck disable=SC2016 nix develop -f "$shellDotNix" fixed -c bash -c '[[ -n $stdenv ]]'
nix develop -f "$shellDotNix" fixed -c bash -c '[[ -n $stdenv ]]'
fi