@@ -11,10 +11,156 @@ jobs:
1111 steps :
1212 - uses : actions/checkout@v3
1313 with :
14- # Nix Flakes doesn't work on shallow clones
15- fetch-depth : 0
14+ # Nix Flakes doesn't work on shallow clones
15+ fetch-depth : 0
1616 - uses : cachix/install-nix-action@v17
1717 - name : List flake structure
1818 run : nix flake show
1919 - name : Run unit tests (flake)
2020 run : nix build -L
21+ check :
22+ runs-on : ubuntu-latest
23+ steps :
24+ - uses : actions/checkout@v3
25+ with :
26+ fetch-depth : 0
27+ - uses : cachix/install-nix-action@v17
28+ - name : Run flake checks
29+ run : nix flake check --no-build --keep-going
30+ introspect :
31+ runs-on : ubuntu-latest
32+ outputs :
33+ nixpkgs-rev : ${{ steps.nixpkgs-rev.outputs.nixpkgs-rev }}
34+ nixos-rev : ${{ steps.nixpkgs-rev.outputs.nixos-rev }}
35+ formats : ${{ steps.list-formats.outputs.formats }}
36+ steps :
37+ - uses : actions/checkout@v3
38+ with :
39+ fetch-depth : 0
40+ - uses : cachix/install-nix-action@v17
41+ - name : Get nixpkgs rev
42+ id : nixpkgs-rev
43+ run : |
44+ getRev() {
45+ nix eval --impure --raw --expr "((builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.${1?}.locked.rev)"
46+ }
47+
48+ nixpkgs_rev=$(getRev nixpkgs) || exit
49+ nixos_rev=$(getRev nixos) || exit
50+
51+ echo "::set-output name=nixpkgs-rev::${nixpkgs_rev}"
52+ echo "::set-output name=nixos-rev::${nixos_rev}"
53+ - name : List available formats
54+ id : list-formats
55+ run : |
56+ # Run in nix-shell in order to use jq
57+ formats=$(nix develop --command bash -c './nixos-generate --list | jq -cnMR "[inputs]"') || exit
58+ echo "::set-output name=formats::${formats}"
59+ formats :
60+ strategy :
61+ matrix :
62+ format : ${{ needs.introspect.outputs.formats && fromJSON(needs.introspect.outputs.formats) }}
63+ nixpkgs-name :
64+ - nixpkgs
65+ - nixos
66+ include :
67+ - nixpkgs-name : nixpkgs
68+ nixpkgs : ' https://github.com/nixos/nixpkgs/archive/${{ needs.introspect.outputs.nixpkgs-rev }}.tar.gz'
69+ - nixpkgs-name : nixos
70+ nixpkgs : ' https://github.com/nixos/nixpkgs/archive/${{ needs.introspect.outputs.nixos-rev }}.tar.gz'
71+ - format : vm
72+ upload : true
73+ - format : vm-nogui
74+ upload : true
75+ - format : sd-aarch64-installer
76+ system : aarch64-linux
77+ - format : sd-aarch64
78+ system : aarch64-linux
79+ runs-on : ubuntu-latest
80+ needs : [ 'check', 'introspect' ]
81+ steps :
82+ - uses : actions/checkout@v3
83+ with :
84+ fetch-depth : 0
85+ # set up qemu if we are targeting a non-native system
86+ - uses : docker/setup-qemu-action@v2
87+ if : ${{ matrix.system }}
88+ - uses : cachix/install-nix-action@v17
89+ with :
90+ # kvm required for a number of formats; big-parallel required for
91+ # proxmox and possibly others.
92+ extra_nix_config : |
93+ system-features = big-parallel kvm
94+ extra-platforms = ${{ matrix.system }}
95+ - name : Output the current nixpkgs version
96+ id : nixpkgs-version
97+ if : ${{ matrix.upload }}
98+ run : |
99+ nixpkgs_version=$(nix eval -I nixpkgs=${{matrix.nixpkgs }} --raw nixpkgs#lib.version) || exit
100+ echo "::set-output name=nixpkgs-version::${nixpkgs_version}"
101+ - name : Build the "${{ matrix.format }}" format
102+ id : generate
103+ run : |
104+ die() {
105+ rc="$?"
106+ echo "::error file=nixos-generate::$*"
107+ exit "$rc"
108+ }
109+
110+ generate() {
111+ timeout 20m \
112+ nix run . \
113+ -- \
114+ -I nixpkgs=${{ matrix.nixpkgs }} \
115+ "$@"
116+ }
117+
118+ getCheck() {
119+ nix eval --json ".#checks.\"${1?}\"" --apply "(builtins.hasAttr \"${2?}\")"
120+ }
121+
122+ hasCheck() {
123+ has_check=$(getCheck "$@") || die "failed to confirm availablity of check output"
124+ [ "$has_check" = true ]
125+ }
126+
127+ buildCheck() {
128+ nix build ".#checks.\"${1?}\".\"${2?}\""
129+ }
130+
131+ checkOutputs() {
132+ path_var="$1"
133+ shift
134+
135+ path="$1"
136+ shift
137+
138+ test_type="$1"
139+ shift
140+
141+ test "$test_type" "$path" || die "path $path does not exist or is not the expected type"
142+ real=$(readlink -f "$path") || die "unable to resolve path to $path"
143+ store_paths=$(nix-store -q --outputs "$real") || die "unable to get store path of $real"
144+ echo "::set-output name=${path_var}::$(echo "$store_paths" | head -n 1)"
145+ }
146+
147+ format=${{ matrix.format }}
148+ system=${{ matrix.system || 'x86_64-linux' }}
149+ check=${format}-${{ matrix.nixpkgs-name }}
150+ out_link="./result-${format}"
151+
152+ if hasCheck "$system" "$check"; then
153+ out=$(generate -f "$format" --system "$system" -o "$out_link") || die "build exited with status $?"
154+ buildCheck "$system" "$check" || die "flake build exited with status $?"
155+ checkOutputs out "$out" -f
156+ checkOutputs out_link "$out_link" -e
157+ fi
158+ - name : Upload artifact from "${{ matrix.format }}" build
159+ if : ${{ matrix.upload || false }}
160+ uses : actions/upload-artifact@v3
161+ with :
162+ name : nixpkgs-${{ steps.nixpkgs-version.outputs.nixpkgs-version }}.${{ matrix.format }}
163+ path : |
164+ ${{ steps.generate.outputs.out }}
165+ ${{ steps.generate.outputs.out_link }}
166+ if-no-files-found : error
0 commit comments