git.iko.soy/typeable/nix-s3-cache-action
on anisimoffnikita/speed-up help sign in
74 lines 2.4 kB history raw
1name: Nix S3 cache
2description: Enable Nix build path recording and upload recorded paths to an S3 binary cache.
4inputs:
5 operation:
6 description: "Operation to run: enable-recorder or upload."
7 required: true
8 aws-role-to-assume:
9 description: AWS IAM role to assume before uploading Nix paths.
10 required: false
11 aws-region:
12 description: AWS region for the Nix cache upload role.
13 required: false
14 default: us-east-1
15 role-duration-seconds:
16 description: AWS role duration for the Nix cache upload role.
17 required: false
18 default: "21600"
19 cache-private-key:
20 description: Private signing key for the Nix binary cache.
21 required: false
22 cache-s3-store-url:
23 description: Nix S3 store URL used as the nix copy destination.
24 required: false
25 cache-query-jobs:
26 description: Number of parallel cache metadata queries (1 disables prefetch; maximum 128).
27 required: false
28 default: "16"
30runs:
31 using: composite
32 steps:
33 - name: Validate operation
34 shell: bash
35 env:
36 OPERATION: ${{ inputs.operation }}
37 run: |
38 set -euo pipefail
40 case "$OPERATION" in
41 enable-recorder|upload) ;;
42 *)
43 echo "Unsupported operation: $OPERATION" >&2
44 echo "Expected one of: enable-recorder, upload" >&2
45 exit 1
46 ;;
47 esac
49 - name: Enable Nix remote cache path recorder
50 if: ${{ inputs.operation == 'enable-recorder' }}
51 shell: bash
52 run: bash "$GITHUB_ACTION_PATH/enable-recorder.sh"
54 - name: Configure AWS credentials for Nix cache upload
55 if: ${{ inputs.operation == 'upload' }}
56 uses: aws-actions/configure-aws-credentials@v6
57 with:
58 role-to-assume: ${{ inputs.aws-role-to-assume }}
59 aws-region: ${{ inputs.aws-region }}
60 role-duration-seconds: ${{ inputs.role-duration-seconds }}
62 - name: Upload built Nix paths to S3 cache
63 if: ${{ inputs.operation == 'upload' }}
64 shell: bash
65 env:
66 NIX_CACHE_PRIVATE_KEY: ${{ inputs.cache-private-key }}
67 NIX_CACHE_S3_STORE_URL: ${{ inputs.cache-s3-store-url }}
68 NIX_CACHE_QUERY_JOBS: ${{ inputs.cache-query-jobs }}
69 run: bash "$GITHUB_ACTION_PATH/upload.sh"
71 - name: Clean up Nix S3 cache files
72 if: ${{ always() && inputs.operation == 'upload' }}
73 shell: bash
74 run: bash "$GITHUB_ACTION_PATH/cleanup.sh"