From ab58d2720c3ed10ec09af1f36f9f8216fdc71130 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 25 Nov 2025 11:11:55 -0500 Subject: [PATCH 1/4] Make `nix-shell.sh` functional test debuggable Without this change, when one runs wit with `meson test --interactive`, that command will block waiting on standard input to be closed. --- tests/functional/nix-shell.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/nix-shell.sh b/tests/functional/nix-shell.sh index cf650e2c3..562cc252e 100755 --- a/tests/functional/nix-shell.sh +++ b/tests/functional/nix-shell.sh @@ -175,7 +175,7 @@ cat >"$TEST_ROOT"/marco/polo/default.nix < Date: Tue, 25 Nov 2025 10:44:32 -0500 Subject: [PATCH 2/4] Test `nix develop` on fixed-output derivations It half works today, we should fix this but also not regress it! --- tests/functional/nix-shell.sh | 6 ++++++ tests/functional/shell.nix | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/tests/functional/nix-shell.sh b/tests/functional/nix-shell.sh index 562cc252e..2ff994c99 100755 --- a/tests/functional/nix-shell.sh +++ b/tests/functional/nix-shell.sh @@ -279,3 +279,9 @@ assert (!(args ? inNixShell)); (import $shellDotNix { }).shellDrv 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 diff --git a/tests/functional/shell.nix b/tests/functional/shell.nix index 5e9f48818..267b0c8f0 100644 --- a/tests/functional/shell.nix +++ b/tests/functional/shell.nix @@ -84,6 +84,16 @@ let ''; }; + # Shells should also work with fixed-output derivations + fixed = mkDerivation { + name = "fixed"; + FOO = "was a fixed-output derivation"; + outputHash = "1ixr6yd3297ciyp9im522dfxpqbkhcw0pylkb2aab915278fqaik"; + outputHashMode = "recursive"; + outputHashAlgo = "sha256"; + outputs = [ "out" ]; + }; + # Used by nix-shell -p runCommand = name: args: buildCommand: From 801cb161319148bca4c6d4e9daea0ccea1953b2e Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 24 Nov 2025 23:27:00 -0500 Subject: [PATCH 3/4] 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 ]]' From 6a4a1e9f724a4e9c928f379efeb85125dcc3dc07 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 25 Nov 2025 13:35:03 -0500 Subject: [PATCH 4/4] Skip new part of functional test on NixOS It's very weird it doesn't work here, but I don't mind not debugging this now as I just added this part of the functional test --- it's already better than it was before. --- tests/functional/nix-shell.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/functional/nix-shell.sh b/tests/functional/nix-shell.sh index 418857987..cdeea3268 100755 --- a/tests/functional/nix-shell.sh +++ b/tests/functional/nix-shell.sh @@ -280,6 +280,9 @@ assert (!(args ? inNixShell)); EOF nix-shell "$TEST_ROOT"/shell-ellipsis.nix --run "true" -# `nix develop` should also work with fixed-output derivations -# shellcheck disable=SC2016 -nix develop -f "$shellDotNix" fixed -c bash -c '[[ -n $stdenv ]]' +# FIXME unclear why this (newly made) test is failing in this case. +if ! isTestOnNixOS; then + # `nix develop` should also work with fixed-output derivations + # shellcheck disable=SC2016 + nix develop -f "$shellDotNix" fixed -c bash -c '[[ -n $stdenv ]]' +fi