forked from lix-project/lix
nix dev-shell: Refactor script for getting the environment
This commit is contained in:
parent
df8e9d691c
commit
2fcfc6c2c6
8
src/nix/get-env.sh
Normal file
8
src/nix/get-env.sh
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
set -e
|
||||||
|
export IN_NIX_SHELL=impure
|
||||||
|
export dontAddDisableDepTrack=1
|
||||||
|
if [[ -n $stdenv ]]; then
|
||||||
|
source $stdenv/setup
|
||||||
|
fi
|
||||||
|
export > $out
|
||||||
|
set >> $out
|
|
@ -27,3 +27,5 @@ $(foreach name, \
|
||||||
$(eval $(call install-symlink, $(bindir)/nix, $(libexecdir)/nix/build-remote))
|
$(eval $(call install-symlink, $(bindir)/nix, $(libexecdir)/nix/build-remote))
|
||||||
|
|
||||||
src/nix-env/user-env.cc: src/nix-env/buildenv.nix.gen.hh
|
src/nix-env/user-env.cc: src/nix-env/buildenv.nix.gen.hh
|
||||||
|
|
||||||
|
src/nix/shell.cc: src/nix/get-env.sh.gen.hh
|
||||||
|
|
|
@ -83,6 +83,10 @@ BuildEnvironment readEnvironment(const Path & path)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const static std::string getEnvSh =
|
||||||
|
#include "get-env.sh.gen.hh"
|
||||||
|
;
|
||||||
|
|
||||||
/* Given an existing derivation, return the shell environment as
|
/* Given an existing derivation, return the shell environment as
|
||||||
initialised by stdenv's setup script. We do this by building a
|
initialised by stdenv's setup script. We do this by building a
|
||||||
modified derivation with the same dependencies and nearly the same
|
modified derivation with the same dependencies and nearly the same
|
||||||
|
@ -94,16 +98,9 @@ StorePath getDerivationEnvironment(ref<Store> store, Derivation drv)
|
||||||
if (builder != "bash")
|
if (builder != "bash")
|
||||||
throw Error("'nix dev-shell' only works on derivations that use 'bash' as their builder");
|
throw Error("'nix dev-shell' only works on derivations that use 'bash' as their builder");
|
||||||
|
|
||||||
drv.args = {
|
auto getEnvShPath = store->addTextToStore("get-env.sh", getEnvSh, {});
|
||||||
"-c",
|
|
||||||
"set -e; "
|
drv.args = {store->printStorePath(getEnvShPath)};
|
||||||
"export IN_NIX_SHELL=impure; "
|
|
||||||
"export dontAddDisableDepTrack=1; "
|
|
||||||
"if [[ -n $stdenv ]]; then "
|
|
||||||
" source $stdenv/setup; "
|
|
||||||
"fi; "
|
|
||||||
"export > $out; "
|
|
||||||
"set >> $out "};
|
|
||||||
|
|
||||||
/* Remove derivation checks. */
|
/* Remove derivation checks. */
|
||||||
drv.env.erase("allowedReferences");
|
drv.env.erase("allowedReferences");
|
||||||
|
@ -120,6 +117,7 @@ StorePath getDerivationEnvironment(ref<Store> store, Derivation drv)
|
||||||
drv.env.erase(output.first);
|
drv.env.erase(output.first);
|
||||||
drv.env["out"] = "";
|
drv.env["out"] = "";
|
||||||
drv.env["outputs"] = "out";
|
drv.env["outputs"] = "out";
|
||||||
|
drv.inputSrcs.insert(std::move(getEnvShPath));
|
||||||
Hash h = hashDerivationModulo(*store, drv, true);
|
Hash h = hashDerivationModulo(*store, drv, true);
|
||||||
auto shellOutPath = store->makeOutputPath("out", h, drvName);
|
auto shellOutPath = store->makeOutputPath("out", h, drvName);
|
||||||
drv.outputs.insert_or_assign("out", DerivationOutput(shellOutPath.clone(), "", ""));
|
drv.outputs.insert_or_assign("out", DerivationOutput(shellOutPath.clone(), "", ""));
|
||||||
|
|
Loading…
Reference in a new issue