File tree Expand file tree Collapse file tree 3 files changed +30
-8
lines changed
Expand file tree Collapse file tree 3 files changed +30
-8
lines changed Original file line number Diff line number Diff line change 55* Download a tarball and unpack it:
66
77 ``` console
8- # nix flake prefetch https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.5.tar.xz
8+ # nix flake prefetch https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.5.tar.xz --out-link ./result
99 Downloaded 'https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.5.tar.xz?narHash=sha256-3XYHZANT6AFBV0BqegkAZHbba6oeDkIUCDwbATLMhAY='
1010 to '/nix/store/sl5vvk8mb4ma1sjyy03kwpvkz50hd22d-source' (hash
1111 'sha256-3XYHZANT6AFBV0BqegkAZHbba6oeDkIUCDwbATLMhAY=').
12+
13+ # cat ./result/README
14+ Linux kernel
15+ …
1216 ```
1317
1418* Download the ` dwarffs ` flake (looked up in the flake registry):
Original file line number Diff line number Diff line change 1818#include " markdown.hh"
1919#include " users.hh"
2020#include " fetch-to-store.hh"
21+ #include " local-fs-store.hh"
2122
2223#include < filesystem>
2324#include < nlohmann/json.hpp>
@@ -1430,8 +1431,18 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
14301431
14311432struct CmdFlakePrefetch : FlakeCommand, MixJSON
14321433{
1434+ std::optional<std::filesystem::path> outLink;
1435+
14331436 CmdFlakePrefetch ()
14341437 {
1438+ addFlag ({
1439+ .longName = " out-link" ,
1440+ .shortName = ' o' ,
1441+ .description = " Create symlink named *path* to the resulting store path." ,
1442+ .labels = {" path" },
1443+ .handler = {&outLink},
1444+ .completer = completePath
1445+ });
14351446 }
14361447
14371448 std::string description () override
@@ -1467,6 +1478,13 @@ struct CmdFlakePrefetch : FlakeCommand, MixJSON
14671478 store->printStorePath (storePath),
14681479 hash.to_string (HashFormat::SRI, true ));
14691480 }
1481+
1482+ if (outLink) {
1483+ if (auto store2 = store.dynamic_pointer_cast <LocalFSStore>())
1484+ createOutLinks (*outLink, {BuiltPath::Opaque{storePath}}, *store2);
1485+ else
1486+ throw Error (" '--out-link' is not supported for this Nix store" );
1487+ }
14701488 }
14711489};
14721490
Original file line number Diff line number Diff line change @@ -73,13 +73,13 @@ test_tarball .gz gzip
7373# All entries in tree.tar.gz refer to the same file, and all have the same inode when unpacked by GNU tar.
7474# We don't preserve the hard links, because that's an optimization we think is not worth the complexity,
7575# so we only make sure that the contents are copied correctly.
76- path= " $( nix flake prefetch --json " tarball+file://$( pwd) /tree.tar.gz" | jq -r .storePath ) "
77- [[ $( cat " $path /a/b/foo" ) = bar ]]
78- [[ $( cat " $path /a/b/xyzzy" ) = bar ]]
79- [[ $( cat " $path /a/yyy" ) = bar ]]
80- [[ $( cat " $path /a/zzz" ) = bar ]]
81- [[ $( cat " $path /c/aap" ) = bar ]]
82- [[ $( cat " $path /fnord" ) = bar ]]
76+ nix flake prefetch --json " tarball+file://$( pwd) /tree.tar.gz" --out-link " $TEST_ROOT /result "
77+ [[ $( cat " $TEST_ROOT /result /a/b/foo" ) = bar ]]
78+ [[ $( cat " $TEST_ROOT /result /a/b/xyzzy" ) = bar ]]
79+ [[ $( cat " $TEST_ROOT /result /a/yyy" ) = bar ]]
80+ [[ $( cat " $TEST_ROOT /result /a/zzz" ) = bar ]]
81+ [[ $( cat " $TEST_ROOT /result /c/aap" ) = bar ]]
82+ [[ $( cat " $TEST_ROOT /result /fnord" ) = bar ]]
8383
8484# Test a tarball that has multiple top-level directories.
8585rm -rf " $TEST_ROOT /tar_root"
You can’t perform that action at this time.
0 commit comments