Skip to content

Commit da1641a

Browse files
committed
tools: improve nix-changes coverage
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent d6bbf57 commit da1641a

2 files changed

Lines changed: 77 additions & 30 deletions

File tree

.github/workflows/nix-changes.yml

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ on:
1111
- v[0-9]+.x
1212
paths:
1313
- '**.nix'
14+
- tools/nix/list-requesites.sh
1415
- .github/workflows/nix-changes.yml
1516
pull_request:
1617
paths:
1718
- '**.nix'
19+
- tools/nix/list-requesites.sh
1820
- .github/workflows/nix-changes.yml
1921
types: [opened, synchronize, reopened, ready_for_review]
2022

@@ -47,7 +49,9 @@ jobs:
4749
with:
4850
fetch-depth: 2
4951
persist-credentials: false
50-
sparse-checkout: '*.nix'
52+
sparse-checkout: |
53+
./tools/nix/list-requesites.sh
54+
'*.nix'
5155
sparse-checkout-cone-mode: false
5256

5357
- uses: cachix/install-nix-action@630ae543ea3a38a9a4166f03376c02c50f408342 # v31.11.0
@@ -60,39 +64,12 @@ jobs:
6064
name: nodejs
6165

6266
- name: Compute requisites after change
63-
shell: bash # See https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference, we want the pipefail option.
64-
run: |
65-
nix-store --query --references "$(
66-
nix-instantiate -I "nixpkgs=./tools/nix/pkgs.nix" shell.nix \
67-
--arg devTools "
68-
(import ./tools/nix/devTools.nix {})
69-
++ builtins.attrValues (
70-
{ inherit (import <nixpkgs> {}) nixfmt-tree sccache; }
71-
// import ./tools/nix/openssl-matrix.nix {}
72-
// import ./tools/nix/pkcs11.nix {}
73-
)")" \
74-
| xargs nix-store --realise \
75-
| xargs nix-store --query --requisites \
76-
| sort -k1.45 \
77-
> requisites-${{ matrix.system }}-after.list
67+
run: ./tools/nix/list-requesites.sh > requisites-${{ matrix.system }}-after.list
7868

7969
- name: Compute requisites before change
80-
shell: bash # See https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference, we want the pipefail option.
8170
run: |
8271
git reset HEAD^ --hard
83-
nix-store --query --references "$(
84-
nix-instantiate -I "nixpkgs=./tools/nix/pkgs.nix" shell.nix \
85-
--arg devTools "
86-
(import ./tools/nix/devTools.nix {})
87-
++ builtins.attrValues (
88-
{ inherit (import <nixpkgs> {}) nixfmt-tree sccache; }
89-
// import ./tools/nix/openssl-matrix.nix {}
90-
// import ./tools/nix/pkcs11.nix {}
91-
)")" \
92-
| xargs nix-store --realise \
93-
| xargs nix-store --query --requisites \
94-
| sort -k1.45 \
95-
> requisites-${{ matrix.system }}-before.list
72+
./tools/nix/list-requesites.sh > requisites-${{ matrix.system }}-before.list
9673
9774
- name: Output diff
9875
run: |

tools/nix/list-requesites.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/sh
2+
3+
set -ex
4+
5+
OPTIONAL_FLAGS=$(nix-instantiate \
6+
--eval --strict --json -E '
7+
builtins.filter
8+
(n: builtins.match "with[A-Z].+" n != null)
9+
(builtins.attrNames (builtins.functionArgs (import ./shell.nix)))
10+
' | jq -r 'map("--arg \(.) true") | join(" ")')
11+
12+
PIPEFAIL="$(mktemp)"
13+
14+
cleanup () {
15+
EXIT_CODE=$?
16+
rm "$PIPEFAIL"
17+
exit $EXIT_CODE
18+
}
19+
20+
trap cleanup INT TERM EXIT
21+
22+
{
23+
# shellcheck disable=SC2086
24+
nix-instantiate -I "nixpkgs=./tools/nix/pkgs.nix" shell.nix \
25+
$OPTIONAL_FLAGS \
26+
--arg sharedLibDeps '{
27+
# Using an empty set as some build dependencies are required only in the absence of shared deps (e.g. Cargo).
28+
# We pass the shared deps as devTools below so they are still accounted for.
29+
}' \
30+
--arg pkcs11 'import ./tools/nix/pkcs11.nix {
31+
# Passing an import call rather than "true" to workaround sharedLibDeps being empty.
32+
}' \
33+
--arg devTools '
34+
let
35+
pkgs = import <nixpkgs> { };
36+
sharedLibDepsFn = import ./tools/nix/sharedLibDeps.nix;
37+
in
38+
(import ./tools/nix/devTools.nix { })
39+
++ pkgs.lib.flatten (
40+
with (pkgs.callPackage ./tools/nix/v8.nix { });
41+
[
42+
# We do not want to build V8 here, but still want to list its requisites.
43+
buildInputs
44+
nativeBuildInputs
45+
propagatedBuildInputs
46+
propagatedNativeBuildInputs
47+
(pkgs.callPackage ./tools/nix/non-v8-deps-mock.nix { })
48+
]
49+
)
50+
++ builtins.attrValues (
51+
{
52+
# Additional packages we are using across the codebase
53+
inherit (pkgs) nixfmt-tree sccache;
54+
}
55+
// import ./tools/nix/openssl-matrix.nix { }
56+
// sharedLibDepsFn (
57+
pkgs.lib.filterAttrs (n: v: builtins.match "with[A-Z].+" n != null) (
58+
builtins.functionArgs sharedLibDepsFn
59+
)
60+
)
61+
)' || echo > "$PIPEFAIL"
62+
} | {
63+
xargs nix-store --query --references || echo > "$PIPEFAIL"
64+
} | {
65+
xargs nix-store --realise || echo > "$PIPEFAIL"
66+
} | {
67+
xargs nix-store --query --requisites || echo > "$PIPEFAIL"
68+
} | {
69+
sort -k1.45 || echo > "$PIPEFAIL"
70+
} && [ ! -s "$PIPEFAIL" ]

0 commit comments

Comments
 (0)