Skip to content

Commit 3ccbe84

Browse files
authored
Merge pull request #200 from DeterminateSystems/nix-develop-cleanups
`nix develop`: Version the JSON + some cleanups
2 parents 727cbf8 + 348526e commit 3ccbe84

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/nix/develop.cc

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,13 @@ const static std::string getEnvSh =
228228
#include "get-env.sh.gen.hh"
229229
;
230230

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. */
231+
/**
232+
* Given an existing derivation, return the shell environment as
233+
* initialised by stdenv's setup script. We do this by building a
234+
* modified derivation with the same dependencies and nearly the same
235+
* initial environment variables, that just writes the resulting
236+
* environment to a file and exits.
237+
*/
236238
static StorePath getDerivationEnvironment(ref<Store> store, ref<Store> evalStore, const StorePath & drvPath)
237239
{
238240
auto drv = evalStore->derivationFromPath(drvPath);
@@ -298,12 +300,13 @@ static StorePath getDerivationEnvironment(ref<Store> store, ref<Store> evalStore
298300
bmNormal,
299301
evalStore);
300302

303+
// `get-env.sh` will write its JSON output to an arbitrary output
304+
// path, so return the first non-empty output path.
301305
for (auto & [_0, optPath] : evalStore->queryPartialDerivationOutputMap(shellDrvPath)) {
302306
assert(optPath);
303307
auto & outPath = *optPath;
304-
assert(store->isValidPath(outPath));
305-
auto outPathS = store->toRealPath(outPath);
306-
if (lstat(outPathS).st_size)
308+
auto st = store->getFSAccessor()->lstat(CanonPath(outPath.to_string()));
309+
if (st.fileSize.value_or(0))
307310
return outPath;
308311
}
309312

@@ -493,17 +496,15 @@ struct Common : InstallableCommand, MixProfile
493496
}
494497
}
495498

496-
std::pair<BuildEnvironment, std::string> getBuildEnvironment(ref<Store> store, ref<Installable> installable)
499+
std::pair<BuildEnvironment, StorePath> getBuildEnvironment(ref<Store> store, ref<Installable> installable)
497500
{
498501
auto shellOutPath = getShellOutPath(store, installable);
499502

500-
auto strPath = store->printStorePath(shellOutPath);
501-
502503
updateProfile(shellOutPath);
503504

504-
debug("reading environment file '%s'", strPath);
505+
debug("reading environment file '%s'", store->printStorePath(shellOutPath));
505506

506-
return {BuildEnvironment::parseJSON(readFile(store->toRealPath(shellOutPath))), strPath};
507+
return {BuildEnvironment::parseJSON(store->getFSAccessor()->readFile(shellOutPath.to_string())), shellOutPath};
507508
}
508509
};
509510

@@ -632,7 +633,7 @@ struct CmdDevelop : Common, MixEnvironment
632633

633634
setEnviron();
634635
// prevent garbage collection until shell exits
635-
setEnv("NIX_GCROOT", gcroot.c_str());
636+
setEnv("NIX_GCROOT", store->printStorePath(gcroot).c_str());
636637

637638
Path shell = "bash";
638639

src/nix/get-env.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ __functions="$(declare -F)"
1414

1515
__dumpEnv() {
1616
printf '{\n'
17+
printf ' "version": 1,\n'
1718

1819
printf ' "bashFunctions": {\n'
1920
local __first=1

0 commit comments

Comments
 (0)