diff options
Diffstat (limited to 'src/nix')
-rw-r--r-- | src/nix/add-to-store.cc | 9 | ||||
-rw-r--r-- | src/nix/command.cc | 25 | ||||
-rw-r--r-- | src/nix/command.hh | 15 | ||||
-rw-r--r-- | src/nix/copy.cc | 4 | ||||
-rw-r--r-- | src/nix/dump-path.cc | 2 | ||||
-rw-r--r-- | src/nix/flake.cc | 13 | ||||
-rw-r--r-- | src/nix/installables.cc | 109 | ||||
-rw-r--r-- | src/nix/installables.hh | 7 | ||||
-rw-r--r-- | src/nix/local.mk | 2 | ||||
-rw-r--r-- | src/nix/log.cc | 2 | ||||
-rw-r--r-- | src/nix/ls.cc | 2 | ||||
-rw-r--r-- | src/nix/main.cc | 2 | ||||
-rw-r--r-- | src/nix/make-content-addressable.cc | 40 | ||||
-rw-r--r-- | src/nix/path-info.cc | 16 | ||||
-rw-r--r-- | src/nix/profile.cc | 49 | ||||
-rw-r--r-- | src/nix/progress-bar.cc | 11 | ||||
-rw-r--r-- | src/nix/repl.cc | 6 | ||||
-rw-r--r-- | src/nix/run.cc | 16 | ||||
-rw-r--r-- | src/nix/shell.cc | 23 | ||||
-rw-r--r-- | src/nix/show-derivation.cc | 18 | ||||
-rw-r--r-- | src/nix/sigs.cc | 18 | ||||
-rw-r--r-- | src/nix/upgrade-nix.cc | 27 | ||||
-rw-r--r-- | src/nix/verify.cc | 20 | ||||
-rw-r--r-- | src/nix/why-depends.cc | 30 |
24 files changed, 251 insertions, 215 deletions
diff --git a/src/nix/add-to-store.cc b/src/nix/add-to-store.cc index 296b2c7e4..139db3657 100644 --- a/src/nix/add-to-store.cc +++ b/src/nix/add-to-store.cc @@ -40,16 +40,17 @@ struct CmdAddToStore : MixDryRun, StoreCommand StringSink sink; dumpPath(path, sink); - ValidPathInfo info; - info.narHash = hashString(htSHA256, *sink.s); + auto narHash = hashString(htSHA256, *sink.s); + + ValidPathInfo info(store->makeFixedOutputPath(true, narHash, *namePart)); + info.narHash = narHash; info.narSize = sink.s->size(); - info.path = store->makeFixedOutputPath(true, info.narHash, *namePart); info.ca = makeFixedOutputCA(true, info.narHash); if (!dryRun) store->addToStore(info, sink.s); - std::cout << fmt("%s\n", info.path); + std::cout << fmt("%s\n", store->printStorePath(info.path)); } }; diff --git a/src/nix/command.cc b/src/nix/command.cc index 2da5736e7..99b24d2a2 100644 --- a/src/nix/command.cc +++ b/src/nix/command.cc @@ -51,28 +51,29 @@ StorePathsCommand::StorePathsCommand(bool recursive) void StorePathsCommand::run(ref<Store> store) { - Paths storePaths; + StorePaths storePaths; if (all) { if (installables.size()) throw UsageError("'--all' does not expect arguments"); for (auto & p : store->queryAllValidPaths()) - storePaths.push_back(p); + storePaths.push_back(p.clone()); } else { for (auto & p : toStorePaths(store, realiseMode, installables)) - storePaths.push_back(p); + storePaths.push_back(p.clone()); if (recursive) { - PathSet closure; - store->computeFSClosure(PathSet(storePaths.begin(), storePaths.end()), - closure, false, false); - storePaths = Paths(closure.begin(), closure.end()); + StorePathSet closure; + store->computeFSClosure(storePathsToSet(storePaths), closure, false, false); + storePaths.clear(); + for (auto & p : closure) + storePaths.push_back(p.clone()); } } - run(store, storePaths); + run(store, std::move(storePaths)); } void StorePathCommand::run(ref<Store> store) @@ -107,7 +108,7 @@ MixProfile::MixProfile() .dest(&profile); } -void MixProfile::updateProfile(const Path & storePath) +void MixProfile::updateProfile(const StorePath & storePath) { if (!profile) return; auto store = getStore().dynamic_pointer_cast<LocalFSStore>(); @@ -116,20 +117,20 @@ void MixProfile::updateProfile(const Path & storePath) switchLink(profile2, createGeneration( ref<LocalFSStore>(store), - profile2, storePath)); + profile2, store->printStorePath(storePath))); } void MixProfile::updateProfile(const Buildables & buildables) { if (!profile) return; - std::optional<Path> result; + std::optional<StorePath> result; for (auto & buildable : buildables) { for (auto & output : buildable.outputs) { if (result) throw Error("'--profile' requires that the arguments produce a single store path, but there are multiple"); - result = output.second; + result = output.second.clone(); } } diff --git a/src/nix/command.hh b/src/nix/command.hh index 4f3f6eb9e..ba75ba6e6 100644 --- a/src/nix/command.hh +++ b/src/nix/command.hh @@ -3,6 +3,7 @@ #include "installables.hh" #include "args.hh" #include "common-eval-args.hh" +#include "path.hh" #include <optional> @@ -35,8 +36,6 @@ struct EvalCommand : virtual StoreCommand, MixEvalArgs { ref<EvalState> getEvalState(); -private: - std::shared_ptr<EvalState> evalState; }; @@ -128,7 +127,7 @@ public: using StoreCommand::run; - virtual void run(ref<Store> store, Paths storePaths) = 0; + virtual void run(ref<Store> store, std::vector<StorePath> storePaths) = 0; void run(ref<Store> store) override; @@ -140,7 +139,7 @@ struct StorePathCommand : public InstallablesCommand { using StoreCommand::run; - virtual void run(ref<Store> store, const Path & storePath) = 0; + virtual void run(ref<Store> store, const StorePath & storePath) = 0; void run(ref<Store> store) override; }; @@ -167,13 +166,13 @@ static RegisterCommand registerCommand(const std::string & name) Buildables build(ref<Store> store, RealiseMode mode, std::vector<std::shared_ptr<Installable>> installables); -PathSet toStorePaths(ref<Store> store, RealiseMode mode, +std::set<StorePath> toStorePaths(ref<Store> store, RealiseMode mode, std::vector<std::shared_ptr<Installable>> installables); -Path toStorePath(ref<Store> store, RealiseMode mode, +StorePath toStorePath(ref<Store> store, RealiseMode mode, std::shared_ptr<Installable> installable); -PathSet toDerivations(ref<Store> store, +std::set<StorePath> toDerivations(ref<Store> store, std::vector<std::shared_ptr<Installable>> installables, bool useDeriver = false); @@ -188,7 +187,7 @@ struct MixProfile : virtual Args, virtual StoreCommand MixProfile(); /* If 'profile' is set, make it point at 'storePath'. */ - void updateProfile(const Path & storePath); + void updateProfile(const StorePath & storePath); /* If 'profile' is set, make it point at the store path produced by 'buildables'. */ diff --git a/src/nix/copy.cc b/src/nix/copy.cc index b1aceb15c..85c777d38 100644 --- a/src/nix/copy.cc +++ b/src/nix/copy.cc @@ -80,14 +80,14 @@ struct CmdCopy : StorePathsCommand return srcUri.empty() ? StoreCommand::createStore() : openStore(srcUri); } - void run(ref<Store> srcStore, Paths storePaths) override + void run(ref<Store> srcStore, StorePaths storePaths) override { if (srcUri.empty() && dstUri.empty()) throw UsageError("you must pass '--from' and/or '--to'"); ref<Store> dstStore = dstUri.empty() ? openStore() : openStore(dstUri); - copyPaths(srcStore, dstStore, PathSet(storePaths.begin(), storePaths.end()), + copyPaths(srcStore, dstStore, storePathsToSet(storePaths), NoRepair, checkSigs, substitute); } }; diff --git a/src/nix/dump-path.cc b/src/nix/dump-path.cc index 90f1552d9..bb741b572 100644 --- a/src/nix/dump-path.cc +++ b/src/nix/dump-path.cc @@ -20,7 +20,7 @@ struct CmdDumpPath : StorePathCommand }; } - void run(ref<Store> store, const Path & storePath) override + void run(ref<Store> store, const StorePath & storePath) override { FdSink sink(STDOUT_FILENO); store->narFromPath(storePath, sink); diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 6e7c5e2eb..22e994e58 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -263,22 +263,23 @@ struct CmdFlakeCheck : FlakeCommand, MixJSON if (!drvInfo) throw Error("flake attribute '%s' is not a derivation", attrPath); // FIXME: check meta attributes - return drvInfo->queryDrvPath(); + return store->parseStorePath(drvInfo->queryDrvPath()); } catch (Error & e) { e.addPrefix(fmt("while checking the derivation '" ANSI_BOLD "%s" ANSI_NORMAL "' at %s:\n", attrPath, pos)); throw; } }; - PathSet drvPaths; + std::vector<StorePathWithOutputs> drvPaths; auto checkApp = [&](const std::string & attrPath, Value & v, const Pos & pos) { try { auto app = App(*state, v); for (auto & i : app.context) { - auto [drvPath, outputName] = decodeContext(i); - if (!outputName.empty() && nix::isDerivation(drvPath)) - drvPaths.insert(drvPath + "!" + outputName); + auto [drvPathS, outputName] = decodeContext(i); + auto drvPath = store->parseStorePath(drvPathS); + if (!outputName.empty() && drvPath.isDerivation()) + drvPaths.emplace_back(drvPath); } } catch (Error & e) { e.addPrefix(fmt("while checking the app definition '" ANSI_BOLD "%s" ANSI_NORMAL "' at %s:\n", attrPath, pos)); @@ -388,7 +389,7 @@ struct CmdFlakeCheck : FlakeCommand, MixJSON fmt("%s.%s.%s", name, attr.name, attr2.name), *attr2.value, *attr2.pos); if ((std::string) attr.name == settings.thisSystem.get()) - drvPaths.insert(drvPath); + drvPaths.emplace_back(drvPath); } } } diff --git a/src/nix/installables.cc b/src/nix/installables.cc index 3e0fe2606..86b9fbdb9 100644 --- a/src/nix/installables.cc +++ b/src/nix/installables.cc @@ -118,20 +118,30 @@ App Installable::toApp(EvalState & state) struct InstallableStorePath : Installable { - Path storePath; + ref<Store> store; + StorePath storePath; - InstallableStorePath(const Path & storePath) : storePath(storePath) { } + InstallableStorePath(ref<Store> store, const Path & storePath) + : store(store), storePath(store->parseStorePath(storePath)) { } - std::string what() override { return storePath; } + std::string what() override { return store->printStorePath(storePath); } Buildables toBuildables() override { - return {{isDerivation(storePath) ? storePath : "", {{"out", storePath}}}}; + std::map<std::string, StorePath> outputs; + outputs.insert_or_assign("out", storePath.clone()); + Buildable b{ + .drvPath = storePath.isDerivation() ? storePath.clone() : std::optional<StorePath>(), + .outputs = std::move(outputs) + }; + Buildables bs; + bs.push_back(std::move(b)); + return bs; } - std::optional<Path> getStorePath() override + std::optional<StorePath> getStorePath() override { - return storePath; + return storePath.clone(); } }; @@ -149,8 +159,8 @@ std::vector<flake::EvalCache::Derivation> InstallableValue::toDerivations() std::vector<flake::EvalCache::Derivation> res; for (auto & drvInfo : drvInfos) { res.push_back({ - drvInfo.queryDrvPath(), - drvInfo.queryOutPath(), + state->store->parseStorePath(drvInfo.queryDrvPath()), + state->store->parseStorePath(drvInfo.queryOutPath()), drvInfo.queryOutputName() }); } @@ -160,19 +170,21 @@ std::vector<flake::EvalCache::Derivation> InstallableValue::toDerivations() Buildables InstallableValue::toBuildables() { + auto state = cmd.getEvalState(); + Buildables res; - PathSet drvPaths; + StorePathSet drvPaths; for (auto & drv : toDerivations()) { - Buildable b{drv.drvPath}; - drvPaths.insert(b.drvPath); + Buildable b{.drvPath = drv.drvPath.clone()}; + drvPaths.insert(drv.drvPath.clone()); auto outputName = drv.outputName; if (outputName == "") - throw Error("derivation '%s' lacks an 'outputName' attribute", b.drvPath); + throw Error("derivation '%s' lacks an 'outputName' attribute", state->store->printStorePath(*b.drvPath)); - b.outputs.emplace(outputName, drv.outPath); + b.outputs.emplace(outputName, drv.outPath.clone()); res.push_back(std::move(b)); } @@ -180,10 +192,13 @@ Buildables InstallableValue::toBuildables() // Hack to recognize .all: if all drvs have the same drvPath, // merge the buildables. if (drvPaths.size() == 1) { - Buildable b{*drvPaths.begin()}; + Buildable b{.drvPath = drvPaths.begin()->clone()}; for (auto & b2 : res) - b.outputs.insert(b2.outputs.begin(), b2.outputs.end()); - return {b}; + for (auto & output : b2.outputs) + b.outputs.insert_or_assign(output.first, output.second.clone()); + Buildables bs; + bs.push_back(std::move(b)); + return bs; } else return res; } @@ -231,10 +246,10 @@ void makeFlakeClosureGCRoot(Store & store, if (std::get_if<FlakeRef::IsPath>(&origFlakeRef.data)) return; /* Get the store paths of all non-local flakes. */ - PathSet closure; + StorePathSet closure; - assert(store.isValidPath(resFlake.flake.sourceInfo.storePath)); - closure.insert(resFlake.flake.sourceInfo.storePath); + assert(store.isValidPath(store.parseStorePath(resFlake.flake.sourceInfo.storePath))); + closure.insert(store.parseStorePath(resFlake.flake.sourceInfo.storePath)); std::queue<std::reference_wrapper<const flake::LockedInputs>> queue; queue.push(resFlake.lockFile); @@ -246,8 +261,8 @@ void makeFlakeClosureGCRoot(Store & store, yet. */ for (auto & dep : flake.inputs) { auto path = dep.second.computeStorePath(store); - if (store.isValidPath(path)) - closure.insert(path); + if (store.isValidPath(store.parseStorePath(path))) + closure.insert(store.parseStorePath(path)); queue.push(dep.second); } } @@ -255,7 +270,8 @@ void makeFlakeClosureGCRoot(Store & store, if (closure.empty()) return; /* Write the closure to a file in the store. */ - auto closurePath = store.addTextToStore("flake-closure", concatStringsSep(" ", closure), closure); + auto closurePath = store.addTextToStore("flake-closure", + concatStringsSep(" ", store.printStorePathSet(closure)), closure); Path cacheDir = getCacheDir() + "/nix/flake-closures"; createDirs(cacheDir); @@ -267,7 +283,7 @@ void makeFlakeClosureGCRoot(Store & store, s = replaceStrings(s, ":", "%3a"); Path symlink = cacheDir + "/" + s; debug("writing GC root '%s' for flake closure of '%s'", symlink, origFlakeRef); - replaceSymlink(closurePath, symlink); + replaceSymlink(store.printStorePath(closurePath), symlink); store.addIndirectRoot(symlink); } @@ -318,7 +334,7 @@ std::tuple<std::string, FlakeRef, flake::EvalCache::Derivation> InstallableFlake auto drv = evalCache.getDerivation(fingerprint, attrPath); if (drv) { if (state->store->isValidPath(drv->drvPath)) - return {attrPath, resFlake.flake.sourceInfo.resolvedRef, *drv}; + return {attrPath, resFlake.flake.sourceInfo.resolvedRef, std::move(*drv)}; } if (!vOutputs) @@ -333,14 +349,14 @@ std::tuple<std::string, FlakeRef, flake::EvalCache::Derivation> InstallableFlake throw Error("flake output attribute '%s' is not a derivation", attrPath); auto drv = flake::EvalCache::Derivation{ - drvInfo->queryDrvPath(), - drvInfo->queryOutPath(), + state->store->parseStorePath(drvInfo->queryDrvPath()), + state->store->parseStorePath(drvInfo->queryOutPath()), drvInfo->queryOutputName() }; evalCache.addDerivation(fingerprint, attrPath, drv); - return {attrPath, resFlake.flake.sourceInfo.resolvedRef, drv}; + return {attrPath, resFlake.flake.sourceInfo.resolvedRef, std::move(drv)}; } catch (AttrPathNotFound & e) { } } @@ -351,7 +367,9 @@ std::tuple<std::string, FlakeRef, flake::EvalCache::Derivation> InstallableFlake std::vector<flake::EvalCache::Derivation> InstallableFlake::toDerivations() { - return {std::get<2>(toDerivation())}; + std::vector<flake::EvalCache::Derivation> res; + res.push_back(std::get<2>(toDerivation())); + return res; } Value * InstallableFlake::toValue(EvalState & state) @@ -406,7 +424,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables( } else { - auto follow = [&](const std::string & s) -> std::optional<Path> { + auto follow = [&](const std::string & s) -> std::optional<StorePath> { try { return store->followLinksToStorePath(s); } catch (NotInStore &) { @@ -417,7 +435,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables( for (auto & s : ss) { size_t hash; - std::optional<Path> storePath; + std::optional<StorePath> storePath; if (hasPrefix(s, "nixpkgs.")) { bool static warned; @@ -440,7 +458,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables( *this, std::move(flakeRef), getDefaultFlakeAttrPaths())); } catch (...) { if (s.find('/') != std::string::npos && (storePath = follow(s))) - result.push_back(std::make_shared<InstallableStorePath>(*storePath)); + result.push_back(std::make_shared<InstallableStorePath>(store, store->printStorePath(*storePath))); else throw; } @@ -467,19 +485,18 @@ Buildables build(ref<Store> store, RealiseMode mode, Buildables buildables; - PathSet pathsToBuild; + std::vector<StorePathWithOutputs> pathsToBuild; for (auto & i : installables) { for (auto & b : i->toBuildables()) { - if (b.drvPath != "") { + if (b.drvPath) { StringSet outputNames; for (auto & output : b.outputs) outputNames.insert(output.first); - pathsToBuild.insert( - b.drvPath + "!" + concatStringsSep(",", outputNames)); + pathsToBuild.push_back({*b.drvPath, outputNames}); } else for (auto & output : b.outputs) - pathsToBuild.insert(output.second); + pathsToBuild.push_back({output.second.clone()}); buildables.push_back(std::move(b)); } } @@ -492,19 +509,19 @@ Buildables build(ref<Store> store, RealiseMode mode, return buildables; } -PathSet toStorePaths(ref<Store> store, RealiseMode mode, +StorePathSet toStorePaths(ref<Store> store, RealiseMode mode, std::vector<std::shared_ptr<Installable>> installables) { - PathSet outPaths; + StorePathSet outPaths; for (auto & b : build(store, mode, installables)) for (auto & output : b.outputs) - outPaths.insert(output.second); + outPaths.insert(output.second.clone()); return outPaths; } -Path toStorePath(ref<Store> store, RealiseMode mode, +StorePath toStorePath(ref<Store> store, RealiseMode mode, std::shared_ptr<Installable> installable) { auto paths = toStorePaths(store, mode, {installable}); @@ -512,17 +529,17 @@ Path toStorePath(ref<Store> store, RealiseMode mode, if (paths.size() != 1) throw Error("argument '%s' should evaluate to one store path", installable->what()); - return *paths.begin(); + return paths.begin()->clone(); } -PathSet toDerivations(ref<Store> store, +StorePathSet toDerivations(ref<Store> store, std::vector<std::shared_ptr<Installable>> installables, bool useDeriver) { - PathSet drvPaths; + StorePathSet drvPaths; for (auto & i : installables) for (auto & b : i->toBuildables()) { - if (b.drvPath.empty()) { + if (!b.drvPath) { if (!useDeriver) throw Error("argument '%s' did not evaluate to a derivation", i->what()); for (auto & output : b.outputs) { @@ -530,10 +547,10 @@ PathSet toDerivations(ref<Store> store, if (derivers.empty()) throw Error("'%s' does not have a known deriver", i->what()); // FIXME: use all derivers? - drvPaths.insert(*derivers.begin()); + drvPaths.insert(derivers.begin()->clone()); } } else - drvPaths.insert(b.drvPath); + drvPaths.insert(b.drvPath->clone()); } return drvPaths; diff --git a/src/nix/installables.hh b/src/nix/installables.hh index 612c8ac92..22e4b38f9 100644 --- a/src/nix/installables.hh +++ b/src/nix/installables.hh @@ -1,6 +1,7 @@ #pragma once #include "util.hh" +#include "path.hh" #include "flake/eval-cache.hh" #include <optional> @@ -14,8 +15,8 @@ struct SourceExprCommand; struct Buildable { - Path drvPath; // may be empty - std::map<std::string, Path> outputs; + std::optional<StorePath> drvPath; + std::map<std::string, StorePath> outputs; }; typedef std::vector<Buildable> Buildables; @@ -51,7 +52,7 @@ struct Installable /* Return a value only if this installable is a store path or a symlink to it. */ - virtual std::optional<Path> getStorePath() + virtual std::optional<StorePath> getStorePath() { return {}; } diff --git a/src/nix/local.mk b/src/nix/local.mk index 44a95f910..fff101a63 100644 --- a/src/nix/local.mk +++ b/src/nix/local.mk @@ -15,7 +15,7 @@ nix_SOURCES := \ $(wildcard src/nix-prefetch-url/*.cc) \ $(wildcard src/nix-store/*.cc) \ -nix_LIBS = libexpr libmain libstore libutil +nix_LIBS = libexpr libmain libstore libutil libnixrust nix_LDFLAGS = -pthread $(SODIUM_LIBS) $(EDITLINE_LIBS) $(BOOST_LDFLAGS) -lboost_context -lboost_thread -lboost_system diff --git a/src/nix/log.cc b/src/nix/log.cc index 122a3d690..795991cb7 100644 --- a/src/nix/log.cc +++ b/src/nix/log.cc @@ -43,7 +43,7 @@ struct CmdLog : InstallableCommand RunPager pager; for (auto & sub : subs) { - auto log = b.drvPath != "" ? sub->getBuildLog(b.drvPath) : nullptr; + auto log = b.drvPath ? sub->getBuildLog(*b.drvPath) : nullptr; for (auto & output : b.outputs) { if (log) break; log = sub->getBuildLog(output.second); diff --git a/src/nix/ls.cc b/src/nix/ls.cc index 9408cc9da..3ef1f2750 100644 --- a/src/nix/ls.cc +++ b/src/nix/ls.cc @@ -67,7 +67,7 @@ struct MixLs : virtual Args, MixJSON if (st.type == FSAccessor::Type::tMissing) throw Error(format("path '%1%' does not exist") % path); doPath(st, path, - st.type == FSAccessor::Type::tDirectory ? "." : baseNameOf(path), + st.type == FSAccessor::Type::tDirectory ? "." : std::string(baseNameOf(path)), showDirectory); } diff --git a/src/nix/main.cc b/src/nix/main.cc index 272c944ba..f0e6cac4c 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -140,7 +140,7 @@ void mainWrapped(int argc, char * * argv) initGC(); programPath = argv[0]; - string programName = baseNameOf(programPath); + auto programName = std::string(baseNameOf(programPath)); { auto legacy = (*RegisterLegacyCommand::commands)[programName]; diff --git a/src/nix/make-content-addressable.cc b/src/nix/make-content-addressable.cc index 5b99b5084..524d467c2 100644 --- a/src/nix/make-content-addressable.cc +++ b/src/nix/make-content-addressable.cc @@ -29,34 +29,36 @@ struct CmdMakeContentAddressable : StorePathsCommand }, }; } - void run(ref<Store> store, Paths storePaths) override + void run(ref<Store> store, StorePaths storePaths) override { - auto paths = store->topoSortPaths(PathSet(storePaths.begin(), storePaths.end())); + auto paths = store->topoSortPaths(storePathsToSet(storePaths)); - paths.reverse(); + std::reverse(paths.begin(), paths.end()); - std::map<Path, Path> remappings; + std::map<StorePath, StorePath> remappings; for (auto & path : paths) { + auto pathS = store->printStorePath(path); auto oldInfo = store->queryPathInfo(path); - auto oldHashPart = storePathToHash(path); - auto name = storePathToName(path); + auto oldHashPart = storePathToHash(pathS); StringSink sink; store->narFromPath(path, sink); StringMap rewrites; - ValidPathInfo info; + StorePathSet references; + bool hasSelfReference = false; for (auto & ref : oldInfo->references) { if (ref == path) - info.references.insert("self"); + hasSelfReference = true; else { - auto replacement = get(remappings, ref, ref); + auto i = remappings.find(ref); + auto replacement = i != remappings.end() ? i->second.clone() : ref.clone(); // FIXME: warn about unremapped paths? - info.references.insert(replacement); if (replacement != ref) - rewrites[storePathToHash(ref)] = storePathToHash(replacement); + rewrites.insert_or_assign(store->printStorePath(ref), store->printStorePath(replacement)); + references.insert(std::move(replacement)); } } @@ -65,24 +67,26 @@ struct CmdMakeContentAddressable : StorePathsCommand HashModuloSink hashModuloSink(htSHA256, oldHashPart); hashModuloSink((unsigned char *) sink.s->data(), sink.s->size()); - info.narHash = hashModuloSink.finish().first; + auto narHash = hashModuloSink.finish().first; + + ValidPathInfo info(store->makeFixedOutputPath(true, narHash, path.name(), references, hasSelfReference)); + info.references = std::move(references); + if (hasSelfReference) info.references.insert(info.path.clone()); + info.narHash = narHash; info.narSize = sink.s->size(); - replaceInSet(info.references, path, std::string("self")); - info.path = store->makeFixedOutputPath(true, info.narHash, name, info.references); - replaceInSet(info.references, std::string("self"), info.path); info.ca = makeFixedOutputCA(true, info.narHash); - printError("rewrote '%s' to '%s'", path, info.path); + printError("rewrote '%s' to '%s'", pathS, store->printStorePath(info.path)); auto source = sinkToSource([&](Sink & nextSink) { - RewritingSink rsink2(oldHashPart, storePathToHash(info.path), nextSink); + RewritingSink rsink2(oldHashPart, storePathToHash(store->printStorePath(info.path)), nextSink); rsink2((unsigned char *) sink.s->data(), sink.s->size()); rsink2.flush(); }); store->addToStore(info, *source); - remappings[path] = info.path; + remappings.insert_or_assign(std::move(path), std::move(info.path)); } } }; diff --git a/src/nix/path-info.cc b/src/nix/path-info.cc index 2cb718f12..bffa7b356 100644 --- a/src/nix/path-info.cc +++ b/src/nix/path-info.cc @@ -78,36 +78,36 @@ struct CmdPathInfo : StorePathsCommand, MixJSON std::cout << fmt("\t%6.1f%c", res, idents.at(power)); } - void run(ref<Store> store, Paths storePaths) override + void run(ref<Store> store, StorePaths storePaths) override { size_t pathLen = 0; for (auto & storePath : storePaths) - pathLen = std::max(pathLen, storePath.size()); + pathLen = std::max(pathLen, store->printStorePath(storePath).size()); if (json) { JSONPlaceholder jsonRoot(std::cout); store->pathInfoToJSON(jsonRoot, // FIXME: preserve order? - PathSet(storePaths.begin(), storePaths.end()), + storePathsToSet(storePaths), true, showClosureSize, AllowInvalid); } else { - for (auto storePath : storePaths) { + for (auto & storePath : storePaths) { auto info = store->queryPathInfo(storePath); - storePath = info->path; // FIXME: screws up padding + auto storePathS = store->printStorePath(storePath); - std::cout << storePath; + std::cout << storePathS; if (showSize || showClosureSize || showSigs) - std::cout << std::string(std::max(0, (int) pathLen - (int) storePath.size()), ' '); + std::cout << std::string(std::max(0, (int) pathLen - (int) storePathS.size()), ' '); if (showSize) printSize(info->narSize); if (showClosureSize) - printSize(store->getClosureSize(storePath).first); + printSize(store->getClosureSize(info->path).first); if (showSigs) { std::cout << '\t'; diff --git a/src/nix/profile.cc b/src/nix/profile.cc index 786ebddef..6ea529f52 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -24,7 +24,7 @@ struct ProfileElementSource struct ProfileElement { - PathSet storePaths; + StorePathSet storePaths; std::optional<ProfileElementSource> source; bool active = true; // FIXME: priority @@ -50,7 +50,7 @@ struct ProfileManifest for (auto & e : json["elements"]) { ProfileElement element; for (auto & p : e["storePaths"]) - element.storePaths.insert((std::string) p); + element.storePaths.insert(state.store->parseStorePath((std::string) p)); element.active = e["active"]; if (e.value("uri", "") != "") { element.source = ProfileElementSource{ @@ -74,19 +74,19 @@ struct ProfileManifest for (auto & drvInfo : drvInfos) { ProfileElement element; - element.storePaths = {drvInfo.queryOutPath()}; + element.storePaths = singleton(state.store->parseStorePath(drvInfo.queryOutPath())); elements.emplace_back(std::move(element)); } } } - std::string toJSON() const + std::string toJSON(Store & store) const { auto array = nlohmann::json::array(); for (auto & element : elements) { auto paths = nlohmann::json::array(); for (auto & path : element.storePaths) - paths.push_back(path); + paths.push_back(store.printStorePath(path)); nlohmann::json obj; obj["storePaths"] = paths; obj["active"] = element.active; @@ -103,37 +103,38 @@ struct ProfileManifest return json.dump(); } - Path build(ref<Store> store) + StorePath build(ref<Store> store) { auto tempDir = createTempDir(); - ValidPathInfo info; + StorePathSet references; Packages pkgs; for (auto & element : elements) { for (auto & path : element.storePaths) { if (element.active) - pkgs.emplace_back(path, true, 5); - info.references.insert(path); + pkgs.emplace_back(store->printStorePath(path), true, 5); + references.insert(path.clone()); } } buildProfile(tempDir, std::move(pkgs)); - writeFile(tempDir + "/manifest.json", toJSON()); + writeFile(tempDir + "/manifest.json", toJSON(*store)); /* Add the symlink tree to the store. */ StringSink sink; dumpPath(tempDir, sink); + ValidPathInfo info(store->makeFixedOutputPath(true, info.narHash, "profile", references)); + info.references = std::move(references); info.narHash = hashString(htSHA256, *sink.s); info.narSize = sink.s->size(); - info.path = store->makeFixedOutputPath(true, info.narHash, "profile", info.references); info.ca = makeFixedOutputCA(true, info.narHash); store->addToStore(info, sink.s); - return info.path; + return std::move(info.path); } }; @@ -166,21 +167,21 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile { ProfileManifest manifest(*getEvalState(), *profile); - PathSet pathsToBuild; + std::vector<StorePathWithOutputs> pathsToBuild; for (auto & installable : installables) { if (auto installable2 = std::dynamic_pointer_cast<InstallableFlake>(installable)) { auto [attrPath, resolvedRef, drv] = installable2->toDerivation(); ProfileElement element; - element.storePaths = {drv.outPath}; // FIXME + element.storePaths = singleton(drv.outPath.clone()); // FIXME element.source = ProfileElementSource{ installable2->flakeRef, resolvedRef, attrPath, }; - pathsToBuild.insert(makeDrvPathWithOutputs(drv.drvPath, {"out"})); // FIXME + pathsToBuild.emplace_back(drv.drvPath.clone(), StringSet{"out"}); // FIXME manifest.elements.emplace_back(std::move(element)); } else @@ -223,13 +224,13 @@ public: return res; } - bool matches(const ProfileElement & element, size_t pos, std::vector<Matcher> matchers) + bool matches(const Store & store, const ProfileElement & element, size_t pos, const std::vector<Matcher> & matchers) { for (auto & matcher : matchers) { if (auto n = std::get_if<size_t>(&matcher)) { if (*n == pos) return true; } else if (auto path = std::get_if<Path>(&matcher)) { - if (element.storePaths.count(*path)) return true; + if (element.storePaths.count(store.parseStorePath(*path))) return true; } else if (auto regex = std::get_if<std::regex>(&matcher)) { if (element.source && std::regex_match(element.source->attrPath, *regex)) @@ -280,8 +281,8 @@ struct CmdProfileRemove : virtual EvalCommand, MixDefaultProfile, MixProfileElem for (size_t i = 0; i < oldManifest.elements.size(); ++i) { auto & element(oldManifest.elements[i]); - if (!matches(element, i, matchers)) - newManifest.elements.push_back(element); + if (!matches(*store, element, i, matchers)) + newManifest.elements.push_back(std::move(element)); } // FIXME: warn about unused matchers? @@ -322,13 +323,13 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf auto matchers = getMatchers(store); // FIXME: code duplication - PathSet pathsToBuild; + std::vector<StorePathWithOutputs> pathsToBuild; for (size_t i = 0; i < manifest.elements.size(); ++i) { auto & element(manifest.elements[i]); if (element.source && !element.source->originalRef.isImmutable() - && matches(element, i, matchers)) + && matches(*store, element, i, matchers)) { Activity act(*logger, lvlChatty, actUnknown, fmt("checking '%s' for updates", element.source->attrPath)); @@ -342,14 +343,14 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf printInfo("upgrading '%s' from flake '%s' to '%s'", element.source->attrPath, element.source->resolvedRef, resolvedRef); - element.storePaths = {drv.outPath}; // FIXME + element.storePaths = singleton(drv.outPath.clone()); // FIXME element.source = ProfileElementSource{ installable.flakeRef, resolvedRef, attrPath, }; - pathsToBuild.insert(makeDrvPathWithOutputs(drv.drvPath, {"out"})); // FIXME + pathsToBuild.emplace_back(drv.drvPath, StringSet{"out"}); // FIXME } } @@ -385,7 +386,7 @@ struct CmdProfileInfo : virtual EvalCommand, virtual StoreCommand, MixDefaultPro std::cout << fmt("%d %s %s %s\n", i, element.source ? element.source->originalRef.to_string() + "#" + element.source->attrPath : "-", element.source ? element.source->resolvedRef.to_string() + "#" + element.source->attrPath : "-", - concatStringsSep(" ", element.storePaths)); + concatStringsSep(" ", store->printStorePathSet(element.storePaths))); } } }; diff --git a/src/nix/progress-bar.cc b/src/nix/progress-bar.cc index 661966733..d20c09f26 100644 --- a/src/nix/progress-bar.cc +++ b/src/nix/progress-bar.cc @@ -24,6 +24,13 @@ static uint64_t getI(const std::vector<Logger::Field> & fields, size_t n) return fields[n].i; } +static std::string_view storePathToName(std::string_view path) +{ + auto base = baseNameOf(path); + auto i = base.find('-'); + return i == std::string::npos ? base.substr(0, 0) : base.substr(i + 1); +} + class ProgressBar : public Logger { private: @@ -148,7 +155,7 @@ public: if (type == actBuild) { auto name = storePathToName(getS(fields, 0)); if (hasSuffix(name, ".drv")) - name.resize(name.size() - 4); + name = name.substr(name.size() - 4); i->s = fmt("building " ANSI_BOLD "%s" ANSI_NORMAL, name); auto machineName = getS(fields, 1); if (machineName != "") @@ -173,7 +180,7 @@ public: if (type == actPostBuildHook) { auto name = storePathToName(getS(fields, 0)); if (hasSuffix(name, ".drv")) - name.resize(name.size() - 4); + name = name.substr(name.size() - 4); i->s = fmt("post-build " ANSI_BOLD "%s" ANSI_NORMAL, name); i->name = DrvName(name).name; } diff --git a/src/nix/repl.cc b/src/nix/repl.cc index 2b4d1a2c4..9f76e1b4f 100644 --- a/src/nix/repl.cc +++ b/src/nix/repl.cc @@ -413,7 +413,7 @@ Path NixRepl::getDerivationPath(Value & v) { if (!drvInfo) throw Error("expression does not evaluate to a derivation, so I can't build it"); Path drvPath = drvInfo->queryDrvPath(); - if (drvPath == "" || !state.store->isValidPath(drvPath)) + if (drvPath == "" || !state.store->isValidPath(state.store->parseStorePath(drvPath))) throw Error("expression did not evaluate to a valid derivation"); return drvPath; } @@ -521,10 +521,10 @@ bool NixRepl::processLine(string line) but doing it in a child makes it easier to recover from problems / SIGINT. */ if (runProgram(settings.nixBinDir + "/nix", Strings{"build", "--no-link", drvPath}) == 0) { - Derivation drv = readDerivation(drvPath); + auto drv = readDerivation(*state.store, drvPath); std::cout << std::endl << "this derivation produced the following outputs:" << std::endl; for (auto & i : drv.outputs) - std::cout << format(" %1% -> %2%") % i.first % i.second.path << std::endl; + std::cout << fmt(" %s -> %s\n", i.first, state.store->printStorePath(i.second.path)); } } else if (command == ":i") { runProgram(settings.nixBinDir + "/nix-env", Strings{"-i", drvPath}); diff --git a/src/nix/run.cc b/src/nix/run.cc index 2865f5bbb..7fd9c4c7e 100644 --- a/src/nix/run.cc +++ b/src/nix/run.cc @@ -109,26 +109,26 @@ struct CmdRun : InstallablesCommand, RunCommon, MixEnvironment auto accessor = store->getFSAccessor(); - std::unordered_set<Path> done; - std::queue<Path> todo; - for (auto & path : outPaths) todo.push(path); + std::unordered_set<StorePath> done; + std::queue<StorePath> todo; + for (auto & path : outPaths) todo.push(path.clone()); setEnviron(); auto unixPath = tokenizeString<Strings>(getEnv("PATH").value_or(""), ":"); while (!todo.empty()) { - Path path = todo.front(); + auto path = todo.front().clone(); todo.pop(); - if (!done.insert(path).second) continue; + if (!done.insert(path.clone()).second) continue; if (true) - unixPath.push_front(path + "/bin"); + unixPath.push_front(store->printStorePath(path) + "/bin"); - auto propPath = path + "/nix-support/propagated-user-env-packages"; + auto propPath = store->printStorePath(path) + "/nix-support/propagated-user-env-packages"; if (accessor->stat(propPath).type == FSAccessor::tRegular) { for (auto & p : tokenizeString<Paths>(readFile(propPath))) - todo.push(p); + todo.push(store->parseStorePath(p)); } } diff --git a/src/nix/shell.cc b/src/nix/shell.cc index 6d5f1603c..6b3d02b6b 100644 --- a/src/nix/shell.cc +++ b/src/nix/shell.cc @@ -88,7 +88,7 @@ BuildEnvironment readEnvironment(const Path & path) modified derivation with the same dependencies and nearly the same initial environment variables, that just writes the resulting environment to a file and exits. */ -Path getDerivationEnvironment(ref<Store> store, Derivation drv) +StorePath getDerivationEnvironment(ref<Store> store, Derivation drv) { auto builder = baseNameOf(drv.builder); if (builder != "bash") @@ -120,12 +120,11 @@ Path getDerivationEnvironment(ref<Store> store, Derivation drv) drv.env.erase(output.first); drv.env["out"] = ""; drv.env["outputs"] = "out"; - drv.outputs["out"] = DerivationOutput("", "", ""); - Hash h = hashDerivationModulo(*store, drv); - Path shellOutPath = store->makeOutputPath("out", h, drvName); - drv.outputs["out"].path = shellOutPath; - drv.env["out"] = shellOutPath; - Path shellDrvPath2 = writeDerivation(store, drv, drvName); + Hash h = hashDerivationModulo(*store, drv, true); + auto shellOutPath = store->makeOutputPath("out", h, drvName); + drv.outputs.insert_or_assign("out", DerivationOutput(shellOutPath.clone(), "", "")); + drv.env["out"] = store->printStorePath(shellOutPath); + auto shellDrvPath2 = writeDerivation(store, drv, drvName); /* Build the derivation. */ store->buildPaths({shellDrvPath2}); @@ -203,11 +202,11 @@ struct Common : InstallableCommand, MixProfile return {"devShell." + settings.thisSystem.get(), "defaultPackage." + settings.thisSystem.get()}; } - Path getShellOutPath(ref<Store> store) + StorePath getShellOutPath(ref<Store> store) { auto path = installable->getStorePath(); - if (path && hasSuffix(*path, "-env")) - return *path; + if (path && hasSuffix(path->to_string(), "-env")) + return path->clone(); else { auto drvs = toDerivations(store, {installable}); @@ -227,7 +226,7 @@ struct Common : InstallableCommand, MixProfile updateProfile(shellOutPath); - return readEnvironment(shellOutPath); + return readEnvironment(store->printStorePath(shellOutPath)); } }; @@ -279,7 +278,7 @@ struct CmdDevShell : Common, MixEnvironment setEnviron(); - auto args = Strings{baseNameOf(shell), "--rcfile", rcFilePath}; + auto args = Strings{std::string(baseNameOf(shell)), "--rcfile", rcFilePath}; restoreAffinity(); restoreSignals(); diff --git a/src/nix/show-derivation.cc b/src/nix/show-derivation.cc index 6065adc4d..0ede7b468 100644 --- a/src/nix/show-derivation.cc +++ b/src/nix/show-derivation.cc @@ -46,9 +46,9 @@ struct CmdShowDerivation : InstallablesCommand auto drvPaths = toDerivations(store, installables, true); if (recursive) { - PathSet closure; + StorePathSet closure; store->computeFSClosure(drvPaths, closure); - drvPaths = closure; + drvPaths = std::move(closure); } { @@ -56,17 +56,19 @@ struct CmdShowDerivation : InstallablesCommand JSONObject jsonRoot(std::cout, true); for (auto & drvPath : drvPaths) { - if (!isDerivation(drvPath)) continue; + if (!drvPath.isDerivation()) continue; - auto drvObj(jsonRoot.object(drvPath)); + auto drvPathS = store->printStorePath(drvPath); - auto drv = readDerivation(drvPath); + auto drvObj(jsonRoot.object(drvPathS)); + + auto drv = readDerivation(*store, drvPathS); { auto outputsObj(drvObj.object("outputs")); for (auto & output : drv.outputs) { auto outputObj(outputsObj.object(output.first)); - outputObj.attr("path", output.second.path); + outputObj.attr("path", store->printStorePath(output.second.path)); if (output.second.hash != "") { outputObj.attr("hashAlgo", output.second.hashAlgo); outputObj.attr("hash", output.second.hash); @@ -77,13 +79,13 @@ struct CmdShowDerivation : InstallablesCommand { auto inputsList(drvObj.list("inputSrcs")); for (auto & input : drv.inputSrcs) - inputsList.elem(input); + inputsList.elem(store->printStorePath(input)); } { auto inputDrvsObj(drvObj.object("inputDrvs")); for (auto & input : drv.inputDrvs) { - auto inputList(inputDrvsObj.list(input.first)); + auto inputList(inputDrvsObj.list(store->printStorePath(input.first))); for (auto & outputId : input.second) inputList.elem(outputId); } diff --git a/src/nix/sigs.cc b/src/nix/sigs.cc index 23bc83ad0..5f07448e0 100644 --- a/src/nix/sigs.cc +++ b/src/nix/sigs.cc @@ -27,7 +27,7 @@ struct CmdCopySigs : StorePathsCommand return "copy path signatures from substituters (like binary caches)"; } - void run(ref<Store> store, Paths storePaths) override + void run(ref<Store> store, StorePaths storePaths) override { if (substituterUris.empty()) throw UsageError("you must specify at least one substituter using '-s'"); @@ -44,18 +44,20 @@ struct CmdCopySigs : StorePathsCommand //logger->setExpected(doneLabel, storePaths.size()); - auto doPath = [&](const Path & storePath) { + auto doPath = [&](const Path & storePathS) { //Activity act(*logger, lvlInfo, format("getting signatures for '%s'") % storePath); checkInterrupt(); + auto storePath = store->parseStorePath(storePathS); + auto info = store->queryPathInfo(storePath); StringSet newSigs; for (auto & store2 : substituters) { try { - auto info2 = store2->queryPathInfo(storePath); + auto info2 = store2->queryPathInfo(info->path); /* Don't import signatures that don't match this binary. */ @@ -80,11 +82,11 @@ struct CmdCopySigs : StorePathsCommand }; for (auto & storePath : storePaths) - pool.enqueue(std::bind(doPath, storePath)); + pool.enqueue(std::bind(doPath, store->printStorePath(storePath))); pool.process(); - printInfo(format("imported %d signatures") % added); + printInfo("imported %d signatures", added); } }; @@ -109,7 +111,7 @@ struct CmdSignPaths : StorePathsCommand return "sign the specified paths"; } - void run(ref<Store> store, Paths storePaths) override + void run(ref<Store> store, StorePaths storePaths) override { if (secretKeyFile.empty()) throw UsageError("you must specify a secret key file using '-k'"); @@ -123,7 +125,7 @@ struct CmdSignPaths : StorePathsCommand auto info2(*info); info2.sigs.clear(); - info2.sign(secretKey); + info2.sign(*store, secretKey); assert(!info2.sigs.empty()); if (!info->sigs.count(*info2.sigs.begin())) { @@ -132,7 +134,7 @@ struct CmdSignPaths : StorePathsCommand } } - printInfo(format("added %d signatures") % added); + printInfo("added %d signatures", added); } }; diff --git a/src/nix/upgrade-nix.cc b/src/nix/upgrade-nix.cc index e6c369a7c..87f1f9d1b 100644 --- a/src/nix/upgrade-nix.cc +++ b/src/nix/upgrade-nix.cc @@ -58,13 +58,9 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand printInfo("upgrading Nix in profile '%s'", profileDir); - Path storePath; - { - Activity act(*logger, lvlInfo, actUnknown, "querying latest Nix version"); - storePath = getLatestNix(store); - } + auto storePath = getLatestNix(store); - auto version = DrvName(storePathToName(storePath)).version; + auto version = DrvName(storePath.name()).version; if (dryRun) { stopProgressBar(); @@ -73,13 +69,13 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand } { - Activity act(*logger, lvlInfo, actUnknown, fmt("downloading '%s'...", storePath)); + Activity act(*logger, lvlInfo, actUnknown, fmt("downloading '%s'...", store->printStorePath(storePath))); store->ensurePath(storePath); } { - Activity act(*logger, lvlInfo, actUnknown, fmt("verifying that '%s' works...", storePath)); - auto program = storePath + "/bin/nix-env"; + Activity act(*logger, lvlInfo, actUnknown, fmt("verifying that '%s' works...", store->printStorePath(storePath))); + auto program = store->printStorePath(storePath) + "/bin/nix-env"; auto s = runProgram(program, false, {"--version"}); if (s.find("Nix") == std::string::npos) throw Error("could not verify that '%s' works", program); @@ -88,9 +84,10 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand stopProgressBar(); { - Activity act(*logger, lvlInfo, actUnknown, fmt("installing '%s' into profile '%s'...", storePath, profileDir)); + Activity act(*logger, lvlInfo, actUnknown, + fmt("installing '%s' into profile '%s'...", store->printStorePath(storePath), profileDir)); runProgram(settings.nixBinDir + "/nix-env", false, - {"--profile", profileDir, "-i", storePath, "--no-sandbox"}); + {"--profile", profileDir, "-i", store->printStorePath(storePath), "--no-sandbox"}); } printError(ANSI_GREEN "upgrade to version %s done" ANSI_NORMAL, version); @@ -129,15 +126,17 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand !hasSuffix(userEnv, "user-environment")) throw Error("directory '%s' does not appear to be part of a Nix profile", where); - if (!store->isValidPath(userEnv)) + if (!store->isValidPath(store->parseStorePath(userEnv))) throw Error("directory '%s' is not in the Nix store", userEnv); return profileDir; } /* Return the store path of the latest stable Nix. */ - Path getLatestNix(ref<Store> store) + StorePath getLatestNix(ref<Store> store) { + Activity act(*logger, lvlInfo, actUnknown, "querying latest Nix version"); + // FIXME: use nixos.org? auto req = DownloadRequest(storePathsUrl); auto res = getDownloader()->download(req); @@ -148,7 +147,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand Bindings & bindings(*state->allocBindings(0)); auto v2 = findAlongAttrPath(*state, settings.thisSystem, bindings, *v); - return state->forceString(*v2); + return store->parseStorePath(state->forceString(*v2)); } }; diff --git a/src/nix/verify.cc b/src/nix/verify.cc index fa1414196..9b0658803 100644 --- a/src/nix/verify.cc +++ b/src/nix/verify.cc @@ -49,7 +49,7 @@ struct CmdVerify : StorePathsCommand }; } - void run(ref<Store> store, Paths storePaths) override + void run(ref<Store> store, StorePaths storePaths) override { std::vector<ref<Store>> substituters; for (auto & s : substituterUris) @@ -80,7 +80,7 @@ struct CmdVerify : StorePathsCommand MaintainCount<std::atomic<size_t>> mcActive(active); update(); - auto info = store->queryPathInfo(storePath); + auto info = store->queryPathInfo(store->parseStorePath(storePath)); if (!noContents) { @@ -88,7 +88,7 @@ struct CmdVerify : StorePathsCommand if (info->ca == "") hashSink = std::make_unique<HashSink>(info->narHash.type); else - hashSink = std::make_unique<HashModuloSink>(info->narHash.type, storePathToHash(info->path)); + hashSink = std::make_unique<HashModuloSink>(info->narHash.type, storePathToHash(store->printStorePath(info->path))); store->narFromPath(info->path, *hashSink); @@ -96,10 +96,10 @@ struct CmdVerify : StorePathsCommand if (hash.first != info->narHash) { corrupted++; - act2.result(resCorruptedPath, info->path); + act2.result(resCorruptedPath, store->printStorePath(info->path)); printError( - format("path '%s' was modified! expected hash '%s', got '%s'") - % info->path % info->narHash.to_string() % hash.first.to_string()); + "path '%s' was modified! expected hash '%s', got '%s'", + store->printStorePath(info->path), info->narHash.to_string(), hash.first.to_string()); } } @@ -120,7 +120,7 @@ struct CmdVerify : StorePathsCommand auto doSigs = [&](StringSet sigs) { for (auto sig : sigs) { if (!sigsSeen.insert(sig).second) continue; - if (validSigs < ValidPathInfo::maxSigs && info->checkSignature(publicKeys, sig)) + if (validSigs < ValidPathInfo::maxSigs && info->checkSignature(*store, publicKeys, sig)) validSigs++; } }; @@ -147,8 +147,8 @@ struct CmdVerify : StorePathsCommand if (!good) { untrusted++; - act2.result(resUntrustedPath, info->path); - printError(format("path '%s' is untrusted") % info->path); + act2.result(resUntrustedPath, store->printStorePath(info->path)); + printError("path '%s' is untrusted", store->printStorePath(info->path)); } } @@ -164,7 +164,7 @@ struct CmdVerify : StorePathsCommand }; for (auto & storePath : storePaths) - pool.enqueue(std::bind(doPath, storePath)); + pool.enqueue(std::bind(doPath, store->printStorePath(storePath))); pool.process(); diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc index 3d13a77e4..c539adb7f 100644 --- a/src/nix/why-depends.cc +++ b/src/nix/why-depends.cc @@ -73,9 +73,9 @@ struct CmdWhyDepends : SourceExprCommand auto packagePath = toStorePath(store, Build, package); auto dependency = parseInstallable(store, _dependency); auto dependencyPath = toStorePath(store, NoBuild, dependency); - auto dependencyPathHash = storePathToHash(dependencyPath); + auto dependencyPathHash = storePathToHash(store->printStorePath(dependencyPath)); - PathSet closure; + StorePathSet closure; store->computeFSClosure({packagePath}, closure, false, false); if (!closure.count(dependencyPath)) { @@ -91,28 +91,28 @@ struct CmdWhyDepends : SourceExprCommand struct Node { - Path path; - PathSet refs; - PathSet rrefs; + StorePath path; + StorePathSet refs; + StorePathSet rrefs; size_t dist = inf; Node * prev = nullptr; bool queued = false; bool visited = false; }; - std::map<Path, Node> graph; + std::map<StorePath, Node> graph; for (auto & path : closure) - graph.emplace(path, Node{path, store->queryPathInfo(path)->references}); + graph.emplace(path.clone(), Node{path.clone(), cloneStorePathSet(store->queryPathInfo(path)->references)}); // Transpose the graph. for (auto & node : graph) for (auto & ref : node.second.refs) - graph[ref].rrefs.insert(node.first); + graph.find(ref)->second.rrefs.insert(node.first.clone()); /* Run Dijkstra's shortest path algorithm to get the distance of every path in the closure to 'dependency'. */ - graph[dependencyPath].dist = 0; + graph[dependencyPath.clone()].dist = 0; std::priority_queue<Node *> queue; @@ -151,12 +151,14 @@ struct CmdWhyDepends : SourceExprCommand struct BailOut { }; printNode = [&](Node & node, const string & firstPad, const string & tailPad) { + auto pathS = store->printStorePath(node.path); + assert(node.dist != inf); std::cout << fmt("%s%s%s%s" ANSI_NORMAL "\n", firstPad, node.visited ? "\e[38;5;244m" : "", firstPad != "" ? "=> " : "", - node.path); + pathS); if (node.path == dependencyPath && !all && packagePath != dependencyPath) @@ -175,7 +177,7 @@ struct CmdWhyDepends : SourceExprCommand auto & node2 = graph.at(ref); if (node2.dist == inf) continue; refs.emplace(node2.dist, &node2); - hashes.insert(storePathToHash(node2.path)); + hashes.insert(storePathToHash(store->printStorePath(node2.path))); } /* For each reference, find the files and symlinks that @@ -187,7 +189,7 @@ struct CmdWhyDepends : SourceExprCommand visitPath = [&](const Path & p) { auto st = accessor->stat(p); - auto p2 = p == node.path ? "/" : std::string(p, node.path.size() + 1); + auto p2 = p == pathS ? "/" : std::string(p, pathS.size() + 1); auto getColour = [&](const std::string & hash) { return hash == dependencyPathHash ? ANSI_GREEN : ANSI_BLUE; @@ -231,11 +233,11 @@ struct CmdWhyDepends : SourceExprCommand // FIXME: should use scanForReferences(). - visitPath(node.path); + visitPath(pathS); RunPager pager; for (auto & ref : refs) { - auto hash = storePathToHash(ref.second->path); + auto hash = storePathToHash(store->printStorePath(ref.second->path)); bool last = all ? ref == *refs.rbegin() : true; |