From 04821bc1718aff975b51e98ce7bfb91888167c6d Mon Sep 17 00:00:00 2001 From: Matthew Kenigsberg Date: Tue, 5 May 2020 10:49:39 -0600 Subject: use flake's nixpkgs to find bashInteractive --- src/nix/dev-shell.cc | 3 +-- src/nix/installables.cc | 12 ++++++++++++ src/nix/installables.hh | 7 +++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/nix/dev-shell.cc b/src/nix/dev-shell.cc index d842be79f..b3314021f 100644 --- a/src/nix/dev-shell.cc +++ b/src/nix/dev-shell.cc @@ -286,9 +286,8 @@ struct CmdDevShell : Common, MixEnvironment std::string getBashPath(ref store) { - auto flakeRef = FlakeRef::fromAttrs({{"type","indirect"}, {"id", "nixpkgs"}}); auto state = getEvalState(); - auto lockedFlake = std::make_shared(lockFlake(*state, flakeRef, lockFlags)); + auto lockedFlake = std::make_shared(lockFlake(*state, installable->nixpkgsFlakeRef(), lockFlags)); auto cache = openEvalCache(*state, lockedFlake, true); auto root = cache->getRoot(); diff --git a/src/nix/installables.cc b/src/nix/installables.cc index cae85b34e..4e38876ca 100644 --- a/src/nix/installables.cc +++ b/src/nix/installables.cc @@ -493,6 +493,18 @@ InstallableFlake::getCursor(EvalState & state, bool useEvalCache) return res; } +FlakeRef InstallableFlake::nixpkgsFlakeRef() const +{ + auto lockedFlake = lockFlake(*(cmd.getEvalState()), flakeRef, cmd.lockFlags); + + auto nixpkgsInput = lockedFlake.flake.inputs.find("nixpkgs"); + if (nixpkgsInput != lockedFlake.flake.inputs.end()) { + return std::move(nixpkgsInput->second.ref); + } + + return Installable::nixpkgsFlakeRef(); +} + std::vector> SourceExprCommand::parseInstallables( ref store, std::vector ss) { diff --git a/src/nix/installables.hh b/src/nix/installables.hh index 531720de6..57e3d6c8e 100644 --- a/src/nix/installables.hh +++ b/src/nix/installables.hh @@ -57,6 +57,11 @@ struct Installable virtual std::vector, std::string>> getCursor(EvalState & state, bool useEvalCache); + + virtual FlakeRef nixpkgsFlakeRef() const + { + return std::move(FlakeRef::fromAttrs({{"type","indirect"}, {"id", "nixpkgs"}})); + } }; struct InstallableValue : Installable @@ -104,6 +109,8 @@ struct InstallableFlake : InstallableValue std::vector, std::string>> getCursor(EvalState & state, bool useEvalCache) override; + + FlakeRef nixpkgsFlakeRef() const override; }; ref openEvalCache( -- cgit v1.2.3