about summary refs log tree commit diff
path: root/src/nix-store
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-11-26T14·39+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-11-26T14·39+0100
commit46a369ad9558939bc2c6ee588df483ca503bbb5a (patch)
tree7a3fc4d49d0a5fb29d1c6e139672d91f86e71f47 /src/nix-store
parenta3d6585c5a1006d4f9ebd2163d06f86ab71a4a3e (diff)
Make "nix-build -A <derivation>.<output>" do the right thing
For example, given a derivation with outputs "out", "man" and "bin":

  $ nix-build -A pkg

produces ./result pointing to the "out" output;

  $ nix-build -A pkg.man

produces ./result-man pointing to the "man" output;

  $ nix-build -A pkg.all

produces ./result, ./result-man and ./result-bin;

  $ nix-build -A pkg.all -A pkg2

produces ./result, ./result-man, ./result-bin and ./result-2.
Diffstat (limited to 'src/nix-store')
-rw-r--r--src/nix-store/nix-store.cc20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc
index e973beda9f0f..c0da37d251da 100644
--- a/src/nix-store/nix-store.cc
+++ b/src/nix-store/nix-store.cc
@@ -60,13 +60,21 @@ static Path useDeriver(Path path)
    other paths it means ensure their validity. */
 static PathSet realisePath(const Path & path, bool build = true)
 {
-    if (isDerivation(path)) {
+    DrvPathWithOutputs p = parseDrvPathWithOutputs(path);
+
+    if (isDerivation(p.first)) {
         if (build) store->buildPaths(singleton<PathSet>(path));
-        Derivation drv = derivationFromPath(*store, path);
+        Derivation drv = derivationFromPath(*store, p.first);
         rootNr++;
 
+        if (p.second.empty())
+            foreach (DerivationOutputs::iterator, i, drv.outputs) p.second.insert(i->first);
+
         PathSet outputs;
-        foreach (DerivationOutputs::iterator, i, drv.outputs) {
+        foreach (StringSet::iterator, j, p.second) {
+            DerivationOutputs::iterator i = drv.outputs.find(*j);
+            if (i == drv.outputs.end())
+                throw Error(format("derivation `%1%' does not have an output named `%2%'") % p.first % *j);
             Path outPath = i->second.path;
             if (gcRoot == "")
                 printGCWarning();
@@ -103,8 +111,10 @@ static void opRealise(Strings opFlags, Strings opArgs)
         else throw UsageError(format("unknown flag `%1%'") % *i);
 
     Paths paths;
-    foreach (Strings::iterator, i, opArgs)
-        paths.push_back(followLinksToStorePath(*i));
+    foreach (Strings::iterator, i, opArgs) {
+        DrvPathWithOutputs p = parseDrvPathWithOutputs(*i);
+        paths.push_back(makeDrvPathWithOutputs(followLinksToStorePath(p.first), p.second));
+    }
 
     unsigned long long downloadSize, narSize;
     PathSet willBuild, willSubstitute, unknown;