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

Merge pull request #14641 from obsidiansystems/simplify-nix-develop

Simplify `nix develop` "gathering derivation environment"
This commit is contained in:
John Ericson 2025-11-25 19:08:12 +00:00 committed by GitHub
commit 423e732b22
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 20 deletions

View file

@ -272,26 +272,24 @@ static StorePath getDerivationEnvironment(ref<Store> store, ref<Store> 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);

View file

@ -175,7 +175,7 @@ cat >"$TEST_ROOT"/marco/polo/default.nix <<EOF
(import $TEST_ROOT/lookup-test/shell.nix {}).polo
EOF
chmod a+x "$TEST_ROOT"/marco/polo/default.nix
(cd "$TEST_ROOT"/marco && ./polo/default.nix | grepQuiet "Polo")
(cd "$TEST_ROOT"/marco && ./polo/default.nix < /dev/null | grepQuiet "Polo")
# https://github.com/NixOS/nix/issues/11892
mkdir "$TEST_ROOT"/issue-11892
@ -279,3 +279,10 @@ assert (!(args ? inNixShell));
(import $shellDotNix { }).shellDrv
EOF
nix-shell "$TEST_ROOT"/shell-ellipsis.nix --run "true"
# 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

View file

@ -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: