From e7faf65784f5052d6dddeb5532f9829e5f6a07b9 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 25 Jul 2022 15:12:28 +0200 Subject: [PATCH] Remove FlakeRef::fetchTree() --- src/libexpr/flake/flakeref.cc | 6 ------ src/libexpr/flake/flakeref.hh | 2 -- src/nix/flake-prefetch.md | 9 +++------ src/nix/flake.cc | 12 +++--------- 4 files changed, 6 insertions(+), 23 deletions(-) diff --git a/src/libexpr/flake/flakeref.cc b/src/libexpr/flake/flakeref.cc index 0b30b8467..0a53037fa 100644 --- a/src/libexpr/flake/flakeref.cc +++ b/src/libexpr/flake/flakeref.cc @@ -229,12 +229,6 @@ FlakeRef FlakeRef::fromAttrs(const fetchers::Attrs & attrs) fetchers::maybeGetStrAttr(attrs, "dir").value_or("")); } -std::pair FlakeRef::fetchTree(ref store) const -{ - auto [tree, lockedInput] = input.fetch(store); - return {std::move(tree), FlakeRef(std::move(lockedInput), subdir)}; -} - std::pair, FlakeRef> FlakeRef::lazyFetch(ref store) const { auto [accessor, lockedInput] = input.lazyFetch(store); diff --git a/src/libexpr/flake/flakeref.hh b/src/libexpr/flake/flakeref.hh index bdf93b251..5157dc325 100644 --- a/src/libexpr/flake/flakeref.hh +++ b/src/libexpr/flake/flakeref.hh @@ -57,8 +57,6 @@ struct FlakeRef static FlakeRef fromAttrs(const fetchers::Attrs & attrs); - std::pair fetchTree(ref store) const; - std::pair, FlakeRef> lazyFetch(ref store) const; }; diff --git a/src/nix/flake-prefetch.md b/src/nix/flake-prefetch.md index a1cf0289a..28a5f8844 100644 --- a/src/nix/flake-prefetch.md +++ b/src/nix/flake-prefetch.md @@ -2,21 +2,18 @@ R""( # Examples -* Download a tarball and unpack it: +* Download a tarball: ```console # nix flake prefetch https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.5.tar.xz - 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 - 'sha256-3XYHZANT6AFBV0BqegkAZHbba6oeDkIUCDwbATLMhAY='). + Fetched 'https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.5.tar.xz?narHash=sha256-3XYHZANT6AFBV0BqegkAZHbba6oeDkIUCDwbATLMhAY='. ``` * Download the `dwarffs` flake (looked up in the flake registry): ```console # nix flake prefetch dwarffs --json - {"hash":"sha256-VHg3MYVgQ12LeRSU2PSoDeKlSPD8PYYEFxxwkVVDRd0=" - ,"storePath":"/nix/store/hang3792qwdmm2n0d9nsrs5n6bsws6kv-source"} + {} ``` # Description diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 5a0094d04..2ff096faa 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -1163,7 +1163,7 @@ struct CmdFlakePrefetch : FlakeCommand, MixJSON std::string description() override { - return "download the source tree denoted by a flake reference into the Nix store"; + return "fetch the source tree denoted by a flake reference"; } std::string doc() override @@ -1177,19 +1177,13 @@ struct CmdFlakePrefetch : FlakeCommand, MixJSON { auto originalRef = getFlakeRef(); auto resolvedRef = originalRef.resolve(store); - auto [tree, lockedRef] = resolvedRef.fetchTree(store); - auto hash = store->queryPathInfo(tree.storePath)->narHash; + auto [accessor, lockedRef] = resolvedRef.lazyFetch(store); if (json) { auto res = nlohmann::json::object(); - res["storePath"] = store->printStorePath(tree.storePath); - res["hash"] = hash.to_string(SRI, true); logger->cout(res.dump()); } else { - notice("Downloaded '%s' to '%s' (hash '%s').", - lockedRef.to_string(), - store->printStorePath(tree.storePath), - hash.to_string(SRI, true)); + notice("Fetched '%s'.", lockedRef.to_string()); } } };