| 1 | #!/usr/bin/env bash |
| 2 | # The sibling of the nix stub: `nix-store --query --references <drv>` over |
| 3 | # the derivations it writes. One opaque store path per input file, named by |
| 4 | # the file's content, which is what makes the closure content-addressed. |
| 5 | # It also names a derivation's one output, where the nix stub builds it, |
| 6 | # and says which outputs are not built yet. |
| 7 | set -euo pipefail |
| 8 | |
| 9 | case "${1:-} ${2:-}" in |
| 10 | "--query --outputs") |
| 11 | drv="${*: -1}" |
| 12 | printf '%s\n' "${drv%.drv}.out" |
| 13 | exit 0 |
| 14 | ;; |
| 15 | "--check-validity --print-invalid") |
| 16 | shift 2 |
| 17 | for path in "$@"; do [ -e "$path" ] || printf '%s\n' "$path"; done |
| 18 | exit 0 |
| 19 | ;; |
| 20 | esac |
| 21 | |
| 22 | drv="${*: -1}" |
| 23 | [ -f "$drv" ] || { echo "nix-store (stub): no such derivation: $drv" >&2; exit 1; } |
| 24 | while read -r sum path; do |
| 25 | printf '/nix/store/%s-%s\n' "$sum" "${path//\//_}" |
| 26 | done < "$drv" |