Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/nix/flake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1088,21 +1088,21 @@ 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;
std::optional<StorePath> storePath;
if (!(*inputNode)->lockedRef.input.isRelative()) {
storePath =
dryRun
? (*inputNode)->lockedRef.input.computeStorePath(*store)
: (*inputNode)->lockedRef.input.fetchToStore(store).first;
sources.insert(*storePath);
}
if (json) {
auto & jsonObj3 = jsonObj2[inputName];
jsonObj3["path"] = store->printStorePath(storePath);
sources.insert(std::move(storePath));
if (storePath)
jsonObj3["path"] = store->printStorePath(*storePath);
jsonObj3["inputs"] = traverse(**inputNode);
} else {
sources.insert(std::move(storePath));
} else
traverse(**inputNode);
}
}
}
return jsonObj2;
Expand Down
14 changes: 11 additions & 3 deletions tests/functional/flakes/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ writeTrivialFlake() {
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() {
local repo="$1"
local extraArgs="${2-}"
Expand All @@ -107,7 +117,5 @@ createGitRepo() {
mkdir -p "$repo"

# 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"
initGitRepo "$repo" $extraArgs
}
14 changes: 12 additions & 2 deletions tests/functional/flakes/relative-paths.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ EOF

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

git init "$rootFlake"
initGitRepo "$rootFlake"
git -C "$rootFlake" add flake.nix sub0/flake.nix sub1/flake.nix

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

# 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.
if false; then
Expand Down
Loading