From 68f524d717bb53e5faee8c7ff0a1f9d18dccbead Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 6 Jul 2020 18:34:58 +0200 Subject: [PATCH] nix develop: Support derivations with multiple outputs --- src/nix/develop.cc | 2 ++ src/nix/get-env.sh | 9 +++++++++ tests/shell.nix | 1 + 3 files changed, 12 insertions(+) diff --git a/src/nix/develop.cc b/src/nix/develop.cc index ae6a23346..171eeeb3c 100644 --- a/src/nix/develop.cc +++ b/src/nix/develop.cc @@ -130,7 +130,9 @@ StorePath getDerivationEnvironment(ref store, const StorePath & drvPath) drvName += "-env"; for (auto & output : drv.outputs) drv.env.erase(output.first); + drv.outputs = {{"out", DerivationOutput { .path = StorePath::dummy }}}; drv.env["out"] = ""; + drv.env["_outputs_saved"] = drv.env["outputs"]; drv.env["outputs"] = "out"; drv.inputSrcs.insert(std::move(getEnvShPath)); Hash h = hashDerivationModulo(*store, drv, true); diff --git a/src/nix/get-env.sh b/src/nix/get-env.sh index a25ec43a9..2e0e83561 100644 --- a/src/nix/get-env.sh +++ b/src/nix/get-env.sh @@ -1,9 +1,18 @@ set -e if [ -e .attrs.sh ]; then source .attrs.sh; fi + +outputs=$_outputs_saved +for __output in $_outputs_saved; do + declare "$__output"="$out" +done +unset _outputs_saved __output + export IN_NIX_SHELL=impure export dontAddDisableDepTrack=1 + if [[ -n $stdenv ]]; then source $stdenv/setup fi + export > $out set >> $out diff --git a/tests/shell.nix b/tests/shell.nix index 6cb4f082b..6ce59b416 100644 --- a/tests/shell.nix +++ b/tests/shell.nix @@ -24,6 +24,7 @@ let pkgs = rec { VAR_FROM_NIX = "bar"; TEST_inNixShell = if inNixShell then "true" else "false"; inherit stdenv; + outputs = ["dev" "out"]; }; # Used by nix-shell -p