diff options
author | Matthew Kenigsberg <matthewkenigsberg@gmail.com> | 2020-04-27 12:17:58 -0600 |
---|---|---|
committer | Matthew Kenigsberg <matthewkenigsberg@gmail.com> | 2020-05-16 11:03:06 -0600 |
commit | 8fbc8540d3ea540d985b577166a1168d472c2d70 (patch) | |
tree | ca6ad4e2046f643b69e6b6cc9aacfd7ec2101099 /src/nix | |
parent | 5f64655ff429be08aa0787761697787e7050f373 (diff) |
use nixpkgs#bashInteractive for dev-shell
Diffstat (limited to 'src/nix')
-rw-r--r-- | src/nix/dev-shell.cc | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/src/nix/dev-shell.cc b/src/nix/dev-shell.cc index 6b1cf0ffd..d842be79f 100644 --- a/src/nix/dev-shell.cc +++ b/src/nix/dev-shell.cc @@ -6,6 +6,9 @@ #include "derivations.hh" #include "affinity.hh" #include "progress-bar.hh" +#include "attr-path.hh" +#include "eval-cache.hh" +#include "flake/flake.hh" #include <regex> @@ -281,6 +284,41 @@ struct CmdDevShell : Common, MixEnvironment }; } + std::string getBashPath(ref<Store> store) + { + auto flakeRef = FlakeRef::fromAttrs({{"type","indirect"}, {"id", "nixpkgs"}}); + auto state = getEvalState(); + auto lockedFlake = std::make_shared<flake::LockedFlake>(lockFlake(*state, flakeRef, lockFlags)); + auto cache = openEvalCache(*state, lockedFlake, true); + auto root = cache->getRoot(); + + auto attrPath = "legacyPackages." + settings.thisSystem.get() + ".bashInteractive"; + auto attr = root->findAlongAttrPath(parseAttrPath(*state, attrPath)); + if (!attr || !attr->isDerivation()) throw Error("couldn't find bashInteractive derivation"); + + auto aDrvPath = attr->getAttr(state->sDrvPath); + auto drvPath = store->parseStorePath(aDrvPath->getString()); + if (!store->isValidPath(drvPath) && !settings.readOnlyMode) { + /* The eval cache contains 'drvPath', but the actual path + has been garbage-collected. So force it to be + regenerated. */ + aDrvPath->forceValue(); + if (!store->isValidPath(drvPath)) + throw Error("don't know how to recreate store derivation '%s'!", + store->printStorePath(drvPath)); + } + + auto outputName = attr->getAttr(state->sOutputName)->getString(); + if (outputName == "") + throw Error("derivation '%s' lacks an 'outputName' attribute", store->printStorePath(drvPath)); + + auto outPath = store->parseStorePath(attr->getAttr(state->sOutPath)->getString()); + + store->buildPaths({{drvPath, {outputName}}}); + + return store->printStorePath(outPath) + "/bin/bash"; + } + void run(ref<Store> store) override { auto [buildEnvironment, gcroot] = getBuildEnvironment(store); @@ -303,12 +341,11 @@ struct CmdDevShell : Common, MixEnvironment stopProgressBar(); - auto shell = getEnv("SHELL").value_or("bash"); - setEnviron(); // prevent garbage collection until shell exits setenv("NIX_GCROOT", gcroot.data(), 1); + auto shell = getBashPath(store); auto args = Strings{std::string(baseNameOf(shell)), "--rcfile", rcFilePath}; restoreAffinity(); |