diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-06-29 16:39:41 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-06-29 16:39:41 +0200 |
commit | b681408879c9ad1e500fa6e4566c6d119def4271 (patch) | |
tree | 8f7687379aa4799ab0c96c03b834f07d767a27e9 /src | |
parent | ca946860ce6ce5d4800b0d93d3f83c30d3c953c0 (diff) |
Factor out EvalCache::forceDerivation()
Diffstat (limited to 'src')
-rw-r--r-- | src/libexpr/eval-cache.cc | 16 | ||||
-rw-r--r-- | src/libexpr/eval-cache.hh | 3 | ||||
-rw-r--r-- | src/nix/installables.cc | 12 |
3 files changed, 20 insertions, 11 deletions
diff --git a/src/libexpr/eval-cache.cc b/src/libexpr/eval-cache.cc index a47a539f5..3a18b71d4 100644 --- a/src/libexpr/eval-cache.cc +++ b/src/libexpr/eval-cache.cc @@ -2,6 +2,7 @@ #include "sqlite.hh" #include "eval.hh" #include "eval-inline.hh" +#include "store-api.hh" namespace nix::eval_cache { @@ -502,4 +503,19 @@ bool AttrCursor::isDerivation() return aType && aType->getString() == "derivation"; } +StorePath AttrCursor::forceDerivation() +{ + auto aDrvPath = getAttr(root->state.sDrvPath); + auto drvPath = root->state.store->parseStorePath(aDrvPath->getString()); + if (!root->state.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 (!root->state.store->isValidPath(drvPath)) + throw Error("don't know how to recreate store derivation '%s'!", + root->state.store->printStorePath(drvPath)); + } + return drvPath; +} + } diff --git a/src/libexpr/eval-cache.hh b/src/libexpr/eval-cache.hh index 9c47da315..30261fd3a 100644 --- a/src/libexpr/eval-cache.hh +++ b/src/libexpr/eval-cache.hh @@ -101,6 +101,9 @@ public: bool isDerivation(); Value & forceValue(); + + /* Force creation of the .drv file in the Nix store. */ + StorePath forceDerivation(); }; } diff --git a/src/nix/installables.cc b/src/nix/installables.cc index fb79fad5d..3683ab945 100644 --- a/src/nix/installables.cc +++ b/src/nix/installables.cc @@ -444,17 +444,7 @@ std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableF if (!attr->isDerivation()) throw Error("flake output attribute '%s' is not a derivation", attrPath); - auto aDrvPath = attr->getAttr(state->sDrvPath); - auto drvPath = state->store->parseStorePath(aDrvPath->getString()); - if (!state->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 (!state->store->isValidPath(drvPath)) - throw Error("don't know how to recreate store derivation '%s'!", - state->store->printStorePath(drvPath)); - } + auto drvPath = attr->forceDerivation(); auto drvInfo = DerivationInfo{ std::move(drvPath), |