mirror of
https://github.com/NixOS/nix
synced 2025-06-25 19:01:16 +02:00
Merge pull request #12443 from DeterminateSystems/prefetch-out-link
nix flake prefetch: Add --out-link option
This commit is contained in:
commit
eb91014928
3 changed files with 30 additions and 8 deletions
|
@ -5,10 +5,14 @@ R""(
|
||||||
* Download a tarball and unpack it:
|
* Download a tarball and unpack it:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
# nix flake prefetch https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.5.tar.xz
|
# nix flake prefetch https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.5.tar.xz --out-link ./result
|
||||||
Downloaded 'https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.5.tar.xz?narHash=sha256-3XYHZANT6AFBV0BqegkAZHbba6oeDkIUCDwbATLMhAY='
|
Downloaded 'https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.5.tar.xz?narHash=sha256-3XYHZANT6AFBV0BqegkAZHbba6oeDkIUCDwbATLMhAY='
|
||||||
to '/nix/store/sl5vvk8mb4ma1sjyy03kwpvkz50hd22d-source' (hash
|
to '/nix/store/sl5vvk8mb4ma1sjyy03kwpvkz50hd22d-source' (hash
|
||||||
'sha256-3XYHZANT6AFBV0BqegkAZHbba6oeDkIUCDwbATLMhAY=').
|
'sha256-3XYHZANT6AFBV0BqegkAZHbba6oeDkIUCDwbATLMhAY=').
|
||||||
|
|
||||||
|
# cat ./result/README
|
||||||
|
Linux kernel
|
||||||
|
…
|
||||||
```
|
```
|
||||||
|
|
||||||
* Download the `dwarffs` flake (looked up in the flake registry):
|
* Download the `dwarffs` flake (looked up in the flake registry):
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "markdown.hh"
|
#include "markdown.hh"
|
||||||
#include "users.hh"
|
#include "users.hh"
|
||||||
#include "fetch-to-store.hh"
|
#include "fetch-to-store.hh"
|
||||||
|
#include "local-fs-store.hh"
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
@ -1430,8 +1431,18 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
|
||||||
|
|
||||||
struct CmdFlakePrefetch : FlakeCommand, MixJSON
|
struct CmdFlakePrefetch : FlakeCommand, MixJSON
|
||||||
{
|
{
|
||||||
|
std::optional<std::filesystem::path> outLink;
|
||||||
|
|
||||||
CmdFlakePrefetch()
|
CmdFlakePrefetch()
|
||||||
{
|
{
|
||||||
|
addFlag({
|
||||||
|
.longName = "out-link",
|
||||||
|
.shortName = 'o',
|
||||||
|
.description = "Create symlink named *path* to the resulting store path.",
|
||||||
|
.labels = {"path"},
|
||||||
|
.handler = {&outLink},
|
||||||
|
.completer = completePath
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string description() override
|
std::string description() override
|
||||||
|
@ -1467,6 +1478,13 @@ struct CmdFlakePrefetch : FlakeCommand, MixJSON
|
||||||
store->printStorePath(storePath),
|
store->printStorePath(storePath),
|
||||||
hash.to_string(HashFormat::SRI, true));
|
hash.to_string(HashFormat::SRI, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (outLink) {
|
||||||
|
if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>())
|
||||||
|
createOutLinks(*outLink, {BuiltPath::Opaque{storePath}}, *store2);
|
||||||
|
else
|
||||||
|
throw Error("'--out-link' is not supported for this Nix store");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -73,13 +73,13 @@ test_tarball .gz gzip
|
||||||
# All entries in tree.tar.gz refer to the same file, and all have the same inode when unpacked by GNU tar.
|
# All entries in tree.tar.gz refer to the same file, and all have the same inode when unpacked by GNU tar.
|
||||||
# We don't preserve the hard links, because that's an optimization we think is not worth the complexity,
|
# We don't preserve the hard links, because that's an optimization we think is not worth the complexity,
|
||||||
# so we only make sure that the contents are copied correctly.
|
# so we only make sure that the contents are copied correctly.
|
||||||
path="$(nix flake prefetch --json "tarball+file://$(pwd)/tree.tar.gz" | jq -r .storePath)"
|
nix flake prefetch --json "tarball+file://$(pwd)/tree.tar.gz" --out-link "$TEST_ROOT/result"
|
||||||
[[ $(cat "$path/a/b/foo") = bar ]]
|
[[ $(cat "$TEST_ROOT/result/a/b/foo") = bar ]]
|
||||||
[[ $(cat "$path/a/b/xyzzy") = bar ]]
|
[[ $(cat "$TEST_ROOT/result/a/b/xyzzy") = bar ]]
|
||||||
[[ $(cat "$path/a/yyy") = bar ]]
|
[[ $(cat "$TEST_ROOT/result/a/yyy") = bar ]]
|
||||||
[[ $(cat "$path/a/zzz") = bar ]]
|
[[ $(cat "$TEST_ROOT/result/a/zzz") = bar ]]
|
||||||
[[ $(cat "$path/c/aap") = bar ]]
|
[[ $(cat "$TEST_ROOT/result/c/aap") = bar ]]
|
||||||
[[ $(cat "$path/fnord") = bar ]]
|
[[ $(cat "$TEST_ROOT/result/fnord") = bar ]]
|
||||||
|
|
||||||
# Test a tarball that has multiple top-level directories.
|
# Test a tarball that has multiple top-level directories.
|
||||||
rm -rf "$TEST_ROOT/tar_root"
|
rm -rf "$TEST_ROOT/tar_root"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue