1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 03:56:01 +01:00

Use ref<LockedFlake> where non-null

This commit is contained in:
Robert Hensing 2025-10-09 20:53:48 +02:00
parent 0387b7d6db
commit 42c9cbf9ca
6 changed files with 10 additions and 11 deletions

View file

@ -69,7 +69,7 @@ struct InstallableFlake : InstallableValue
*/ */
std::vector<ref<eval_cache::AttrCursor>> getCursors(EvalState & state) override; std::vector<ref<eval_cache::AttrCursor>> getCursors(EvalState & state) override;
std::shared_ptr<flake::LockedFlake> getLockedFlake() const; ref<flake::LockedFlake> getLockedFlake() const;
FlakeRef nixpkgsFlakeRef() const; FlakeRef nixpkgsFlakeRef() const;
}; };

View file

@ -185,16 +185,16 @@ std::vector<ref<eval_cache::AttrCursor>> InstallableFlake::getCursors(EvalState
return res; return res;
} }
std::shared_ptr<flake::LockedFlake> InstallableFlake::getLockedFlake() const ref<flake::LockedFlake> InstallableFlake::getLockedFlake() const
{ {
if (!_lockedFlake) { if (!_lockedFlake) {
flake::LockFlags lockFlagsApplyConfig = lockFlags; flake::LockFlags lockFlagsApplyConfig = lockFlags;
// FIXME why this side effect? // FIXME why this side effect?
lockFlagsApplyConfig.applyNixConfig = true; lockFlagsApplyConfig.applyNixConfig = true;
_lockedFlake = _lockedFlake = make_ref<flake::LockedFlake>(lockFlake(flakeSettings, *state, flakeRef, lockFlagsApplyConfig));
std::make_shared<flake::LockedFlake>(lockFlake(flakeSettings, *state, flakeRef, lockFlagsApplyConfig));
} }
return _lockedFlake; // _lockedFlake is now non-null but still just a shared_ptr
return ref<flake::LockedFlake>(_lockedFlake);
} }
FlakeRef InstallableFlake::nixpkgsFlakeRef() const FlakeRef InstallableFlake::nixpkgsFlakeRef() const

View file

@ -342,8 +342,7 @@ void completeFlakeRefWithFragment(
parseFlakeRef(fetchSettings, expandTilde(flakeRefS), std::filesystem::current_path().string()); parseFlakeRef(fetchSettings, expandTilde(flakeRefS), std::filesystem::current_path().string());
auto evalCache = openEvalCache( auto evalCache = openEvalCache(
*evalState, *evalState, make_ref<flake::LockedFlake>(lockFlake(flakeSettings, *evalState, flakeRef, lockFlags)));
std::make_shared<flake::LockedFlake>(lockFlake(flakeSettings, *evalState, flakeRef, lockFlags)));
auto root = evalCache->getRoot(); auto root = evalCache->getRoot();

View file

@ -954,7 +954,7 @@ std::optional<Fingerprint> LockedFlake::getFingerprint(ref<Store> store, const f
Flake::~Flake() {} Flake::~Flake() {}
ref<eval_cache::EvalCache> openEvalCache(EvalState & state, std::shared_ptr<LockedFlake> lockedFlake) ref<eval_cache::EvalCache> openEvalCache(EvalState & state, ref<LockedFlake> lockedFlake)
{ {
auto fingerprint = state.settings.useEvalCache && state.settings.pureEval auto fingerprint = state.settings.useEvalCache && state.settings.pureEval
? lockedFlake->getFingerprint(state.store, state.fetchSettings) ? lockedFlake->getFingerprint(state.store, state.fetchSettings)

View file

@ -222,7 +222,7 @@ void callFlake(EvalState & state, const LockedFlake & lockedFlake, Value & v);
/** /**
* Open an evaluation cache for a flake. * Open an evaluation cache for a flake.
*/ */
ref<eval_cache::EvalCache> openEvalCache(EvalState & state, std::shared_ptr<LockedFlake> lockedFlake); ref<eval_cache::EvalCache> openEvalCache(EvalState & state, ref<LockedFlake> lockedFlake);
} // namespace flake } // namespace flake

View file

@ -1155,7 +1155,7 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
evalSettings.enableImportFromDerivation.setDefault(false); evalSettings.enableImportFromDerivation.setDefault(false);
auto state = getEvalState(); auto state = getEvalState();
auto flake = std::make_shared<LockedFlake>(lockFlake()); auto flake = make_ref<LockedFlake>(lockFlake());
auto localSystem = std::string(settings.thisSystem.get()); auto localSystem = std::string(settings.thisSystem.get());
std::function<bool(eval_cache::AttrCursor & visitor, const std::vector<Symbol> & attrPath, const Symbol & attr)> std::function<bool(eval_cache::AttrCursor & visitor, const std::vector<Symbol> & attrPath, const Symbol & attr)>
@ -1443,7 +1443,7 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
return j; return j;
}; };
auto cache = openEvalCache(*state, flake); auto cache = openEvalCache(*state, ref<flake::LockedFlake>(flake));
auto j = visit(*cache->getRoot(), {}, fmt(ANSI_BOLD "%s" ANSI_NORMAL, flake->flake.lockedRef), ""); auto j = visit(*cache->getRoot(), {}, fmt(ANSI_BOLD "%s" ANSI_NORMAL, flake->flake.lockedRef), "");
if (json) if (json)