From ec613603ba324bf12f8f554d74fb1a02c6e9b472 Mon Sep 17 00:00:00 2001 From: regnat Date: Wed, 12 May 2021 16:19:51 +0200 Subject: DerivedPathWithHints -> BuiltPath Just a renaming for now --- src/libcmd/command.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/libcmd/command.cc') diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 9da470c15..25e4873e8 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -162,7 +162,7 @@ void MixProfile::updateProfile(const StorePath & storePath) profile2, storePath)); } -void MixProfile::updateProfile(const DerivedPathsWithHints & buildables) +void MixProfile::updateProfile(const BuiltPaths & buildables) { if (!profile) return; @@ -170,10 +170,10 @@ void MixProfile::updateProfile(const DerivedPathsWithHints & buildables) for (auto & buildable : buildables) { std::visit(overloaded { - [&](DerivedPathWithHints::Opaque bo) { + [&](BuiltPath::Opaque bo) { result.push_back(bo.path); }, - [&](DerivedPathWithHints::Built bfd) { + [&](BuiltPath::Built bfd) { for (auto & output : bfd.outputs) { /* Output path should be known because we just tried to build it. */ -- cgit v1.2.3 From 21050846457f356346204dd52fb7a6d49f710688 Mon Sep 17 00:00:00 2001 From: regnat Date: Mon, 17 May 2021 08:45:08 +0200 Subject: Enfore the use of properly built paths in libcmd Replace `DerivedPathWithHints` by a new `BuiltPath` type that serves as a proof that the corresponding path has been built. --- src/libcmd/command.cc | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'src/libcmd/command.cc') diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 25e4873e8..569c4b9e4 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -54,7 +54,7 @@ void StoreCommand::run() run(getStore()); } -RealisedPathsCommand::RealisedPathsCommand(bool recursive) +BuiltPathsCommand::BuiltPathsCommand(bool recursive) : recursive(recursive) { if (recursive) @@ -81,39 +81,45 @@ RealisedPathsCommand::RealisedPathsCommand(bool recursive) }); } -void RealisedPathsCommand::run(ref store) +void BuiltPathsCommand::run(ref store) { - std::vector paths; + BuiltPaths paths; if (all) { if (installables.size()) throw UsageError("'--all' does not expect arguments"); // XXX: Only uses opaque paths, ignores all the realisations for (auto & p : store->queryAllValidPaths()) - paths.push_back(p); + paths.push_back(BuiltPath::Opaque{p}); } else { - auto pathSet = toRealisedPaths(store, realiseMode, operateOn, installables); + paths = toBuiltPaths(store, realiseMode, operateOn, installables); if (recursive) { - auto roots = std::move(pathSet); - pathSet = {}; - RealisedPath::closure(*store, roots, pathSet); + // XXX: This only computes the store path closure, ignoring + // intermediate realisations + StorePathSet pathsRoots, pathsClosure; + for (auto & root: paths) { + auto rootFromThis = root.outPaths(); + pathsRoots.insert(rootFromThis.begin(), rootFromThis.end()); + } + store->computeFSClosure(pathsRoots, pathsClosure); + for (auto & path : pathsClosure) + paths.push_back(BuiltPath::Opaque{path}); } - for (auto & path : pathSet) - paths.push_back(path); } run(store, std::move(paths)); } StorePathsCommand::StorePathsCommand(bool recursive) - : RealisedPathsCommand(recursive) + : BuiltPathsCommand(recursive) { } -void StorePathsCommand::run(ref store, std::vector paths) +void StorePathsCommand::run(ref store, BuiltPaths paths) { StorePaths storePaths; - for (auto & p : paths) - storePaths.push_back(p.path()); + for (auto& builtPath : paths) + for (auto& p : builtPath.outPaths()) + storePaths.push_back(p); run(store, std::move(storePaths)); } @@ -175,10 +181,7 @@ void MixProfile::updateProfile(const BuiltPaths & buildables) }, [&](BuiltPath::Built bfd) { for (auto & output : bfd.outputs) { - /* Output path should be known because we just tried to - build it. */ - assert(output.second); - result.push_back(*output.second); + result.push_back(output.second); } }, }, buildable.raw()); -- cgit v1.2.3 From 4a7a8b87cd0dd383f1059fe7903c4b001314f58d Mon Sep 17 00:00:00 2001 From: Pamplemousse Date: Tue, 29 Jun 2021 14:28:43 -0700 Subject: Prefer to throw specific errors Signed-off-by: Pamplemousse --- src/libcmd/command.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcmd/command.cc') diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 569c4b9e4..6777b23be 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -188,7 +188,7 @@ void MixProfile::updateProfile(const BuiltPaths & buildables) } if (result.size() != 1) - throw Error("'--profile' requires that the arguments produce a single store path, but there are %d", result.size()); + throw UsageError("'--profile' requires that the arguments produce a single store path, but there are %d", result.size()); updateProfile(result[0]); } -- cgit v1.2.3 From bef40c29491ba9b31c85b9b89a5342979344f583 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 29 Jun 2021 21:09:48 +0200 Subject: Add --eval-store option --- src/libcmd/command.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/libcmd/command.cc') diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 6777b23be..93f20a8c3 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -54,6 +54,38 @@ void StoreCommand::run() run(getStore()); } +EvalCommand::EvalCommand() +{ + // FIXME: move to MixEvalArgs? + addFlag({ + .longName = "eval-store", + .description = "The Nix store to use for evaluations.", + .labels = {"store-url"}, + //.category = ..., + .handler = {&evalStoreUrl}, + }); +} + +EvalCommand::~EvalCommand() +{ + if (evalState) + evalState->printStats(); +} + +ref EvalCommand::getEvalStore() +{ + if (!evalStore) + evalStore = evalStoreUrl ? openStore(*evalStoreUrl) : getStore(); + return ref(evalStore); +} + +ref EvalCommand::getEvalState() +{ + if (!evalState) + evalState = std::make_shared(searchPath, getEvalStore(), getStore()); + return ref(evalState); +} + BuiltPathsCommand::BuiltPathsCommand(bool recursive) : recursive(recursive) { -- cgit v1.2.3 From 2ff3035cf4d5167d180878d69cb47b31890a24c4 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 15 Jul 2021 14:28:33 +0200 Subject: Support --eval-store in nix-instantiate and nix-build --- src/libcmd/command.cc | 8 -------- 1 file changed, 8 deletions(-) (limited to 'src/libcmd/command.cc') diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 93f20a8c3..4add710ed 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -56,14 +56,6 @@ void StoreCommand::run() EvalCommand::EvalCommand() { - // FIXME: move to MixEvalArgs? - addFlag({ - .longName = "eval-store", - .description = "The Nix store to use for evaluations.", - .labels = {"store-url"}, - //.category = ..., - .handler = {&evalStoreUrl}, - }); } EvalCommand::~EvalCommand() -- cgit v1.2.3 From 8d9f7048cd3b09fb58f6bad0328f644b0ddaaa16 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 16 Jul 2021 16:04:47 +0200 Subject: 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libcmd/command.cc') 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 -- cgit v1.2.3 From a15e65eef0443a4d41b1a9e9b1504234dc5f5947 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 27 Sep 2021 10:53:09 +0200 Subject: run(): Move --- src/libcmd/command.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libcmd/command.cc') diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 2daf43aa7..2b9902677 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -138,7 +138,7 @@ StorePathsCommand::StorePathsCommand(bool recursive) { } -void StorePathsCommand::run(ref store, BuiltPaths paths) +void StorePathsCommand::run(ref store, BuiltPaths && paths) { StorePaths storePaths; for (auto& builtPath : paths) @@ -148,7 +148,7 @@ void StorePathsCommand::run(ref store, BuiltPaths paths) run(store, std::move(storePaths)); } -void StorePathCommand::run(ref store, std::vector storePaths) +void StorePathCommand::run(ref store, std::vector && storePaths) { if (storePaths.size() != 1) throw UsageError("this command requires exactly one store path"); -- cgit v1.2.3 From 4b2b15113196e403bc32ce0d7b4338971d7954a8 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 27 Sep 2021 10:57:11 +0200 Subject: nix path-info -r: Don't duplicate the root paths This fixes $ nix path-info -r $(type -P ls) /nix/store/vfilzcp8a467w3p0mp54ybq6bdzb8w49-coreutils-8.32 /nix/store/5d821pjgzb90lw4zbg6xwxs7llm335wr-libunistring-0.9.10 ... /nix/store/mrv4y369nw6hg4pw8d9p9bfdxj9pjw0x-acl-2.3.0 /nix/store/vfilzcp8a467w3p0mp54ybq6bdzb8w49-coreutils-8.32 Also, output the paths in topologically sorted order like we used to. --- src/libcmd/command.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/libcmd/command.cc') diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 2b9902677..0d61e12d0 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -120,7 +120,7 @@ void BuiltPathsCommand::run(ref store) // XXX: This only computes the store path closure, ignoring // intermediate realisations StorePathSet pathsRoots, pathsClosure; - for (auto & root: paths) { + for (auto & root : paths) { auto rootFromThis = root.outPaths(); pathsRoots.insert(rootFromThis.begin(), rootFromThis.end()); } @@ -140,12 +140,15 @@ StorePathsCommand::StorePathsCommand(bool recursive) void StorePathsCommand::run(ref store, BuiltPaths && paths) { - StorePaths storePaths; - for (auto& builtPath : paths) - for (auto& p : builtPath.outPaths()) - storePaths.push_back(p); + StorePathSet storePaths; + for (auto & builtPath : paths) + for (auto & p : builtPath.outPaths()) + storePaths.insert(p); - run(store, std::move(storePaths)); + auto sorted = store->topoSortPaths(storePaths); + std::reverse(sorted.begin(), sorted.end()); + + run(store, std::move(sorted)); } void StorePathCommand::run(ref store, std::vector && storePaths) -- cgit v1.2.3 From 242f9bf3dc04170502020fb0338b78ea76b9ebac Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 30 Sep 2021 21:31:21 +0000 Subject: `std::visit` by reference I had started the trend of doing `std::visit` by value (because a type error once mislead me into thinking that was the only form that existed). While the optomizer in principle should be able to deal with extra coppying or extra indirection once the lambdas inlined, sticking with by reference is the conventional default. I hope this might even improve performance. --- src/libcmd/command.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libcmd/command.cc') diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 0d61e12d0..fd3edfc46 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -203,10 +203,10 @@ void MixProfile::updateProfile(const BuiltPaths & buildables) for (auto & buildable : buildables) { std::visit(overloaded { - [&](BuiltPath::Opaque bo) { + [&](const BuiltPath::Opaque & bo) { result.push_back(bo.path); }, - [&](BuiltPath::Built bfd) { + [&](const BuiltPath::Built & bfd) { for (auto & output : bfd.outputs) { result.push_back(output.second); } -- cgit v1.2.3