Require Cachix cache in image build #90
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build NixOS Image | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| build-image: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Install Nix | |
| uses: cachix/install-nix-action@v27 | |
| with: | |
| nix_path: nixpkgs=channel:nixos-unstable | |
| - name: Enable public Nix caches | |
| uses: DeterminateSystems/magic-nix-cache-action@v7 | |
| - name: Enable Cachix cache | |
| uses: cachix/cachix-action@v14 | |
| with: | |
| name: clawdinators | |
| authToken: ${{ secrets.CACHIX_AUTH_TOKEN }} | |
| - name: Cache Nix store | |
| uses: nix-community/cache-nix-action@v5 | |
| - name: Free disk space | |
| run: | | |
| sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /usr/local/share/boost /opt/hostedtoolcache | |
| df -h | |
| - name: Install tooling | |
| run: | | |
| nix profile install \ | |
| nixpkgs#nixos-generators \ | |
| nixpkgs#awscli2 | |
| - name: Write agenix image key | |
| env: | |
| CLAWDINATOR_AGE_KEY: ${{ secrets.CLAWDINATOR_AGE_KEY }} | |
| run: | | |
| mkdir -p nix/keys | |
| printf '%s' "${CLAWDINATOR_AGE_KEY}" > nix/keys/clawdinator.agekey | |
| chmod 600 nix/keys/clawdinator.agekey | |
| - name: Fetch age secrets | |
| env: | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| AWS_REGION: ${{ secrets.AWS_REGION }} | |
| S3_BUCKET: ${{ secrets.S3_BUCKET }} | |
| run: | | |
| mkdir -p nix/age-secrets | |
| aws s3 sync "s3://${S3_BUCKET}/age-secrets" nix/age-secrets | |
| for file in \ | |
| nix/age-secrets/clawdinator-github-app.pem.age \ | |
| nix/age-secrets/clawdinator-discord-token.age \ | |
| nix/age-secrets/clawdinator-anthropic-api-key.age | |
| do | |
| test -f "$file" | |
| done | |
| - name: Build image | |
| run: scripts/build-image.sh | |
| - name: Upload image to S3 | |
| env: | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| AWS_REGION: ${{ secrets.AWS_REGION }} | |
| S3_BUCKET: ${{ secrets.S3_BUCKET }} | |
| run: | | |
| key="$(scripts/upload-image.sh)" | |
| echo "S3_KEY=${key}" >> "${GITHUB_ENV}" | |
| - name: Import image into AMI | |
| env: | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| AWS_REGION: ${{ secrets.AWS_REGION }} | |
| S3_BUCKET: ${{ secrets.S3_BUCKET }} | |
| S3_KEY: ${{ env.S3_KEY }} | |
| AMI_DESCRIPTION: clawdinator-nixos | |
| run: | | |
| ami_id="$(scripts/import-image.sh)" | |
| echo "AMI_ID=${ami_id}" >> "${GITHUB_ENV}" |