Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/nix/develop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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> store, ref<Store> evalStore, const StorePath & drvPath)
{
auto drv = evalStore->derivationFromPath(drvPath);
Expand Down Expand Up @@ -297,12 +299,13 @@ static StorePath getDerivationEnvironment(ref<Store> store, ref<Store> 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 & outPath = *optPath;
assert(store->isValidPath(outPath));
auto outPathS = store->toRealPath(outPath);
if (lstat(outPathS).st_size)
auto st = store->getFSAccessor()->lstat(CanonPath(outPath.to_string()));
if (st.fileSize.value_or(0))
return outPath;
}

Expand Down Expand Up @@ -492,17 +495,15 @@ struct Common : InstallableCommand, MixProfile
}
}

std::pair<BuildEnvironment, std::string> getBuildEnvironment(ref<Store> store, ref<Installable> installable)
std::pair<BuildEnvironment, StorePath> getBuildEnvironment(ref<Store> store, ref<Installable> 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(readFile(store->toRealPath(shellOutPath))), strPath};
return {BuildEnvironment::parseJSON(store->getFSAccessor()->readFile(shellOutPath.to_string())), shellOutPath};
}
};

Expand Down Expand Up @@ -629,7 +630,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;
Expand Down
1 change: 1 addition & 0 deletions src/nix/get-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ __functions="$(declare -F)"

__dumpEnv() {
printf '{\n'
printf ' "version": 1,\n'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not opposing to have this, but have you have a more concrete motivation for this change i.e. can you elaborate how "could even be pushed to binary caches" would be used? Afaik mkShell is buildable and can be already pushed to a binary cache. You removed the the version 1 from flakes again for the reason that a "v2" would be the first explicit version and before everything is "v1".


printf ' "bashFunctions": {\n'
local __first=1
Expand Down
Loading