aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-12-04 00:58:09 +0100
committerEelco Dolstra <edolstra@gmail.com>2020-12-04 00:59:24 +0100
commitf337aa70998141ccfaa956e9f670152dbb15b385 (patch)
tree7563c50f1cc90ea34ca45bd66d8962d4c9fff6bc
parent8df58eae4c6f074b8e33a5bcb0c73b6700e34d5a (diff)
Split 'nix store add-to-store' into 'add-path' and 'add-file'
This makes it consistent with 'nix hash <path|file>'.
-rw-r--r--src/nix/add-file.md (renamed from src/nix/add-to-store.md)6
-rw-r--r--src/nix/add-path.md29
-rw-r--r--src/nix/add-to-store.cc65
-rw-r--r--tests/fetchurl.sh2
4 files changed, 77 insertions, 25 deletions
diff --git a/src/nix/add-to-store.md b/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<std::string> 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> store) override
@@ -78,4 +60,45 @@ struct CmdAddToStore : MixDryRun, StoreCommand
}
};
-static auto rCmdAddToStore = registerCommand2<CmdAddToStore>({"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<CmdAddFile>({"store", "add-file"});
+static auto rCmdAddPath = registerCommand2<CmdAddPath>({"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 '<nix/fetchurl.nix>' --argstr url file:///no-such-dir/fetchurl.sh --argstr sha256 $hash --no-out-link --substituters $other_store)