Skip to content

Commit 0ac22e1

Browse files
committed
ci(gh-actions): Extract reusable install-nix action
1 parent a68c506 commit 0ac22e1

File tree

4 files changed

+58
-30
lines changed

4 files changed

+58
-30
lines changed

.github/generate-matrix/action.yml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,12 @@ runs:
3636
using: "composite"
3737
steps:
3838
- name: Install Nix
39-
uses: cachix/install-nix-action@v27
40-
if: ${{ runner.environment == 'github-hosted' }}
39+
uses: metacraft-labs/nixos-modules/.github/install-nix@feat/CD
4140
with:
42-
extra_nix_config: |
43-
accept-flake-config = true
44-
substituters = https://cache.nixos.org ${{inputs.substituters}}
45-
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= ${{inputs.trusted-public-keys}}
46-
netrc-file = /home/runner/.config/nix/netrc
47-
- name: Configure Nix
48-
shell: bash
49-
run: |
50-
mkdir -p /home/runner/.config/nix
51-
echo "machine ${{inputs.cachix-cache}}.cachix.org password ${{inputs.cachix-auth-token}}" >> /home/runner/.config/nix/netrc
41+
cachix-cache: ${{ inputs.cachix-cache }}
42+
cachix-auth-token: ${{ inputs.cachix-auth-token }}
43+
trusted-public-keys: ${{ inputs.trusted-public-keys }}
44+
substituters: ${{ inputs.substituters }}
5245

5346
- name: Generate CI Matrix
5447
id: generate-matrix

.github/install-nix/action.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Install Nix
2+
description: Installs Nix and configures substituters and trusted public keys
3+
4+
inputs:
5+
cachix-cache:
6+
description: The name of the cachix cache to use
7+
required: true
8+
cachix-auth-token:
9+
description: Cachix auth token
10+
required: true
11+
trusted-public-keys:
12+
description: Trusted public keys
13+
required: false
14+
default: ''
15+
substituters:
16+
description: Substituters
17+
required: false
18+
default: ''
19+
20+
runs:
21+
using: "composite"
22+
steps:
23+
- name: Install Nix
24+
uses: cachix/install-nix-action@v27
25+
if: ${{ runner.environment == 'github-hosted' }}
26+
with:
27+
extra_nix_config: |
28+
accept-flake-config = true
29+
allow-import-from-derivation = true
30+
substituters = https://cache.nixos.org ${{inputs.substituters}}
31+
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= ${{inputs.trusted-public-keys}}
32+
netrc-file = $HOME/.config/nix/netrc
33+
34+
- name: Configure Nix
35+
if: ${{ runner.environment == 'github-hosted' }}
36+
shell: bash
37+
run: |
38+
mkdir -p $HOME/.config/nix
39+
{
40+
echo "machine ${{inputs.cachix-cache}}.cachix.org password ${{inputs.cachix-auth-token}}"
41+
} >> $HOME/.config/nix/netrc

.github/print-matrix/action.yml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,12 @@ runs:
3737
using: "composite"
3838
steps:
3939
- name: Install Nix
40-
uses: cachix/install-nix-action@v27
41-
if: ${{ runner.environment == 'github-hosted' }}
40+
uses: metacraft-labs/nixos-modules/.github/install-nix@feat/CD
4241
with:
43-
extra_nix_config: |
44-
accept-flake-config = true
45-
substituters = https://cache.nixos.org ${{inputs.substituters}}
46-
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= ${{inputs.trusted-public-keys}}
47-
netrc-file = /home/runner/.config/nix/netrc
48-
nix-installer-tag: v0.15.1
49-
- name: Configure Nix
50-
shell: bash
51-
run: |
52-
mkdir -p /home/runner/.config/nix
53-
echo "machine ${{inputs.cachix-cache}}.cachix.org password ${{inputs.cachix-auth-token}}" >> /home/runner/.config/nix/netrc
42+
cachix-cache: ${{ inputs.CACHIX_CACHE }}
43+
cachix-auth-token: ${{ inputs.CACHIX_AUTH_TOKEN }}
44+
trusted-public-keys: ${{ inputs.TRUSTED_PUBLIC_KEYS }}
45+
substituters: ${{ inputs.SUBSTITUTERS }}
5446

5547
- name: Print CI Matrix
5648
id: print-matrix

.github/workflows/ci.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ jobs:
3838
name: Generate Matrix of Matrices
3939
runs-on: ubuntu-latest
4040
steps:
41-
- uses: actions/checkout@v4
42-
4341
- name: Install Nix
44-
uses: cachix/install-nix-action@v27
45-
if: ${{ runner.environment == 'github-hosted' }}
42+
uses: metacraft-labs/nixos-modules/.github/install-nix@feat/CD
4643
with:
47-
extra_nix_config: accept-flake-config = true
44+
cachix-cache: ${{ vars.CACHIX_CACHE }}
45+
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
46+
trusted-public-keys: ${{ vars.TRUSTED_PUBLIC_KEYS }}
47+
substituters: ${{ vars.SUBSTITUTERS }}
48+
49+
- uses: actions/checkout@v4
4850

4951
- name: Generate Matrix for Matrix
5052
id: generate-matrix

0 commit comments

Comments
 (0)