diff --git a/src/nix/installables.cc b/src/nix/installables.cc index 4e38876ca..21fd54f64 100644 --- a/src/nix/installables.cc +++ b/src/nix/installables.cc @@ -408,8 +408,7 @@ ref openEvalCache( std::tuple InstallableFlake::toDerivation() { - auto lockedFlake = std::make_shared( - lockFlake(*state, flakeRef, lockFlags)); + auto lockedFlake = getLockedFlake(); auto cache = openEvalCache(*state, lockedFlake, true); auto root = cache->getRoot(); @@ -455,9 +454,9 @@ std::vector InstallableFlake::toDerivations() std::pair 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,12 +492,19 @@ InstallableFlake::getCursor(EvalState & state, bool useEvalCache) return res; } +std::shared_ptr InstallableFlake::getLockedFlake() const +{ + if (!_lockedFlake) + _lockedFlake = std::make_shared(lockFlake(*state, flakeRef, lockFlags)); + return _lockedFlake; +} + FlakeRef InstallableFlake::nixpkgsFlakeRef() const { - auto lockedFlake = lockFlake(*(cmd.getEvalState()), flakeRef, cmd.lockFlags); + auto lockedFlake = getLockedFlake(); - auto nixpkgsInput = lockedFlake.flake.inputs.find("nixpkgs"); - if (nixpkgsInput != lockedFlake.flake.inputs.end()) { + auto nixpkgsInput = lockedFlake->flake.inputs.find("nixpkgs"); + if (nixpkgsInput != lockedFlake->flake.inputs.end()) { return std::move(nixpkgsInput->second.ref); } diff --git a/src/nix/installables.hh b/src/nix/installables.hh index 57e3d6c8e..a2db71389 100644 --- a/src/nix/installables.hh +++ b/src/nix/installables.hh @@ -88,6 +88,7 @@ struct InstallableFlake : InstallableValue Strings attrPaths; Strings prefixes; const flake::LockFlags & lockFlags; + mutable std::shared_ptr _lockedFlake; InstallableFlake(ref state, FlakeRef && flakeRef, Strings && attrPaths, Strings && prefixes, const flake::LockFlags & lockFlags) @@ -110,6 +111,8 @@ struct InstallableFlake : InstallableValue std::vector, std::string>> getCursor(EvalState & state, bool useEvalCache) override; + std::shared_ptr getLockedFlake() const; + FlakeRef nixpkgsFlakeRef() const override; };