about summary refs log tree commit diff
path: root/src/nix/command.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-04-25T11·20+0200
committerEelco Dolstra <edolstra@gmail.com>2017-04-25T11·20+0200
commit7ee81f3887353cae2feecb98b482badf57a1fd5b (patch)
treec06ad44f0d0901c92e68b0284281691ee753c5fc /src/nix/command.cc
parentc769841bc4ecb9dd3d8456931fec78e102c3832f (diff)
Make StorePathsCommand a subclass of InstallablesCommand
This allows commands like 'nix path-info', 'nix copy', 'nix verify'
etc. to work on arbitrary installables. E.g. to copy geeqie to a
binary cache:

  $ nix copy -r --to file:///tmp/binary-cache nixpkgs.geeqie

Or to get the closure size of thunderbird:

  $ nix path-info -S nixpkgs.thunderbird
Diffstat (limited to 'src/nix/command.cc')
-rw-r--r--src/nix/command.cc18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/nix/command.cc b/src/nix/command.cc
index 4034de96c162..2809a9b4f288 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 {
 
@@ -98,23 +99,32 @@ 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 & i : installables) {
+            for (auto & path : i->toBuildable()) {
+                if (isDerivation(path)) {
+                    Derivation drv = store->derivationFromPath(path);
+                    for (auto & output : drv.outputs)
+                        storePaths.push_back(output.second.path);
+                } else
+                    storePaths.push_back(path);
+            }
+        }
 
         if (recursive) {
             PathSet closure;