Merge branch 'nixpkgs#bashInteractive' of https://github.com/mkenigs/nix into flakes

This commit is contained in:
Eelco Dolstra 2020-05-28 11:59:54 +02:00
commit 04fb4e8a0f
3 changed files with 35 additions and 6 deletions

View file

@ -303,12 +303,13 @@ 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 state = getEvalState();
auto bashInstallable = std::make_shared<InstallableFlake>(state, std::move(installable->nixpkgsFlakeRef()), Strings{"bashInteractive"}, Strings{"legacyPackages." + settings.thisSystem.get() + "."}, lockFlags);
auto shell = state->store->printStorePath(toStorePath(state->store, Build, bashInstallable)) + "/bin/bash";
auto args = Strings{std::string(baseNameOf(shell)), "--rcfile", rcFilePath};
restoreAffinity();

View file

@ -408,8 +408,7 @@ ref<eval_cache::EvalCache> openEvalCache(
std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableFlake::toDerivation()
{
auto lockedFlake = std::make_shared<flake::LockedFlake>(
lockFlake(*state, flakeRef, lockFlags));
auto lockedFlake = getLockedFlake();
auto cache = openEvalCache(*state, lockedFlake, true);
auto root = cache->getRoot();
@ -455,9 +454,9 @@ std::vector<InstallableValue::DerivationInfo> InstallableFlake::toDerivations()
std::pair<Value *, Pos> InstallableFlake::toValue(EvalState & state)
{
auto lockedFlake = lockFlake(state, flakeRef, lockFlags);
auto lockedFlake = getLockedFlake();
auto vOutputs = getFlakeOutputs(state, lockedFlake);
auto vOutputs = getFlakeOutputs(state, *lockedFlake);
auto emptyArgs = state.allocBindings(0);
@ -493,6 +492,25 @@ InstallableFlake::getCursor(EvalState & state, bool useEvalCache)
return res;
}
std::shared_ptr<flake::LockedFlake> InstallableFlake::getLockedFlake() const
{
if (!_lockedFlake)
_lockedFlake = std::make_shared<flake::LockedFlake>(lockFlake(*state, flakeRef, lockFlags));
return _lockedFlake;
}
FlakeRef InstallableFlake::nixpkgsFlakeRef() const
{
auto lockedFlake = getLockedFlake();
auto nixpkgsInput = lockedFlake->flake.inputs.find("nixpkgs");
if (nixpkgsInput != lockedFlake->flake.inputs.end()) {
return std::move(nixpkgsInput->second.ref);
}
return Installable::nixpkgsFlakeRef();
}
std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
ref<Store> store, std::vector<std::string> ss)
{

View file

@ -57,6 +57,11 @@ struct Installable
virtual std::vector<std::pair<std::shared_ptr<eval_cache::AttrCursor>, std::string>>
getCursor(EvalState & state, bool useEvalCache);
virtual FlakeRef nixpkgsFlakeRef() const
{
return std::move(FlakeRef::fromAttrs({{"type","indirect"}, {"id", "nixpkgs"}}));
}
};
struct InstallableValue : Installable
@ -83,6 +88,7 @@ struct InstallableFlake : InstallableValue
Strings attrPaths;
Strings prefixes;
const flake::LockFlags & lockFlags;
mutable std::shared_ptr<flake::LockedFlake> _lockedFlake;
InstallableFlake(ref<EvalState> state, FlakeRef && flakeRef,
Strings && attrPaths, Strings && prefixes, const flake::LockFlags & lockFlags)
@ -104,6 +110,10 @@ struct InstallableFlake : InstallableValue
std::vector<std::pair<std::shared_ptr<eval_cache::AttrCursor>, std::string>>
getCursor(EvalState & state, bool useEvalCache) override;
std::shared_ptr<flake::LockedFlake> getLockedFlake() const;
FlakeRef nixpkgsFlakeRef() const override;
};
ref<eval_cache::EvalCache> openEvalCache(