Skip to content

Commit 423e732

Browse files
authored
Merge pull request #14641 from obsidiansystems/simplify-nix-develop
Simplify `nix develop` "gathering derivation environment"
2 parents 05990fb + 6a4a1e9 commit 423e732

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

src/nix/develop.cc

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -272,26 +272,24 @@ static StorePath getDerivationEnvironment(ref<Store> store, ref<Store> evalStore
272272
drv.name += "-env";
273273
drv.env.emplace("name", drv.name);
274274
drv.inputSrcs.insert(std::move(getEnvShPath));
275-
if (experimentalFeatureSettings.isEnabled(Xp::CaDerivations)) {
276-
for (auto & output : drv.outputs) {
277-
output.second = DerivationOutput::Deferred{}, drv.env[output.first] = hashPlaceholder(output.first);
278-
}
279-
} else {
280-
for (auto & output : drv.outputs) {
281-
output.second = DerivationOutput::Deferred{};
282-
drv.env[output.first] = "";
283-
}
284-
auto hashesModulo = hashDerivationModulo(*evalStore, drv, true);
285-
286-
for (auto & output : drv.outputs) {
287-
Hash h = hashesModulo.hashes.at(output.first);
288-
auto outPath = store->makeOutputPath(output.first, h, drv.name);
289-
output.second = DerivationOutput::InputAddressed{
290-
.path = outPath,
291-
};
292-
drv.env[output.first] = store->printStorePath(outPath);
293-
}
275+
for (auto & [outputName, output] : drv.outputs) {
276+
std::visit(
277+
overloaded{
278+
[&](const DerivationOutput::InputAddressed &) {
279+
output = DerivationOutput::Deferred{};
280+
drv.env[outputName] = "";
281+
},
282+
[&](const DerivationOutput::CAFixed &) {
283+
output = DerivationOutput::Deferred{};
284+
drv.env[outputName] = "";
285+
},
286+
[&](const auto &) {
287+
// Do nothing for other types (CAFloating, Deferred, Impure)
288+
},
289+
},
290+
output.raw);
294291
}
292+
drv.fillInOutputPaths(*evalStore);
295293

296294
auto shellDrvPath = writeDerivation(*evalStore, drv);
297295

tests/functional/nix-shell.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ cat >"$TEST_ROOT"/marco/polo/default.nix <<EOF
175175
(import $TEST_ROOT/lookup-test/shell.nix {}).polo
176176
EOF
177177
chmod a+x "$TEST_ROOT"/marco/polo/default.nix
178-
(cd "$TEST_ROOT"/marco && ./polo/default.nix | grepQuiet "Polo")
178+
(cd "$TEST_ROOT"/marco && ./polo/default.nix < /dev/null | grepQuiet "Polo")
179179

180180
# https://github.com/NixOS/nix/issues/11892
181181
mkdir "$TEST_ROOT"/issue-11892
@@ -279,3 +279,10 @@ assert (!(args ? inNixShell));
279279
(import $shellDotNix { }).shellDrv
280280
EOF
281281
nix-shell "$TEST_ROOT"/shell-ellipsis.nix --run "true"
282+
283+
# FIXME unclear why this (newly made) test is failing in this case.
284+
if ! isTestOnNixOS; then
285+
# `nix develop` should also work with fixed-output derivations
286+
# shellcheck disable=SC2016
287+
nix develop -f "$shellDotNix" fixed -c bash -c '[[ -n $stdenv ]]'
288+
fi

tests/functional/shell.nix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ let
8484
'';
8585
};
8686

87+
# Shells should also work with fixed-output derivations
88+
fixed = mkDerivation {
89+
name = "fixed";
90+
FOO = "was a fixed-output derivation";
91+
outputHash = "1ixr6yd3297ciyp9im522dfxpqbkhcw0pylkb2aab915278fqaik";
92+
outputHashMode = "recursive";
93+
outputHashAlgo = "sha256";
94+
outputs = [ "out" ];
95+
};
96+
8797
# Used by nix-shell -p
8898
runCommand =
8999
name: args: buildCommand:

0 commit comments

Comments
 (0)