From 8d9f7048cd3b09fb58f6bad0328f644b0ddaaa16 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 16 Jul 2021 16:04:47 +0200 Subject: [PATCH] Use eval-store in more places In particular, this now works: $ nix path-info --eval-store auto --store https://cache.nixos.org nixpkgs#hello Previously this would fail as it would try to upload the hello .drv to cache.nixos.org. Now the .drv is instantiated in the local store, and then we check for the existence of the outputs in cache.nixos.org. --- src/libcmd/command.cc | 2 +- src/libcmd/command.hh | 17 ++++++++++++----- src/libcmd/installables.cc | 38 +++++++++++++++++++------------------ src/libcmd/installables.hh | 2 +- src/libstore/derivations.cc | 2 +- src/nix/app.cc | 5 +++-- src/nix/build.cc | 5 ++++- src/nix/bundle.cc | 2 +- src/nix/develop.cc | 6 +++--- src/nix/diff-closures.cc | 4 ++-- src/nix/profile.cc | 2 +- src/nix/run.cc | 4 ++-- src/nix/why-depends.cc | 4 ++-- 13 files changed, 53 insertions(+), 40 deletions(-) diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 4add710ed..2daf43aa7 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -115,7 +115,7 @@ void BuiltPathsCommand::run(ref store) for (auto & p : store->queryAllValidPaths()) paths.push_back(BuiltPath::Opaque{p}); } else { - paths = toBuiltPaths(store, realiseMode, operateOn, installables); + paths = toBuiltPaths(getEvalStore(), store, realiseMode, operateOn, installables); if (recursive) { // XXX: This only computes the store path closure, ignoring // intermediate realisations diff --git a/src/libcmd/command.hh b/src/libcmd/command.hh index 659b13559..f3625ed0d 100644 --- a/src/libcmd/command.hh +++ b/src/libcmd/command.hh @@ -223,15 +223,21 @@ static RegisterCommand registerCommand2(std::vector && name) return RegisterCommand(std::move(name), [](){ return make_ref(); }); } -BuiltPaths build(ref store, Realise mode, +BuiltPaths build(ref evalStore, ref store, Realise mode, std::vector> installables, BuildMode bMode = bmNormal); -std::set toStorePaths(ref store, - Realise mode, OperateOn operateOn, +std::set toStorePaths( + ref evalStore, + ref store, + Realise mode, + OperateOn operateOn, std::vector> installables); -StorePath toStorePath(ref store, - Realise mode, OperateOn operateOn, +StorePath toStorePath( + ref evalStore, + ref store, + Realise mode, + OperateOn operateOn, std::shared_ptr installable); std::set toDerivations(ref store, @@ -239,6 +245,7 @@ std::set toDerivations(ref store, bool useDeriver = false); BuiltPaths toBuiltPaths( + ref evalStore, ref store, Realise mode, OperateOn operateOn, diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 124df34ea..00f8105ae 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -392,8 +392,6 @@ DerivedPaths InstallableValue::toDerivedPaths() for (auto & i : drvsToOutputs) res.push_back(DerivedPath::Built { i.first, i.second }); - copyClosure(state->store, state->buildStore, drvsToCopy); - return res; } @@ -703,10 +701,10 @@ std::shared_ptr SourceExprCommand::parseInstallable( return installables.front(); } -BuiltPaths getBuiltPaths(ref store, DerivedPaths hopefullyBuiltPaths) +BuiltPaths getBuiltPaths(ref evalStore, ref store, const DerivedPaths & hopefullyBuiltPaths) { BuiltPaths res; - for (auto& b : hopefullyBuiltPaths) + for (auto & b : hopefullyBuiltPaths) std::visit( overloaded{ [&](DerivedPath::Opaque bo) { @@ -714,14 +712,13 @@ BuiltPaths getBuiltPaths(ref store, DerivedPaths hopefullyBuiltPaths) }, [&](DerivedPath::Built bfd) { OutputPathMap outputs; - auto drv = store->readDerivation(bfd.drvPath); - auto outputHashes = staticOutputHashes(*store, drv); + auto drv = evalStore->readDerivation(bfd.drvPath); + auto outputHashes = staticOutputHashes(*evalStore, drv); // FIXME: expensive auto drvOutputs = drv.outputsAndOptPaths(*store); - for (auto& output : bfd.outputs) { + for (auto & output : bfd.outputs) { if (!outputHashes.count(output)) throw Error( - "the derivation '%s' doesn't have an output " - "named '%s'", + "the derivation '%s' doesn't have an output named '%s'", store->printStorePath(bfd.drvPath), output); if (settings.isExperimentalFeatureEnabled( "ca-derivations")) { @@ -753,7 +750,7 @@ BuiltPaths getBuiltPaths(ref store, DerivedPaths hopefullyBuiltPaths) return res; } -BuiltPaths build(ref store, Realise mode, +BuiltPaths build(ref evalStore, ref store, Realise mode, std::vector> installables, BuildMode bMode) { if (mode == Realise::Nothing) @@ -771,18 +768,19 @@ BuiltPaths build(ref store, Realise mode, else if (mode == Realise::Outputs) store->buildPaths(pathsToBuild, bMode); - return getBuiltPaths(store, pathsToBuild); + return getBuiltPaths(evalStore, store, pathsToBuild); } BuiltPaths toBuiltPaths( + ref evalStore, ref store, Realise mode, OperateOn operateOn, std::vector> installables) { - if (operateOn == OperateOn::Output) { - return build(store, mode, installables); - } else { + if (operateOn == OperateOn::Output) + return build(evalStore, store, mode, installables); + else { if (mode == Realise::Nothing) settings.readOnlyMode = true; @@ -793,23 +791,27 @@ BuiltPaths toBuiltPaths( } } -StorePathSet toStorePaths(ref store, +StorePathSet toStorePaths( + ref evalStore, + ref store, Realise mode, OperateOn operateOn, std::vector> installables) { StorePathSet outPaths; - for (auto & path : toBuiltPaths(store, mode, operateOn, installables)) { + for (auto & path : toBuiltPaths(evalStore, store, mode, operateOn, installables)) { auto thisOutPaths = path.outPaths(); outPaths.insert(thisOutPaths.begin(), thisOutPaths.end()); } return outPaths; } -StorePath toStorePath(ref store, +StorePath toStorePath( + ref evalStore, + ref store, Realise mode, OperateOn operateOn, std::shared_ptr installable) { - auto paths = toStorePaths(store, mode, operateOn, {installable}); + auto paths = toStorePaths(evalStore, store, mode, operateOn, {installable}); if (paths.size() != 1) throw Error("argument '%s' should evaluate to one store path", installable->what()); diff --git a/src/libcmd/installables.hh b/src/libcmd/installables.hh index 298fd48f8..79931ad3e 100644 --- a/src/libcmd/installables.hh +++ b/src/libcmd/installables.hh @@ -26,7 +26,7 @@ struct App struct UnresolvedApp { App unresolved; - App resolve(ref); + App resolve(ref evalStore, ref store); }; struct Installable diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index f6defd98f..899475860 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -568,7 +568,7 @@ DrvHashModulo hashDerivationModulo(Store & store, const Derivation & drv, bool m } -std::map staticOutputHashes(Store& store, const Derivation& drv) +std::map staticOutputHashes(Store & store, const Derivation & drv) { std::map res; std::visit(overloaded { diff --git a/src/nix/app.cc b/src/nix/app.cc index 01a0064db..9719a65dd 100644 --- a/src/nix/app.cc +++ b/src/nix/app.cc @@ -100,7 +100,8 @@ UnresolvedApp Installable::toApp(EvalState & state) throw Error("attribute '%s' has unsupported type '%s'", attrPath, type); } -App UnresolvedApp::resolve(ref store) +// FIXME: move to libcmd +App UnresolvedApp::resolve(ref evalStore, ref store) { auto res = unresolved; @@ -110,7 +111,7 @@ App UnresolvedApp::resolve(ref store) installableContext.push_back( std::make_shared(store, ctxElt.toDerivedPath())); - auto builtContext = build(store, Realise::Outputs, installableContext); + auto builtContext = build(evalStore, store, Realise::Outputs, installableContext); res.program = resolveString(*store, unresolved.program, builtContext); if (!store->isInStore(res.program)) throw Error("app program '%s' is not in the Nix store", res.program); diff --git a/src/nix/build.cc b/src/nix/build.cc index 15923ebc3..13eb66ac6 100644 --- a/src/nix/build.cc +++ b/src/nix/build.cc @@ -52,7 +52,10 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile void run(ref store) override { - auto buildables = build(store, dryRun ? Realise::Nothing : Realise::Outputs, installables, buildMode); + auto buildables = build( + getEvalStore(), store, + dryRun ? Realise::Nothing : Realise::Outputs, + installables, buildMode); if (json) logger->cout("%s", derivedPathsWithHintsToJSON(buildables, store).dump()); diff --git a/src/nix/bundle.cc b/src/nix/bundle.cc index 88bc3d1d1..cedb5704c 100644 --- a/src/nix/bundle.cc +++ b/src/nix/bundle.cc @@ -69,7 +69,7 @@ struct CmdBundle : InstallableCommand { auto evalState = getEvalState(); - auto app = installable->toApp(*evalState).resolve(store); + auto app = installable->toApp(*evalState).resolve(getEvalStore(), store); auto [bundlerFlakeRef, bundlerName] = parseFlakeRefWithFragment(bundler, absPath(".")); const flake::LockFlags lockFlags{ .writeLockFile = false }; diff --git a/src/nix/develop.cc b/src/nix/develop.cc index 9ac2791f8..cb173b91b 100644 --- a/src/nix/develop.cc +++ b/src/nix/develop.cc @@ -307,7 +307,7 @@ struct Common : InstallableCommand, MixProfile auto dir = absPath(dir_); auto installable = parseInstallable(store, installable_); auto builtPaths = toStorePaths( - store, Realise::Nothing, OperateOn::Output, {installable}); + getEvalStore(), store, Realise::Nothing, OperateOn::Output, {installable}); for (auto & path: builtPaths) { auto from = store->printStorePath(path); if (script.find(from) == std::string::npos) @@ -495,8 +495,8 @@ struct CmdDevelop : Common, MixEnvironment Strings{"legacyPackages." + settings.thisSystem.get() + "."}, nixpkgsLockFlags); - shell = state->store->printStorePath( - toStorePath(state->store, Realise::Outputs, OperateOn::Output, bashInstallable)) + "/bin/bash"; + shell = store->printStorePath( + toStorePath(getEvalStore(), store, Realise::Outputs, OperateOn::Output, bashInstallable)) + "/bin/bash"; } catch (Error &) { ignoreException(); } diff --git a/src/nix/diff-closures.cc b/src/nix/diff-closures.cc index 0c7d531c1..734c41e0e 100644 --- a/src/nix/diff-closures.cc +++ b/src/nix/diff-closures.cc @@ -131,9 +131,9 @@ struct CmdDiffClosures : SourceExprCommand void run(ref store) override { auto before = parseInstallable(store, _before); - auto beforePath = toStorePath(store, Realise::Outputs, operateOn, before); + auto beforePath = toStorePath(getEvalStore(), store, Realise::Outputs, operateOn, before); auto after = parseInstallable(store, _after); - auto afterPath = toStorePath(store, Realise::Outputs, operateOn, after); + auto afterPath = toStorePath(getEvalStore(), store, Realise::Outputs, operateOn, after); printClosureDiff(store, beforePath, afterPath, ""); } }; diff --git a/src/nix/profile.cc b/src/nix/profile.cc index 511771f89..8cef6d0b6 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -253,7 +253,7 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile manifest.elements.emplace_back(std::move(element)); } else { - auto buildables = build(store, Realise::Outputs, {installable}, bmNormal); + auto buildables = build(getEvalStore(), store, Realise::Outputs, {installable}, bmNormal); for (auto & buildable : buildables) { ProfileElement element; diff --git a/src/nix/run.cc b/src/nix/run.cc index c0ba05a3e..0c8afec2d 100644 --- a/src/nix/run.cc +++ b/src/nix/run.cc @@ -93,7 +93,7 @@ struct CmdShell : InstallablesCommand, RunCommon, MixEnvironment void run(ref store) override { - auto outPaths = toStorePaths(store, Realise::Outputs, OperateOn::Output, installables); + auto outPaths = toStorePaths(getEvalStore(), store, Realise::Outputs, OperateOn::Output, installables); auto accessor = store->getFSAccessor(); @@ -178,7 +178,7 @@ struct CmdRun : InstallableCommand, RunCommon { auto state = getEvalState(); - auto app = installable->toApp(*state).resolve(store); + auto app = installable->toApp(*state).resolve(getEvalStore(), store); Strings allArgs{app.program}; for (auto & i : args) allArgs.push_back(i); diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc index 7a4ca5172..2f6b361bb 100644 --- a/src/nix/why-depends.cc +++ b/src/nix/why-depends.cc @@ -62,9 +62,9 @@ struct CmdWhyDepends : SourceExprCommand void run(ref store) override { auto package = parseInstallable(store, _package); - auto packagePath = toStorePath(store, Realise::Outputs, operateOn, package); + auto packagePath = toStorePath(getEvalStore(), store, Realise::Outputs, operateOn, package); auto dependency = parseInstallable(store, _dependency); - auto dependencyPath = toStorePath(store, Realise::Derivation, operateOn, dependency); + auto dependencyPath = toStorePath(getEvalStore(), store, Realise::Derivation, operateOn, dependency); auto dependencyPathHash = dependencyPath.hashPart(); StorePathSet closure;