From f337aa70998141ccfaa956e9f670152dbb15b385 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 4 Dec 2020 00:58:09 +0100 Subject: [PATCH] Split 'nix store add-to-store' into 'add-path' and 'add-file' This makes it consistent with 'nix hash '. --- src/nix/{add-to-store.md => add-file.md} | 6 +-- src/nix/add-path.md | 29 +++++++++++ src/nix/add-to-store.cc | 65 ++++++++++++++++-------- tests/fetchurl.sh | 2 +- 4 files changed, 77 insertions(+), 25 deletions(-) rename src/nix/{add-to-store.md => add-file.md} (72%) create mode 100644 src/nix/add-path.md diff --git a/src/nix/add-to-store.md b/src/nix/add-file.md similarity index 72% rename from src/nix/add-to-store.md rename to src/nix/add-file.md index 593ad67ad..ed237a035 100644 --- a/src/nix/add-to-store.md +++ b/src/nix/add-file.md @@ -2,8 +2,8 @@ R""( # Description -Copy the file or directory *path* to the Nix store, and -print the resulting store path on standard output. +Copy the regular file *path* to the Nix store, and print the resulting +store path on standard output. > **Warning** > @@ -18,7 +18,7 @@ Add a regular file to the store: ```console # echo foo > bar -# nix add-to-store --flat ./bar +# nix store add-file ./bar /nix/store/cbv2s4bsvzjri77s2gb8g8bpcb6dpa8w-bar # cat /nix/store/cbv2s4bsvzjri77s2gb8g8bpcb6dpa8w-bar diff --git a/src/nix/add-path.md b/src/nix/add-path.md new file mode 100644 index 000000000..87473611d --- /dev/null +++ b/src/nix/add-path.md @@ -0,0 +1,29 @@ +R""( + +# Description + +Copy *path* to the Nix store, and print the resulting store path on +standard output. + +> **Warning** +> +> The resulting store path is not registered as a garbage +> collector root, so it could be deleted before you have a +> chance to register it. + +# Examples + +Add a directory to the store: + +```console +# mkdir dir +# echo foo > dir/bar + +# nix store add-path ./dir +/nix/store/6pmjx56pm94n66n4qw1nff0y1crm8nqg-dir + +# cat /nix/store/6pmjx56pm94n66n4qw1nff0y1crm8nqg-dir/bar +foo +``` + +)"" diff --git a/src/nix/add-to-store.cc b/src/nix/add-to-store.cc index 66822b0ff..ea4bbbab9 100644 --- a/src/nix/add-to-store.cc +++ b/src/nix/add-to-store.cc @@ -9,10 +9,11 @@ struct CmdAddToStore : MixDryRun, StoreCommand { Path path; std::optional namePart; - FileIngestionMethod ingestionMethod = FileIngestionMethod::Recursive; + FileIngestionMethod ingestionMethod; CmdAddToStore() { + // FIXME: completion expectArg("path", &path); addFlag({ @@ -22,25 +23,6 @@ struct CmdAddToStore : MixDryRun, StoreCommand .labels = {"name"}, .handler = {&namePart}, }); - - addFlag({ - .longName = "flat", - .shortName = 0, - .description = "add flat file to the Nix store", - .handler = {&ingestionMethod, FileIngestionMethod::Flat}, - }); - } - - std::string description() override - { - return "add a path to the Nix store"; - } - - std::string doc() override - { - return - #include "add-to-store.md" - ; } void run(ref store) override @@ -78,4 +60,45 @@ struct CmdAddToStore : MixDryRun, StoreCommand } }; -static auto rCmdAddToStore = registerCommand2({"store", "add-path"}); +struct CmdAddFile : CmdAddToStore +{ + CmdAddFile() + { + ingestionMethod = FileIngestionMethod::Flat; + } + + std::string description() override + { + return "add a regular file to the Nix store"; + } + + std::string doc() override + { + return + #include "add-file.md" + ; + } +}; + +struct CmdAddPath : CmdAddToStore +{ + CmdAddPath() + { + ingestionMethod = FileIngestionMethod::Recursive; + } + + std::string description() override + { + return "add a path to the Nix store"; + } + + std::string doc() override + { + return + #include "add-path.md" + ; + } +}; + +static auto rCmdAddFile = registerCommand2({"store", "add-file"}); +static auto rCmdAddPath = registerCommand2({"store", "add-path"}); diff --git a/tests/fetchurl.sh b/tests/fetchurl.sh index 7ec25808c..10ec0173a 100644 --- a/tests/fetchurl.sh +++ b/tests/fetchurl.sh @@ -36,7 +36,7 @@ other_store=file://$TEST_ROOT/other_store?store=/fnord/store hash=$(nix hash file --type sha256 --base16 ./fetchurl.sh) -storePath=$(nix --store $other_store store add-path --flat ./fetchurl.sh) +storePath=$(nix --store $other_store store add-file ./fetchurl.sh) outPath=$(nix-build '' --argstr url file:///no-such-dir/fetchurl.sh --argstr sha256 $hash --no-out-link --substituters $other_store)