diff --git a/src/nix/develop.cc b/src/nix/develop.cc index d23dce10b..1eff735da 100644 --- a/src/nix/develop.cc +++ b/src/nix/develop.cc @@ -227,11 +227,13 @@ const static std::string getEnvSh = #include "get-env.sh.gen.hh" ; -/* Given an existing derivation, return the shell environment as - initialised by stdenv's setup script. We do this by building a - modified derivation with the same dependencies and nearly the same - initial environment variables, that just writes the resulting - environment to a file and exits. */ +/** + * Given an existing derivation, return the shell environment as + * initialised by stdenv's setup script. We do this by building a + * modified derivation with the same dependencies and nearly the same + * initial environment variables, that just writes the resulting + * environment to a file and exits. + */ static StorePath getDerivationEnvironment(ref store, ref evalStore, const StorePath & drvPath) { auto drv = evalStore->derivationFromPath(drvPath); @@ -302,6 +304,8 @@ static StorePath getDerivationEnvironment(ref store, ref evalStore bmNormal, evalStore); + // `get-env.sh` will write its JSON output to an arbitrary output + // path, so return the first non-empty output path. for (auto & [_0, optPath] : evalStore->queryPartialDerivationOutputMap(shellDrvPath)) { assert(optPath); auto accessor = evalStore->requireStoreObjectAccessor(*optPath); @@ -495,19 +499,18 @@ struct Common : InstallableCommand, MixProfile } } - std::pair getBuildEnvironment(ref store, ref installable) + std::pair getBuildEnvironment(ref store, ref installable) { auto shellOutPath = getShellOutPath(store, installable); - auto strPath = store->printStorePath(shellOutPath); - updateProfile(shellOutPath); - debug("reading environment file '%s'", strPath); + debug("reading environment file '%s'", store->printStorePath(shellOutPath)); return { BuildEnvironment::parseJSON(store->requireStoreObjectAccessor(shellOutPath)->readFile(CanonPath::root)), - strPath}; + shellOutPath, + }; } }; @@ -634,7 +637,7 @@ struct CmdDevelop : Common, MixEnvironment setEnviron(); // prevent garbage collection until shell exits - setEnv("NIX_GCROOT", gcroot.c_str()); + setEnv("NIX_GCROOT", store->printStorePath(gcroot).c_str()); Path shell = "bash"; bool foundInteractive = false;