forked from lix-project/lix
Merge pull request #9173 from vkryachko/transitive-input-overrides
Fix transitive input locking.
This commit is contained in:
commit
bf13943206
|
@ -358,10 +358,13 @@ LockedFlake lockFlake(
|
||||||
debug("old lock file: %s", oldLockFile);
|
debug("old lock file: %s", oldLockFile);
|
||||||
|
|
||||||
std::map<InputPath, FlakeInput> overrides;
|
std::map<InputPath, FlakeInput> overrides;
|
||||||
|
std::set<InputPath> explicitCliOverrides;
|
||||||
std::set<InputPath> overridesUsed, updatesUsed;
|
std::set<InputPath> overridesUsed, updatesUsed;
|
||||||
|
|
||||||
for (auto & i : lockFlags.inputOverrides)
|
for (auto & i : lockFlags.inputOverrides) {
|
||||||
overrides.insert_or_assign(i.first, FlakeInput { .ref = i.second });
|
overrides.insert_or_assign(i.first, FlakeInput { .ref = i.second });
|
||||||
|
explicitCliOverrides.insert(i.first);
|
||||||
|
}
|
||||||
|
|
||||||
LockFile newLockFile;
|
LockFile newLockFile;
|
||||||
|
|
||||||
|
@ -432,6 +435,7 @@ LockedFlake lockFlake(
|
||||||
ancestors? */
|
ancestors? */
|
||||||
auto i = overrides.find(inputPath);
|
auto i = overrides.find(inputPath);
|
||||||
bool hasOverride = i != overrides.end();
|
bool hasOverride = i != overrides.end();
|
||||||
|
bool hasCliOverride = explicitCliOverrides.contains(inputPath);
|
||||||
if (hasOverride) {
|
if (hasOverride) {
|
||||||
overridesUsed.insert(inputPath);
|
overridesUsed.insert(inputPath);
|
||||||
// Respect the “flakeness” of the input even if we
|
// Respect the “flakeness” of the input even if we
|
||||||
|
@ -467,7 +471,7 @@ LockedFlake lockFlake(
|
||||||
|
|
||||||
if (oldLock
|
if (oldLock
|
||||||
&& oldLock->originalRef == *input.ref
|
&& oldLock->originalRef == *input.ref
|
||||||
&& !hasOverride)
|
&& !hasCliOverride)
|
||||||
{
|
{
|
||||||
debug("keeping existing input '%s'", inputPathS);
|
debug("keeping existing input '%s'", inputPathS);
|
||||||
|
|
||||||
|
@ -547,7 +551,7 @@ LockedFlake lockFlake(
|
||||||
nuked the next time we update the lock
|
nuked the next time we update the lock
|
||||||
file. That is, overrides are sticky unless you
|
file. That is, overrides are sticky unless you
|
||||||
use --no-write-lock-file. */
|
use --no-write-lock-file. */
|
||||||
auto ref = input2.ref ? *input2.ref : *input.ref;
|
auto ref = (input2.ref && explicitCliOverrides.contains(inputPath)) ? *input2.ref : *input.ref;
|
||||||
|
|
||||||
if (input.isFlake) {
|
if (input.isFlake) {
|
||||||
Path localPath = parentPath;
|
Path localPath = parentPath;
|
||||||
|
|
|
@ -260,3 +260,79 @@ EOF
|
||||||
|
|
||||||
checkRes=$(nix flake lock "$flakeFollowCycle" 2>&1 && fail "nix flake lock should have failed." || true)
|
checkRes=$(nix flake lock "$flakeFollowCycle" 2>&1 && fail "nix flake lock should have failed." || true)
|
||||||
echo $checkRes | grep -F "error: follow cycle detected: [baz -> foo -> bar -> baz]"
|
echo $checkRes | grep -F "error: follow cycle detected: [baz -> foo -> bar -> baz]"
|
||||||
|
|
||||||
|
|
||||||
|
# Test transitive input url locking
|
||||||
|
# This tests the following lockfile issue: https://github.com/NixOS/nix/issues/9143
|
||||||
|
#
|
||||||
|
# We construct the following graph, where p->q means p has input q.
|
||||||
|
#
|
||||||
|
# A -> B -> C
|
||||||
|
#
|
||||||
|
# And override B/C to flake D, first in A's flake.nix and then with --override-input.
|
||||||
|
#
|
||||||
|
# A -> B -> D
|
||||||
|
flakeFollowsCustomUrlA="$TEST_ROOT/follows/custom-url/flakeA"
|
||||||
|
flakeFollowsCustomUrlB="$TEST_ROOT/follows/custom-url/flakeA/flakeB"
|
||||||
|
flakeFollowsCustomUrlC="$TEST_ROOT/follows/custom-url/flakeA/flakeB/flakeC"
|
||||||
|
flakeFollowsCustomUrlD="$TEST_ROOT/follows/custom-url/flakeA/flakeB/flakeD"
|
||||||
|
|
||||||
|
|
||||||
|
createGitRepo "$flakeFollowsCustomUrlA"
|
||||||
|
mkdir -p "$flakeFollowsCustomUrlB"
|
||||||
|
mkdir -p "$flakeFollowsCustomUrlC"
|
||||||
|
mkdir -p "$flakeFollowsCustomUrlD"
|
||||||
|
|
||||||
|
cat > "$flakeFollowsCustomUrlD/flake.nix" <<EOF
|
||||||
|
{
|
||||||
|
description = "Flake D";
|
||||||
|
inputs = {};
|
||||||
|
outputs = { ... }: {};
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat > "$flakeFollowsCustomUrlC/flake.nix" <<EOF
|
||||||
|
{
|
||||||
|
description = "Flake C";
|
||||||
|
inputs = {};
|
||||||
|
outputs = { ... }: {};
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat > "$flakeFollowsCustomUrlB/flake.nix" <<EOF
|
||||||
|
{
|
||||||
|
description = "Flake B";
|
||||||
|
inputs = {
|
||||||
|
C = {
|
||||||
|
url = "path:./flakeC";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
outputs = { ... }: {};
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat > "$flakeFollowsCustomUrlA/flake.nix" <<EOF
|
||||||
|
{
|
||||||
|
description = "Flake A";
|
||||||
|
inputs = {
|
||||||
|
B = {
|
||||||
|
url = "path:./flakeB";
|
||||||
|
inputs.C.url = "path:./flakeB/flakeD";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
outputs = { ... }: {};
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
git -C "$flakeFollowsCustomUrlA" add flake.nix flakeB/flake.nix \
|
||||||
|
flakeB/flakeC/flake.nix flakeB/flakeD/flake.nix
|
||||||
|
|
||||||
|
# lock "original" entry should contain overridden url
|
||||||
|
json=$(nix flake metadata "$flakeFollowsCustomUrlA" --json)
|
||||||
|
[[ $(echo "$json" | jq -r .locks.nodes.C.original.path) = './flakeB/flakeD' ]]
|
||||||
|
rm "$flakeFollowsCustomUrlA"/flake.lock
|
||||||
|
|
||||||
|
# if override-input is specified, lock "original" entry should contain original url
|
||||||
|
json=$(nix flake metadata "$flakeFollowsCustomUrlA" --override-input B/C "path:./flakeB/flakeD" --json)
|
||||||
|
echo "$json" | jq .locks.nodes.C.original
|
||||||
|
[[ $(echo "$json" | jq -r .locks.nodes.C.original.path) = './flakeC' ]]
|
||||||
|
|
Loading…
Reference in a new issue