Skip to content

Commit b6ad602

Browse files
committed
feat: add ephemeral Nix install action for GitHub runners
1 parent 38f7257 commit b6ad602

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: 'Install Nix on ephemeral runners'
2+
description: 'Installs Nix and sets up AWS credentials for pushing to Nix binary cache'
3+
inputs:
4+
push-to-cache:
5+
description: 'Whether to push build outputs to the Nix binary cache'
6+
required: false
7+
default: 'true'
8+
runs:
9+
using: 'composite'
10+
steps:
11+
- name: aws-creds
12+
uses: aws-actions/configure-aws-credentials@v4
13+
if: ${{ inputs.push-to-cache == 'true' }}
14+
with:
15+
role-to-assume: ${{ secrets.DEV_AWS_ROLE }}
16+
aws-region: "us-east-1"
17+
output-credentials: true
18+
role-duration-seconds: 18000
19+
- name: Setup AWS credentials for Nix
20+
if: ${{ inputs.push-to-cache == 'true' }}
21+
run: |
22+
sudo -H aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
23+
sudo -H aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
24+
sudo -H aws configure set aws_session_token $AWS_SESSION_TOKEN
25+
sudo mkdir -p /etc/nix
26+
sudo -E python -c "import os; file = open('/etc/nix/nix-secret-key', 'w'); file.write(os.environ['NIX_SIGN_SECRET_KEY']); file.close()"
27+
cat << 'EOF' | sudo tee /etc/nix/upload-to-cache.sh > /dev/null
28+
#!/usr/bin/env bash
29+
set -euf
30+
export IFS=' '
31+
/nix/var/nix/profiles/default/bin/nix copy --to 's3://nix-postgres-artifacts?secret-key=/etc/nix/nix-secret-key' $OUT_PATHS
32+
EOF
33+
sudo chmod +x /etc/nix/upload-to-cache.sh
34+
env:
35+
NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }}
36+
- name: Install nix
37+
uses: cachix/install-nix-action@v31
38+
with:
39+
install_url: https://releases.nixos.org/nix/nix-2.31.2/install
40+
extra_nix_config: |
41+
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
42+
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
43+
${{ inputs.push-to-cache == 'true' && 'post-build-hook = /etc/nix/upload-to-cache.sh' || '' }}

.github/workflows/nix-build.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@ jobs:
2323
- name: Checkout Repo
2424
uses: actions/checkout@v4
2525
- name: Install nix
26-
uses: cachix/install-nix-action@v31
27-
with:
28-
install_url: https://releases.nixos.org/nix/nix-2.31.2/install
26+
uses: ./.github/actions/nix-install-ephemeral
2927
- id: set-matrix
3028
name: Generate Nix Matrix
3129
run: |
3230
set -Eeu
33-
echo matrix="$(nix shell nixpkgs/405fc615369e0ea1b9c284c107ca4c3e1bc15774#nix-eval-jobs --command scripts/github-matrix.py checks legacyPackages)" >> "$GITHUB_OUTPUT"
31+
echo matrix="$(nix shell github:nix-community/nix-eval-jobs --command scripts/github-matrix.py checks legacyPackages)" >> "$GITHUB_OUTPUT"
3432
3533
nix-build-aarch64-linux:
3634
name: ${{ matrix.name }} (aarch64-linux)
@@ -97,7 +95,7 @@ jobs:
9795
run-tests:
9896
needs: [nix-build-aarch64-linux, nix-build-aarch64-darwin] #, nix-build-x86_64-linux]
9997
if: |
100-
!cancelled() &&
98+
!cancelled() &&
10199
(needs.nix-build-aarch64-linux.result == 'skipped' || needs.nix-build-aarch64-linux.result == 'success') &&
102100
(needs.nix-build-aarch64-darwin.result == 'skipped' || needs.nix-build-aarch64-darwin.result == 'success')
103101
uses: ./.github/workflows/test.yml

0 commit comments

Comments
 (0)