1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 14:51:16 +02:00

Merge pull request #12562 from NixOS/mergify/bp/2.26-maintenance/pr-12559

nix flake archive: Recurse into relative path inputs (backport #12559)
This commit is contained in:
mergify[bot] 2025-02-24 22:18:03 +00:00 committed by GitHub
commit 1dda07eef2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 16 deletions

View file

@ -1088,23 +1088,23 @@ struct CmdFlakeArchive : FlakeCommand, MixJSON, MixDryRun
nlohmann::json jsonObj2 = json ? json::object() : nlohmann::json(nullptr); nlohmann::json jsonObj2 = json ? json::object() : nlohmann::json(nullptr);
for (auto & [inputName, input] : node.inputs) { for (auto & [inputName, input] : node.inputs) {
if (auto inputNode = std::get_if<0>(&input)) { if (auto inputNode = std::get_if<0>(&input)) {
if ((*inputNode)->lockedRef.input.isRelative()) std::optional<StorePath> storePath;
continue; if (!(*inputNode)->lockedRef.input.isRelative()) {
auto storePath = storePath =
dryRun dryRun
? (*inputNode)->lockedRef.input.computeStorePath(*store) ? (*inputNode)->lockedRef.input.computeStorePath(*store)
: (*inputNode)->lockedRef.input.fetchToStore(store).first; : (*inputNode)->lockedRef.input.fetchToStore(store).first;
sources.insert(*storePath);
}
if (json) { if (json) {
auto & jsonObj3 = jsonObj2[inputName]; auto & jsonObj3 = jsonObj2[inputName];
jsonObj3["path"] = store->printStorePath(storePath); if (storePath)
sources.insert(std::move(storePath)); jsonObj3["path"] = store->printStorePath(*storePath);
jsonObj3["inputs"] = traverse(**inputNode); jsonObj3["inputs"] = traverse(**inputNode);
} else { } else
sources.insert(std::move(storePath));
traverse(**inputNode); traverse(**inputNode);
} }
} }
}
return jsonObj2; return jsonObj2;
}; };

View file

@ -99,6 +99,16 @@ writeTrivialFlake() {
EOF EOF
} }
initGitRepo() {
local repo="$1"
local extraArgs="${2-}"
# shellcheck disable=SC2086 # word splitting of extraArgs is intended
git -C "$repo" init $extraArgs
git -C "$repo" config user.email "foobar@example.com"
git -C "$repo" config user.name "Foobar"
}
createGitRepo() { createGitRepo() {
local repo="$1" local repo="$1"
local extraArgs="${2-}" local extraArgs="${2-}"
@ -107,7 +117,5 @@ createGitRepo() {
mkdir -p "$repo" mkdir -p "$repo"
# shellcheck disable=SC2086 # word splitting of extraArgs is intended # shellcheck disable=SC2086 # word splitting of extraArgs is intended
git -C "$repo" init $extraArgs initGitRepo "$repo" $extraArgs
git -C "$repo" config user.email "foobar@example.com"
git -C "$repo" config user.name "Foobar"
} }

View file

@ -45,7 +45,7 @@ EOF
[[ $(nix eval "$rootFlake?dir=sub1#y") = 6 ]] [[ $(nix eval "$rootFlake?dir=sub1#y") = 6 ]]
git init "$rootFlake" initGitRepo "$rootFlake"
git -C "$rootFlake" add flake.nix sub0/flake.nix sub1/flake.nix git -C "$rootFlake" add flake.nix sub0/flake.nix sub1/flake.nix
[[ $(nix eval "$subflake1#y") = 6 ]] [[ $(nix eval "$subflake1#y") = 6 ]]
@ -77,7 +77,17 @@ fi
(! grep narHash "$subflake2/flake.lock") (! grep narHash "$subflake2/flake.lock")
# Test `nix flake archive` with relative path flakes. # Test `nix flake archive` with relative path flakes.
nix flake archive --json "$rootFlake" git -C "$rootFlake" add flake.lock
git -C "$rootFlake" commit -a -m Foo
json=$(nix flake archive --json "$rootFlake" --to "$TEST_ROOT/store2")
[[ $(echo "$json" | jq .inputs.sub0.inputs) = {} ]]
[[ -n $(echo "$json" | jq .path) ]]
#nix flake prefetch --out-link "$TEST_ROOT/result" "$rootFlake"
#outPath=$(readlink "$TEST_ROOT/result")
#[ -e "$TEST_ROOT/store2/nix/store/$(basename "$outPath")" ]
# Test circular relative path flakes. FIXME: doesn't work at the moment. # Test circular relative path flakes. FIXME: doesn't work at the moment.
if false; then if false; then