From d670380bd9f63d83655a0bde71b285103735b072 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 24 Feb 2025 15:30:30 +0100 Subject: [PATCH] nix flake archive: Skip relative path inputs Fixes #12438. (cherry picked from commit b4dfeafed5e2b0d8d6fd90bef4d3bed24caa4734) --- src/nix/flake.cc | 4 +++- tests/functional/flakes/relative-paths.sh | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 4d5cad1a8..87eaafd15 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -1088,12 +1088,14 @@ struct CmdFlakeArchive : FlakeCommand, MixJSON, MixDryRun nlohmann::json jsonObj2 = json ? json::object() : nlohmann::json(nullptr); for (auto & [inputName, input] : node.inputs) { if (auto inputNode = std::get_if<0>(&input)) { + if ((*inputNode)->lockedRef.input.isRelative()) + continue; auto storePath = dryRun ? (*inputNode)->lockedRef.input.computeStorePath(*store) : (*inputNode)->lockedRef.input.fetchToStore(store).first; if (json) { - auto& jsonObj3 = jsonObj2[inputName]; + auto & jsonObj3 = jsonObj2[inputName]; jsonObj3["path"] = store->printStorePath(storePath); sources.insert(std::move(storePath)); jsonObj3["inputs"] = traverse(**inputNode); diff --git a/tests/functional/flakes/relative-paths.sh b/tests/functional/flakes/relative-paths.sh index 9b93da9c1..ac4b07eb2 100644 --- a/tests/functional/flakes/relative-paths.sh +++ b/tests/functional/flakes/relative-paths.sh @@ -76,6 +76,9 @@ if ! isTestOnNixOS; then fi (! grep narHash "$subflake2/flake.lock") +# Test `nix flake archive` with relative path flakes. +nix flake archive --json "$rootFlake" + # Test circular relative path flakes. FIXME: doesn't work at the moment. if false; then