@@ -227,11 +227,13 @@ const static std::string getEnvSh =
227227#include " get-env.sh.gen.hh"
228228 ;
229229
230- /* Given an existing derivation, return the shell environment as
231- initialised by stdenv's setup script. We do this by building a
232- modified derivation with the same dependencies and nearly the same
233- initial environment variables, that just writes the resulting
234- environment to a file and exits. */
230+ /* *
231+ * Given an existing derivation, return the shell environment as
232+ * initialised by stdenv's setup script. We do this by building a
233+ * modified derivation with the same dependencies and nearly the same
234+ * initial environment variables, that just writes the resulting
235+ * environment to a file and exits.
236+ */
235237static StorePath getDerivationEnvironment (ref<Store> store, ref<Store> evalStore, const StorePath & drvPath)
236238{
237239 auto drv = evalStore->derivationFromPath (drvPath);
@@ -302,6 +304,8 @@ static StorePath getDerivationEnvironment(ref<Store> store, ref<Store> evalStore
302304 bmNormal,
303305 evalStore);
304306
307+ // `get-env.sh` will write its JSON output to an arbitrary output
308+ // path, so return the first non-empty output path.
305309 for (auto & [_0, optPath] : evalStore->queryPartialDerivationOutputMap (shellDrvPath)) {
306310 assert (optPath);
307311 auto accessor = evalStore->requireStoreObjectAccessor (*optPath);
@@ -495,19 +499,18 @@ struct Common : InstallableCommand, MixProfile
495499 }
496500 }
497501
498- std::pair<BuildEnvironment, std::string > getBuildEnvironment (ref<Store> store, ref<Installable> installable)
502+ std::pair<BuildEnvironment, StorePath > getBuildEnvironment (ref<Store> store, ref<Installable> installable)
499503 {
500504 auto shellOutPath = getShellOutPath (store, installable);
501505
502- auto strPath = store->printStorePath (shellOutPath);
503-
504506 updateProfile (shellOutPath);
505507
506- debug (" reading environment file '%s'" , strPath );
508+ debug (" reading environment file '%s'" , store-> printStorePath (shellOutPath) );
507509
508510 return {
509511 BuildEnvironment::parseJSON (store->requireStoreObjectAccessor (shellOutPath)->readFile (CanonPath::root)),
510- strPath};
512+ shellOutPath,
513+ };
511514 }
512515};
513516
@@ -634,7 +637,7 @@ struct CmdDevelop : Common, MixEnvironment
634637
635638 setEnviron ();
636639 // prevent garbage collection until shell exits
637- setEnv (" NIX_GCROOT" , gcroot.c_str ());
640+ setEnv (" NIX_GCROOT" , store-> printStorePath ( gcroot) .c_str ());
638641
639642 Path shell = " bash" ;
640643 bool foundInteractive = false ;
0 commit comments