From 801cb161319148bca4c6d4e9daea0ccea1953b2e Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 24 Nov 2025 23:27:00 -0500 Subject: [PATCH] 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. --- src/nix/develop.cc | 36 +++++++++++++++++------------------ tests/functional/nix-shell.sh | 8 +++----- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/nix/develop.cc b/src/nix/develop.cc index 1eff735da..68ff3fcf9 100644 --- a/src/nix/develop.cc +++ b/src/nix/develop.cc @@ -272,26 +272,24 @@ static StorePath getDerivationEnvironment(ref store, ref evalStore drv.name += "-env"; drv.env.emplace("name", drv.name); drv.inputSrcs.insert(std::move(getEnvShPath)); - if (experimentalFeatureSettings.isEnabled(Xp::CaDerivations)) { - for (auto & output : drv.outputs) { - output.second = DerivationOutput::Deferred{}, drv.env[output.first] = hashPlaceholder(output.first); - } - } else { - for (auto & output : drv.outputs) { - output.second = DerivationOutput::Deferred{}; - drv.env[output.first] = ""; - } - auto hashesModulo = hashDerivationModulo(*evalStore, drv, true); - - for (auto & output : drv.outputs) { - Hash h = hashesModulo.hashes.at(output.first); - auto outPath = store->makeOutputPath(output.first, h, drv.name); - output.second = DerivationOutput::InputAddressed{ - .path = outPath, - }; - drv.env[output.first] = store->printStorePath(outPath); - } + for (auto & [outputName, output] : drv.outputs) { + std::visit( + overloaded{ + [&](const DerivationOutput::InputAddressed &) { + output = DerivationOutput::Deferred{}; + drv.env[outputName] = ""; + }, + [&](const DerivationOutput::CAFixed &) { + output = DerivationOutput::Deferred{}; + drv.env[outputName] = ""; + }, + [&](const auto &) { + // Do nothing for other types (CAFloating, Deferred, Impure) + }, + }, + output.raw); } + drv.fillInOutputPaths(*evalStore); auto shellDrvPath = writeDerivation(*evalStore, drv); diff --git a/tests/functional/nix-shell.sh b/tests/functional/nix-shell.sh index 2ff994c99..418857987 100755 --- a/tests/functional/nix-shell.sh +++ b/tests/functional/nix-shell.sh @@ -280,8 +280,6 @@ assert (!(args ? inNixShell)); EOF 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 - # shellcheck disable=SC2016 - nix develop -f "$shellDotNix" fixed -c bash -c '[[ -n $stdenv ]]' -fi +# `nix develop` should also work with fixed-output derivations +# shellcheck disable=SC2016 +nix develop -f "$shellDotNix" fixed -c bash -c '[[ -n $stdenv ]]'