|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# https://github.com/NixOS/nix/issues/13247 |
| 4 | + |
| 5 | +export NIX_TESTS_CA_BY_DEFAULT=1 |
| 6 | + |
| 7 | +source common.sh |
| 8 | + |
| 9 | +clearStoreIfPossible |
| 10 | + |
| 11 | +set -x |
| 12 | + |
| 13 | +# Build derivation (both outputs) |
| 14 | +nix build -f issue-13247.nix --json a a-prime use-a-more-outputs --no-link > "$TEST_ROOT"/a.json |
| 15 | + |
| 16 | +cache="file://$TEST_ROOT/cache" |
| 17 | + |
| 18 | +# Copy all outputs and realisations to cache |
| 19 | +declare -a drvs |
| 20 | +for d in "$NIX_STORE_DIR"/*-issue-13247-a.drv "$NIX_STORE_DIR"/*-use-a-more-outputs.drv; do |
| 21 | + drvs+=("$d" "$d"^*) |
| 22 | +done |
| 23 | +nix copy --to "$cache" "${drvs[@]}" |
| 24 | + |
| 25 | +function delete () { |
| 26 | + # Delete local copy |
| 27 | + # shellcheck disable=SC2046 |
| 28 | + nix-store --delete \ |
| 29 | + $(jq -r <"$TEST_ROOT"/a.json '.[] | .drvPath, .outputs.[]') \ |
| 30 | + "$NIX_STORE_DIR"/*-issue-13247-a.drv \ |
| 31 | + "$NIX_STORE_DIR"/*-use-a-more-outputs.drv |
| 32 | + |
| 33 | + [[ ! -e "$(jq -r <"$TEST_ROOT"/a.json '.[0].outputs.out')" ]] |
| 34 | + [[ ! -e "$(jq -r <"$TEST_ROOT"/a.json '.[1].outputs.out')" ]] |
| 35 | + [[ ! -e "$(jq -r <"$TEST_ROOT"/a.json '.[2].outputs.first')" ]] |
| 36 | + [[ ! -e "$(jq -r <"$TEST_ROOT"/a.json '.[2].outputs.second')" ]] |
| 37 | +} |
| 38 | + |
| 39 | +delete |
| 40 | + |
| 41 | +buildViaSubstitute () { |
| 42 | + nix build -f issue-13247.nix "$1" --no-link --max-jobs 0 --substituters "$cache" --no-require-sigs --offline --substitute |
| 43 | +} |
| 44 | + |
| 45 | +# Substitue just the first output |
| 46 | +buildViaSubstitute use-a-more-outputs^first |
| 47 | + |
| 48 | +# Should only fetch the output we asked for |
| 49 | +[[ -d "$(jq -r <"$TEST_ROOT"/a.json '.[0].outputs.out')" ]] |
| 50 | +[[ -f "$(jq -r <"$TEST_ROOT"/a.json '.[2].outputs.first')" ]] |
| 51 | +[[ ! -e "$(jq -r <"$TEST_ROOT"/a.json '.[2].outputs.second')" ]] |
| 52 | + |
| 53 | +delete |
| 54 | + |
| 55 | +# Substitue just the first output |
| 56 | +# |
| 57 | +# This derivation is the same after normalization, so we should get |
| 58 | +# early cut-off, and thus a chance to download just the output we want |
| 59 | +# rather than building more |
| 60 | +buildViaSubstitute use-a-prime-more-outputs^first |
| 61 | + |
| 62 | +# Should only fetch the output we asked for |
| 63 | +[[ -d "$(jq -r <"$TEST_ROOT"/a.json '.[0].outputs.out')" ]] |
| 64 | +[[ -f "$(jq -r <"$TEST_ROOT"/a.json '.[2].outputs.first')" ]] |
| 65 | + |
| 66 | +# Output should *not* be here, this is the bug |
| 67 | +[[ -e "$(jq -r <"$TEST_ROOT"/a.json '.[2].outputs.second')" ]] |
| 68 | +skipTest "bug is not yet fixed" |
0 commit comments