main
 1name: "Build and populate cache"
 2on:
 3  pull_request:
 4  push:
 5    branches:
 6      - main
 7      - master
 8  # schedule:
 9  #   # rebuild everyday at 2:51
10  #   # TIP: Choose a random time here so not all repositories are build at once:
11  #   # https://www.random.org/clock-times/?num=1&earliest=01%3A00&latest=08%3A00&interval=5&format=html&rnd=new
12  #   - cron: "51 2 * * *"
13  workflow_dispatch:
14jobs:
15  tests:
16    strategy:
17      matrix:
18        # Set this to notify the global nur package registry that changes are
19        # available.
20        #
21        # The repo name as used in
22        # https://github.com/nix-community/NUR/blob/master/repos.json
23        nurRepo:
24          - <YOUR_REPO_NAME>
25        # Set this to cache your build results in cachix for faster builds
26        # in CI and for everyone who uses your cache.
27        #
28        # Format: Your cachix cache host name without the ".cachix.org" suffix.
29        # Example: mycache (for mycache.cachix.org)
30        #
31        # For this to work, you also need to set the CACHIX_SIGNING_KEY or
32        # CACHIX_AUTH_TOKEN secret in your repository secrets settings in
33        # Github found at
34        # https://github.com/<your_githubname>/nur-packages/settings/secrets
35        cachixName:
36          - <YOUR_CACHIX_NAME>
37        nixPath:
38          - nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/nixos-unstable.tar.gz
39          - nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/heads/nixos-26.05.tar.gz
40    runs-on: nixos-latest
41    steps:
42      - name: Checkout repository
43        uses: actions/checkout@v6
44      - name: Setup Nix
45        run: |
46          echo "access-tokens = github.com=${{ secrets.NIX_GITHUB_TOKEN }}" >> /etc/nix/nix.conf
47          echo "NIX_PATH=${{ matrix.nixPath }}" >> $FORGEJO_ENV
48      - name: Show nixpkgs version
49        run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
50      - name: Setup cachix
51        uses: https://github.com/cachix/cachix-action@v17
52        # Don't replace <YOUR_CACHIX_NAME> here!
53        if: ${{ matrix.cachixName != '<YOUR_CACHIX_NAME>' }}
54        with:
55          name: ${{ matrix.cachixName }}
56          signingKey: "${{ secrets.CACHIX_SIGNING_KEY }}"
57          authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
58      - name: Restore and save Nix store
59        uses: https://github.com/nix-community/cache-nix-action@v7
60        with:
61          primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/flake.lock') }}
62          restore-prefixes-first-match: nix-${{ runner.os }}-
63          gc-max-store-size-linux: 2G
64          purge: true
65          purge-prefixes: nix-${{ runner.os }}-
66          purge-created: 0
67          purge-last-accessed: P1DT12H
68          purge-primary-key: never
69      - name: Check evaluation
70        run: |
71          nix-env -f . -qa \* --meta --xml \
72            --allowed-uris https://static.rust-lang.org \
73            --option restrict-eval true \
74            --option allow-import-from-derivation true \
75            --drv-path --show-trace \
76            -I nixpkgs=$(nix-instantiate --find-file nixpkgs) \
77            -I $PWD
78      - name: Build nix packages
79        run: nix shell -f '<nixpkgs>' nix-build-uncached -c nix-build-uncached ci.nix -A cacheOutputs
80      - name: Trigger NUR update
81        # Don't replace <YOUR_REPO_NAME> here!
82        if: ${{ matrix.nurRepo != '<YOUR_REPO_NAME>' }}
83        run: curl -XPOST "https://nur-update.nix-community.org/update?repo=${{ matrix.nurRepo }}"