diff options
Diffstat (limited to 'src/nix/command.cc')
-rw-r--r-- | src/nix/command.cc | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/nix/command.cc b/src/nix/command.cc index a1b2c120a5d9..3c82e0df57f7 100644 --- a/src/nix/command.cc +++ b/src/nix/command.cc @@ -1,5 +1,6 @@ #include "command.hh" #include "store-api.hh" +#include "derivations.hh" namespace nix { @@ -79,6 +80,13 @@ StoreCommand::StoreCommand() mkFlag(0, "store", "store-uri", "URI of the Nix store to use", &storeUri); } +ref<Store> StoreCommand::getStore() +{ + if (!_store) + _store = createStore(); + return ref<Store>(_store); +} + ref<Store> StoreCommand::createStore() { return openStore(storeUri); @@ -91,23 +99,24 @@ void StoreCommand::run() StorePathsCommand::StorePathsCommand() { - expectArgs("paths", &storePaths); mkFlag('r', "recursive", "apply operation to closure of the specified paths", &recursive); mkFlag(0, "all", "apply operation to the entire store", &all); } void StorePathsCommand::run(ref<Store> store) { + Paths storePaths; + if (all) { - if (storePaths.size()) + if (installables.size()) throw UsageError("‘--all’ does not expect arguments"); for (auto & p : store->queryAllValidPaths()) storePaths.push_back(p); } else { - for (auto & storePath : storePaths) - storePath = store->followLinksToStorePath(storePath); + for (auto & p : buildInstallables(store, false)) + storePaths.push_back(p); if (recursive) { PathSet closure; @@ -120,4 +129,14 @@ void StorePathsCommand::run(ref<Store> store) run(store, storePaths); } +void StorePathCommand::run(ref<Store> store) +{ + auto storePaths = buildInstallables(store, false); + + if (storePaths.size() != 1) + throw UsageError("this command requires exactly one store path"); + + run(store, *storePaths.begin()); +} + } |