Skip to content

Commit 8384e41

Browse files
authored
Merge pull request #12559 from DeterminateSystems/archive-relative-paths
nix flake archive: Recurse into relative path inputs
2 parents c8a443d + 14c9755 commit 8384e41

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

src/nix/flake.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,21 +1090,21 @@ struct CmdFlakeArchive : FlakeCommand, MixJSON, MixDryRun
10901090
nlohmann::json jsonObj2 = json ? json::object() : nlohmann::json(nullptr);
10911091
for (auto & [inputName, input] : node.inputs) {
10921092
if (auto inputNode = std::get_if<0>(&input)) {
1093-
if ((*inputNode)->lockedRef.input.isRelative())
1094-
continue;
1095-
auto storePath =
1096-
dryRun
1097-
? (*inputNode)->lockedRef.input.computeStorePath(*store)
1098-
: (*inputNode)->lockedRef.input.fetchToStore(store).first;
1093+
std::optional<StorePath> storePath;
1094+
if (!(*inputNode)->lockedRef.input.isRelative()) {
1095+
storePath =
1096+
dryRun
1097+
? (*inputNode)->lockedRef.input.computeStorePath(*store)
1098+
: (*inputNode)->lockedRef.input.fetchToStore(store).first;
1099+
sources.insert(*storePath);
1100+
}
10991101
if (json) {
11001102
auto & jsonObj3 = jsonObj2[inputName];
1101-
jsonObj3["path"] = store->printStorePath(storePath);
1102-
sources.insert(std::move(storePath));
1103+
if (storePath)
1104+
jsonObj3["path"] = store->printStorePath(*storePath);
11031105
jsonObj3["inputs"] = traverse(**inputNode);
1104-
} else {
1105-
sources.insert(std::move(storePath));
1106+
} else
11061107
traverse(**inputNode);
1107-
}
11081108
}
11091109
}
11101110
return jsonObj2;

tests/functional/flakes/common.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ writeTrivialFlake() {
9999
EOF
100100
}
101101

102+
initGitRepo() {
103+
local repo="$1"
104+
local extraArgs="${2-}"
105+
106+
# shellcheck disable=SC2086 # word splitting of extraArgs is intended
107+
git -C "$repo" init $extraArgs
108+
git -C "$repo" config user.email "[email protected]"
109+
git -C "$repo" config user.name "Foobar"
110+
}
111+
102112
createGitRepo() {
103113
local repo="$1"
104114
local extraArgs="${2-}"
@@ -107,7 +117,5 @@ createGitRepo() {
107117
mkdir -p "$repo"
108118

109119
# shellcheck disable=SC2086 # word splitting of extraArgs is intended
110-
git -C "$repo" init $extraArgs
111-
git -C "$repo" config user.email "[email protected]"
112-
git -C "$repo" config user.name "Foobar"
120+
initGitRepo "$repo" $extraArgs
113121
}

tests/functional/flakes/relative-paths.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ EOF
4545

4646
[[ $(nix eval "$rootFlake?dir=sub1#y") = 6 ]]
4747

48-
git init "$rootFlake"
48+
initGitRepo "$rootFlake"
4949
git -C "$rootFlake" add flake.nix sub0/flake.nix sub1/flake.nix
5050

5151
[[ $(nix eval "$subflake1#y") = 6 ]]
@@ -77,7 +77,17 @@ fi
7777
(! grep narHash "$subflake2/flake.lock")
7878

7979
# Test `nix flake archive` with relative path flakes.
80-
nix flake archive --json "$rootFlake"
80+
git -C "$rootFlake" add flake.lock
81+
git -C "$rootFlake" commit -a -m Foo
82+
83+
json=$(nix flake archive --json "$rootFlake" --to "$TEST_ROOT/store2")
84+
[[ $(echo "$json" | jq .inputs.sub0.inputs) = {} ]]
85+
[[ -n $(echo "$json" | jq .path) ]]
86+
87+
nix flake prefetch --out-link "$TEST_ROOT/result" "$rootFlake"
88+
outPath=$(readlink "$TEST_ROOT/result")
89+
90+
[ -e "$TEST_ROOT/store2/nix/store/$(basename "$outPath")" ]
8191

8292
# Test circular relative path flakes. FIXME: doesn't work at the moment.
8393
if false; then

0 commit comments

Comments
 (0)