about summary refs log tree commit diff
path: root/src/nix-store/main.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-04-07T14·01+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-04-07T14·01+0000
commitc815aff21b668f5fe7bbd04086a988df51281840 (patch)
tree8532d7fab1ab916c99d9034cfa2167b73726aba4 /src/nix-store/main.cc
parent57d023a184bdc2f30cd7052c157e43ba1bca8288 (diff)
* `nix-store --add-fixed' to preload the outputs of fixed-output
  derivations.  This is mostly to simplify the implementation of
  nix-prefetch-{url, svn}, which now work properly in setuid
  installations.

* Enforce valid store names in `nix-store --add / --add-fixed'.

Diffstat (limited to 'src/nix-store/main.cc')
-rw-r--r--src/nix-store/main.cc50
1 files changed, 48 insertions, 2 deletions
diff --git a/src/nix-store/main.cc b/src/nix-store/main.cc
index ff226f986387..a8720ce6fbd7 100644
--- a/src/nix-store/main.cc
+++ b/src/nix-store/main.cc
@@ -85,8 +85,7 @@ static void opRealise(Strings opFlags, Strings opArgs)
 }
 
 
-/* Add files to the Nix values directory and print the resulting
-   paths. */
+/* Add files to the Nix store and print the resulting paths. */
 static void opAdd(Strings opFlags, Strings opArgs)
 {
     if (!opFlags.empty()) throw UsageError("unknown flag");
@@ -96,6 +95,49 @@ static void opAdd(Strings opFlags, Strings opArgs)
 }
 
 
+/* Preload the output of a fixed-output derivation into the Nix
+   store. */
+static void opAddFixed(Strings opFlags, Strings opArgs)
+{
+    bool recursive = false;
+    
+    for (Strings::iterator i = opFlags.begin();
+         i != opFlags.end(); ++i)
+        if (*i == "--recursive") recursive = true;
+        else throw UsageError(format("unknown flag `%1%'") % *i);
+
+    if (opArgs.empty())
+        throw UsageError("first argument must be hash algorithm");
+    
+    string hashAlgo = opArgs.front();
+    opArgs.pop_front();
+
+    for (Strings::iterator i = opArgs.begin(); i != opArgs.end(); ++i)
+        cout << format("%1%\n") % addToStoreFixed(recursive, hashAlgo, *i);
+}
+
+
+/* Hack to support caching in `nix-prefetch-url'. */
+static void opPrintFixedPath(Strings opFlags, Strings opArgs)
+{
+    bool recursive = false;
+    
+    for (Strings::iterator i = opFlags.begin();
+         i != opFlags.end(); ++i)
+        if (*i == "--recursive") recursive = true;
+        else throw UsageError(format("unknown flag `%1%'") % *i);
+
+    Strings::iterator i = opArgs.begin();
+    string hashAlgo = *i++;
+    string hash = *i++;
+    string name = *i++;
+
+    cout << format("%1%\n") %
+        makeFixedOutputPath(recursive, hashAlgo,
+            parseHash(parseHashType(hashAlgo), hash), name);
+}
+
+
 /* Place in `paths' the set of paths that are required to `realise'
    the given store path, i.e., all paths necessary for valid
    deployment of the path.  For a derivation, this is the union of
@@ -557,6 +599,10 @@ void run(Strings args)
             op = opRealise;
         else if (arg == "--add" || arg == "-A")
             op = opAdd;
+        else if (arg == "--add-fixed")
+            op = opAddFixed;
+        else if (arg == "--print-fixed-path")
+            op = opPrintFixedPath;
         else if (arg == "--query" || arg == "-q")
             op = opQuery;
         else if (arg == "--substitute")