|
| 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' || '' }} |
0 commit comments