From 8c18ed78851b714c9b7fd0cf6332c30890717df2 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 27 Jun 2023 10:17:08 -0400 Subject: [PATCH] Get rid of the `--derivation` flag Since PR #7601, we've had enough flexibility in our types of installables that it is no longer needed. Progress towards #7261 --- src/libcmd/command.cc | 12 +----------- src/libcmd/command.hh | 9 +-------- src/libcmd/installables.cc | 27 ++++++++------------------- src/libcmd/installables.hh | 17 ----------------- src/nix/develop.cc | 4 ++-- src/nix/diff-closures.cc | 6 +++--- src/nix/run.cc | 2 +- src/nix/why-depends.cc | 6 +++--- tests/dyn-drv/text-hashed-output.sh | 4 ++-- tests/why-depends.sh | 2 +- 10 files changed, 22 insertions(+), 67 deletions(-) diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 4fc1979563d5..039e040a4d0e 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -130,16 +130,6 @@ ref EvalCommand::getEvalState() return ref(evalState); } -MixOperateOnOptions::MixOperateOnOptions() -{ - addFlag({ - .longName = "derivation", - .description = "Operate on the [store derivation](../../glossary.md#gloss-store-derivation) rather than its outputs.", - .category = installablesCategory, - .handler = {&operateOn, OperateOn::Derivation}, - }); -} - BuiltPathsCommand::BuiltPathsCommand(bool recursive) : recursive(recursive) { @@ -177,7 +167,7 @@ void BuiltPathsCommand::run(ref store, Installables && installables) for (auto & p : store->queryAllValidPaths()) paths.push_back(BuiltPath::Opaque{p}); } else { - paths = Installable::toBuiltPaths(getEvalStore(), store, realiseMode, operateOn, installables); + paths = Installable::toBuiltPaths(getEvalStore(), store, realiseMode, 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 96236b987b09..e8da998a7900 100644 --- a/src/libcmd/command.hh +++ b/src/libcmd/command.hh @@ -168,15 +168,8 @@ private: std::string _installable{"."}; }; -struct MixOperateOnOptions : virtual Args -{ - OperateOn operateOn = OperateOn::Output; - - MixOperateOnOptions(); -}; - /* A command that operates on zero or more store paths. */ -struct BuiltPathsCommand : InstallablesCommand, virtual MixOperateOnOptions +struct BuiltPathsCommand : InstallablesCommand { private: diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 10b077fb58c5..fafea9ad4ad0 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -624,33 +624,22 @@ BuiltPaths Installable::toBuiltPaths( ref evalStore, ref store, Realise mode, - OperateOn operateOn, const Installables & installables) { - if (operateOn == OperateOn::Output) { - BuiltPaths res; - for (auto & p : Installable::build(evalStore, store, mode, installables)) - res.push_back(p.path); - return res; - } else { - if (mode == Realise::Nothing) - settings.readOnlyMode = true; - - BuiltPaths res; - for (auto & drvPath : Installable::toDerivations(store, installables, true)) - res.push_back(BuiltPath::Opaque{drvPath}); - return res; - } + BuiltPaths res; + for (auto & p : Installable::build(evalStore, store, mode, installables)) + res.push_back(p.path); + return res; } StorePathSet Installable::toStorePaths( ref evalStore, ref store, - Realise mode, OperateOn operateOn, + Realise mode, const Installables & installables) { StorePathSet outPaths; - for (auto & path : toBuiltPaths(evalStore, store, mode, operateOn, installables)) { + for (auto & path : toBuiltPaths(evalStore, store, mode, installables)) { auto thisOutPaths = path.outPaths(); outPaths.insert(thisOutPaths.begin(), thisOutPaths.end()); } @@ -660,10 +649,10 @@ StorePathSet Installable::toStorePaths( StorePath Installable::toStorePath( ref evalStore, ref store, - Realise mode, OperateOn operateOn, + Realise mode, ref installable) { - auto paths = toStorePaths(evalStore, store, mode, operateOn, {installable}); + auto paths = toStorePaths(evalStore, store, mode, {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 b0dc0dc02c57..eb27150cd9ce 100644 --- a/src/libcmd/installables.hh +++ b/src/libcmd/installables.hh @@ -39,20 +39,6 @@ enum class Realise { Nothing }; -/** - * How to handle derivations in commands that operate on store paths. - */ -enum class OperateOn { - /** - * Operate on the output path. - */ - Output, - /** - * Operate on the .drv path. - */ - Derivation -}; - /** * Extra info about a DerivedPath * @@ -170,14 +156,12 @@ struct Installable ref evalStore, ref store, Realise mode, - OperateOn operateOn, const Installables & installables); static StorePath toStorePath( ref evalStore, ref store, Realise mode, - OperateOn operateOn, ref installable); static std::set toDerivations( @@ -189,7 +173,6 @@ struct Installable ref evalStore, ref store, Realise mode, - OperateOn operateOn, const Installables & installables); }; diff --git a/src/nix/develop.cc b/src/nix/develop.cc index 195eeaa21e9a..29d78265dbc8 100644 --- a/src/nix/develop.cc +++ b/src/nix/develop.cc @@ -341,7 +341,7 @@ struct Common : InstallableCommand, MixProfile auto dir = absPath(dir_); auto installable = parseInstallable(store, installable_); auto builtPaths = Installable::toStorePaths( - getEvalStore(), store, Realise::Nothing, OperateOn::Output, {installable}); + getEvalStore(), store, Realise::Nothing, {installable}); for (auto & path: builtPaths) { auto from = store->printStorePath(path); if (script.find(from) == std::string::npos) @@ -554,7 +554,7 @@ struct CmdDevelop : Common, MixEnvironment bool found = false; - for (auto & path : Installable::toStorePaths(getEvalStore(), store, Realise::Outputs, OperateOn::Output, {bashInstallable})) { + for (auto & path : Installable::toStorePaths(getEvalStore(), store, Realise::Outputs, {bashInstallable})) { auto s = store->printStorePath(path) + "/bin/bash"; if (pathExists(s)) { shell = s; diff --git a/src/nix/diff-closures.cc b/src/nix/diff-closures.cc index c7c37b66fbe9..0a0d7c0f27bf 100644 --- a/src/nix/diff-closures.cc +++ b/src/nix/diff-closures.cc @@ -106,7 +106,7 @@ void printClosureDiff( using namespace nix; -struct CmdDiffClosures : SourceExprCommand, MixOperateOnOptions +struct CmdDiffClosures : SourceExprCommand { std::string _before, _after; @@ -131,9 +131,9 @@ struct CmdDiffClosures : SourceExprCommand, MixOperateOnOptions void run(ref store) override { auto before = parseInstallable(store, _before); - auto beforePath = Installable::toStorePath(getEvalStore(), store, Realise::Outputs, operateOn, before); + auto beforePath = Installable::toStorePath(getEvalStore(), store, Realise::Outputs, before); auto after = parseInstallable(store, _after); - auto afterPath = Installable::toStorePath(getEvalStore(), store, Realise::Outputs, operateOn, after); + auto afterPath = Installable::toStorePath(getEvalStore(), store, Realise::Outputs, after); printClosureDiff(store, beforePath, afterPath, ""); } }; diff --git a/src/nix/run.cc b/src/nix/run.cc index 1baf299ab9fb..9ea87e95c514 100644 --- a/src/nix/run.cc +++ b/src/nix/run.cc @@ -99,7 +99,7 @@ struct CmdShell : InstallablesCommand, MixEnvironment void run(ref store, Installables && installables) override { - auto outPaths = Installable::toStorePaths(getEvalStore(), store, Realise::Outputs, OperateOn::Output, installables); + auto outPaths = Installable::toStorePaths(getEvalStore(), store, Realise::Outputs, installables); auto accessor = store->getFSAccessor(); diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc index a3a9dc698892..c49102cdc1e0 100644 --- a/src/nix/why-depends.cc +++ b/src/nix/why-depends.cc @@ -27,7 +27,7 @@ static std::string filterPrintable(const std::string & s) return res; } -struct CmdWhyDepends : SourceExprCommand, MixOperateOnOptions +struct CmdWhyDepends : SourceExprCommand { std::string _package, _dependency; bool all = false; @@ -82,7 +82,7 @@ struct CmdWhyDepends : SourceExprCommand, MixOperateOnOptions void run(ref store) override { auto package = parseInstallable(store, _package); - auto packagePath = Installable::toStorePath(getEvalStore(), store, Realise::Outputs, operateOn, package); + auto packagePath = Installable::toStorePath(getEvalStore(), store, Realise::Outputs, package); /* We don't need to build `dependency`. We try to get the store * path if it's already known, and if not, then it's not a dependency. @@ -97,7 +97,7 @@ struct CmdWhyDepends : SourceExprCommand, MixOperateOnOptions auto dependency = parseInstallable(store, _dependency); auto optDependencyPath = [&]() -> std::optional { try { - return {Installable::toStorePath(getEvalStore(), store, Realise::Derivation, operateOn, dependency)}; + return {Installable::toStorePath(getEvalStore(), store, Realise::Derivation, dependency)}; } catch (MissingRealisation &) { return std::nullopt; } diff --git a/tests/dyn-drv/text-hashed-output.sh b/tests/dyn-drv/text-hashed-output.sh index f3e5aa93bb7a..36ea8299040b 100644 --- a/tests/dyn-drv/text-hashed-output.sh +++ b/tests/dyn-drv/text-hashed-output.sh @@ -20,7 +20,7 @@ nix show-derivation "$drvProducingDrv" out1=$(nix-build ./text-hashed-output.nix -A producingDrv --no-out-link) -nix path-info $drv --derivation --json | jq -nix path-info $out1 --derivation --json | jq +nix path-info $drv --json | jq +nix path-info $drvProducingDrv --json | jq test $out1 == $drv diff --git a/tests/why-depends.sh b/tests/why-depends.sh index b35a0d1cf39d..ec9de242d45b 100644 --- a/tests/why-depends.sh +++ b/tests/why-depends.sh @@ -6,7 +6,7 @@ cp ./dependencies.nix ./dependencies.builder0.sh ./config.nix $TEST_HOME cd $TEST_HOME -nix why-depends --derivation --file ./dependencies.nix input2_drv input1_drv +nix why-depends --file ./dependencies.nix input2_drv.drvPath input1_drv.drvPath nix why-depends --file ./dependencies.nix input2_drv input1_drv nix-build ./dependencies.nix -A input0_drv -o dep