forked from
lass.pds.lassul.us/superconfig
This repository has no description
1.6 kB
38 lines
1#!/usr/bin/env bash
2# For the shared job of ci.yml: dry-run every matrix row and list the
3# derivations that more than one row would build (not substitutable from any
4# configured substituter). Usage: ci-shared.sh MATRIX_JSON OUTDIR
5# Writes OUTDIR/<name>.drvs per row, OUTDIR/shared-all.drvs and the
6# substitutable subset OUTDIR/shared.drvs.
7set -euo pipefail
8matrix=$1
9out=$2
10mkdir -p "$out"
11
12while IFS=$'\t' read -r name installables; do
13 read -ra inst <<<"$installables"
14 nix build --dry-run "${inst[@]}" 2>"$out/$name.plan" || {
15 cat "$out/$name.plan"
16 exit 1
17 }
18 # the drv lines below the "will be built:" header, up to the next header
19 awk '/^[^ ]/ { b = /will be built:$/; next } b && $1 ~ /^\/nix\/store\// { print $1 }' \
20 "$out/$name.plan" | sort -u >"$out/$name.drvs"
21done < <(jq -r '.include[] | [.name, .installables] | @tsv' "$matrix")
22
23jq -r '.include[].name' "$matrix" | while read -r name; do cat "$out/$name.drvs"; done |
24 sort | uniq -d >"$out/shared-all.drvs"
25
26# allowSubstitutes = false (trivial builders: etc files, units, wrappers) is
27# never substituted, every machine builds those again anyway
28if [ -s "$out/shared-all.drvs" ]; then
29 xargs nix derivation show <"$out/shared-all.drvs" | jq -r '
30 (.derivations // .) | to_entries[]
31 | select(.value
32 | (.structuredAttrs // (.env.__json | values | fromjson) // .env).allowSubstitutes
33 | . != false and . != "")
34 | if (.key | startswith("/")) then .key else "/nix/store/" + .key end' |
35 sort >"$out/shared.drvs"
36else
37 : >"$out/shared.drvs"
38fi