gunk-dev/the-valley

nix-store

source8ffa911ee306main's published tip history
923 bytes
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, for attest's timing probe.
7set -euo pipefail
8
9case "${1:-} ${2:-}" in
10 "--query --outputs")
11 drv="${*: -1}"
12 if [ -f "$drv.output" ]; then cat "$drv.output"; else printf '%s\n' "${drv%.drv}.out"; fi
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 ;;
20esac
21
22drv="${*: -1}"
23[ -f "$drv" ] || { echo "nix-store (stub): no such derivation: $drv" >&2; exit 1; }
24while read -r sum path; do
25 printf '/nix/store/%s-%s\n' "$sum" "${path//\//_}"
26done < "$drv"