diff options
Diffstat (limited to 'src/nix-store/main.cc')
-rw-r--r-- | src/nix-store/main.cc | 50 |
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") |