-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nix-shell: Use bashInteractive from <nixpkgs>
This adds about 0.1s to nix-shell runtime in the case where bashInteractive already exists. See discussion at NixOS/nixpkgs#27493.
- Loading branch information
Showing
5 changed files
with
54 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ | |
#include "affinity.hh" | ||
#include "util.hh" | ||
#include "shared.hh" | ||
#include "eval.hh" | ||
#include "get-drvs.hh" | ||
|
||
using namespace nix; | ||
using namespace std::string_literals; | ||
|
@@ -75,6 +77,8 @@ int main(int argc, char ** argv) | |
{ | ||
return handleExceptions(argv[0], [&]() { | ||
initNix(); | ||
initGC(); | ||
|
||
auto store = openStore(); | ||
auto dryRun = false; | ||
auto verbose = false; | ||
|
@@ -88,6 +92,7 @@ int main(int argc, char ** argv) | |
Strings instArgs; | ||
Strings buildArgs; | ||
Strings exprs; | ||
Strings searchPath; | ||
|
||
auto shell = getEnv("SHELL", "/bin/sh"); | ||
std::string envCommand; // interactive shell | ||
|
@@ -320,6 +325,8 @@ int main(int argc, char ** argv) | |
} | ||
} | ||
|
||
EvalState state(searchPath, store); | ||
|
||
if (packages && fromArgs) { | ||
throw UsageError("‘-p’ and ‘-E’ are mutually exclusive"); | ||
} | ||
|
@@ -465,7 +472,42 @@ int main(int argc, char ** argv) | |
|
||
auto envPtrs = stringsToCharPtrs(envStrs); | ||
|
||
auto shell = getEnv("NIX_BUILD_SHELL", "bash"); | ||
auto shell = getEnv("NIX_BUILD_SHELL", ""); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
DavidEGrayson
|
||
|
||
if (shell == "") { | ||
|
||
try { | ||
|
||
auto expr = state.parseExprFromString("(import <nixpkgs> {}).bashInteractive", absPath(".")); | ||
|
||
Value v; | ||
state.eval(expr, v); | ||
|
||
auto drv = getDerivation(state, v, false); | ||
if (!drv) | ||
throw Error("the ‘bashInteractive’ attribute in <nixpkgs> did not evaluate to a derivation"); | ||
|
||
auto drvPath = drv->queryDrvPath(); | ||
|
||
unsigned long long downloadSize, narSize; | ||
PathSet willBuild, willSubstitute, unknown; | ||
store->queryMissing({drvPath}, | ||
willBuild, willSubstitute, unknown, downloadSize, narSize); | ||
|
||
if (settings.printMissing) | ||
printMissing(ref<Store>(store), willBuild, willSubstitute, unknown, downloadSize, narSize); | ||
|
||
store->buildPaths({drvPath}); | ||
|
||
shell = drv->queryOutPath() + "/bin/bash"; | ||
if (!pathExists(shell)) | ||
throw Error("expected shell ‘%s’ to exist, but it doesn't", shell); | ||
|
||
} catch (Error & e) { | ||
printError("warning: %s; will use bash from your environment", e.what()); | ||
shell = "bash"; | ||
} | ||
} | ||
|
||
environ = envPtrs.data(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@domenkozar I was thinking, what if we instead looked for like a
stdenv.debugShell
attribute or similar on the current derivation? That seems slightly more modular to me.CC @edolstra @DavidEGrayson @ttuegel