Skip to content

Commit c279ddb

Browse files
committed
tests: Reproduce #6572
1 parent 7e162c6 commit c279ddb

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

tests/build.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,54 @@ testNormalization () {
7070
}
7171

7272
testNormalization
73+
74+
# https://github.com/NixOS/nix/issues/6572
75+
issue_6572_independent_outputs() {
76+
nix build -f multiple-outputs.nix --json independent --no-link > $TEST_ROOT/independent.json
77+
78+
# Make sure that 'nix build' can build a derivation that depends on both outputs of another derivation.
79+
p=$(nix build -f multiple-outputs.nix use-independent --no-link --print-out-paths)
80+
nix-store --delete "$p" # Clean up for next test
81+
82+
# Make sure that 'nix build' tracks input-outputs correctly when a single output is already present.
83+
nix-store --delete "$(jq -r <$TEST_ROOT/independent.json .[0].outputs.first)"
84+
p=$(nix build -f multiple-outputs.nix use-independent --no-link --print-out-paths)
85+
cmp $p <<EOF
86+
first
87+
second
88+
EOF
89+
nix-store --delete "$p" # Clean up for next test
90+
91+
# Make sure that 'nix build' tracks input-outputs correctly when a single output is already present.
92+
nix-store --delete "$(jq -r <$TEST_ROOT/independent.json .[0].outputs.second)"
93+
p=$(nix build -f multiple-outputs.nix use-independent --no-link --print-out-paths)
94+
cmp $p <<EOF
95+
first
96+
second
97+
EOF
98+
nix-store --delete "$p" # Clean up for next test
99+
}
100+
issue_6572_independent_outputs
101+
102+
103+
# https://github.com/NixOS/nix/issues/6572
104+
issue_6572_dependent_outputs() {
105+
106+
nix build -f multiple-outputs.nix --json a --no-link > $TEST_ROOT/a.json
107+
108+
# # Make sure that 'nix build' can build a derivation that depends on both outputs of another derivation.
109+
p=$(nix build -f multiple-outputs.nix use-a --no-link --print-out-paths)
110+
nix-store --delete "$p" # Clean up for next test
111+
112+
# Make sure that 'nix build' tracks input-outputs correctly when a single output is already present.
113+
nix-store --delete "$(jq -r <$TEST_ROOT/a.json .[0].outputs.second)"
114+
p=$(nix build -f multiple-outputs.nix use-a --no-link --print-out-paths)
115+
cmp $p <<EOF
116+
first
117+
second
118+
EOF
119+
nix-store --delete "$p" # Clean up for next test
120+
}
121+
if isDaemonNewer "2.12pre0"; then
122+
issue_6572_dependent_outputs
123+
fi

tests/multiple-outputs.nix

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ rec {
3131
helloString = "Hello, world!";
3232
};
3333

34+
use-a = mkDerivation {
35+
name = "use-a";
36+
inherit (a) first second;
37+
builder = builtins.toFile "builder.sh"
38+
''
39+
cat $first/file $second/file >$out
40+
'';
41+
};
42+
3443
b = mkDerivation {
3544
defaultOutput = assert a.second.helloString == "Hello, world!"; a;
3645
firstOutput = assert a.outputName == "first"; a.first.first;
@@ -87,4 +96,25 @@ rec {
8796
buildCommand = "mkdir $a $b $c";
8897
};
8998

99+
independent = mkDerivation {
100+
name = "multiple-outputs-independent";
101+
outputs = [ "first" "second" ];
102+
builder = builtins.toFile "builder.sh"
103+
''
104+
mkdir $first $second
105+
test -z $all
106+
echo "first" > $first/file
107+
echo "second" > $second/file
108+
'';
109+
};
110+
111+
use-independent = mkDerivation {
112+
name = "use-independent";
113+
inherit (a) first second;
114+
builder = builtins.toFile "builder.sh"
115+
''
116+
cat $first/file $second/file >$out
117+
'';
118+
};
119+
90120
}

0 commit comments

Comments
 (0)