From ac87a806a4aa70eddca22587f6cfcb68c8c992e7 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Mon, 24 Apr 2023 21:20:45 +0100 Subject: [PATCH] chore(ci): add cache for Nix workflow (#1210) * chore(ci): Add cache for Nix workflow * align lockfile with other projects * Include both flake.lock and cargo.lock in hash --- .github/workflows/test.yml | 28 +++++++++++++++++++++++++++- flake.lock | 24 ++++++++++++------------ flake.nix | 3 +++ 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 220985d8003..29f58ad519c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,6 +30,32 @@ jobs: nix_path: nixpkgs=channel:nixos-22.11 github_access_token: ${{ secrets.GITHUB_TOKEN }} + - uses: cachix/cachix-action@v12 + with: + name: barretenberg + + - name: Restore nix store cache + id: nix-store-cache + uses: actions/cache@v3 + with: + path: /tmp/nix-cache + key: ${{ runner.os }}-flake-${{ hashFiles('*.lock') }} + + # Based on https://github.com/marigold-dev/deku/blob/b5016f0cf4bf6ac48db9111b70dd7fb49b969dfd/.github/workflows/build.yml#L26 + - name: Copy cache into nix store + if: steps.nix-store-cache.outputs.cache-hit == 'true' + # We don't check the signature because we're the one that created the cache + run: | + for narinfo in /tmp/nix-cache/*.narinfo; do + path=$(head -n 1 "$narinfo" | awk '{print $2}') + nix copy --no-check-sigs --from "file:///tmp/nix-cache" "$path" + done + - name: Run `nix flake check` run: | - nix flake check + nix flake check -L + + - name: Export cache from nix store + if: steps.nix-store-cache.outputs.cache-hit != 'true' + run: | + nix copy --to "file:///tmp/nix-cache?compression=zstd¶llel-compression=true" .#cargo-artifacts diff --git a/flake.lock b/flake.lock index 04dbc188a52..7c01326f86d 100644 --- a/flake.lock +++ b/flake.lock @@ -10,11 +10,11 @@ ] }, "locked": { - "lastModified": 1682019675, - "narHash": "sha256-KZ/VL/u81z2sFTdwfxvUFR+ftqf3+2AA0gR9kkgKxe4=", + "lastModified": 1682345890, + "narHash": "sha256-ZsInK9Iy81MaCugouU3ifa5Vw2GKlJK9MxCU/LF8bIw=", "owner": "AztecProtocol", "repo": "barretenberg", - "rev": "a38e3611590e085e5f25c322757871fb048aa3d7", + "rev": "87aeb375d7b434e0faf47abb79f97753ab760987", "type": "github" }, "original": { @@ -39,11 +39,11 @@ ] }, "locked": { - "lastModified": 1681680516, - "narHash": "sha256-EB8Adaeg4zgcYDJn9sR6UMjN/OHdIiMMK19+3LmmXQY=", + "lastModified": 1681177078, + "narHash": "sha256-ZNIjBDou2GOabcpctiQykEQVkI8BDwk7TyvlWlI4myE=", "owner": "ipetkov", "repo": "crane", - "rev": "54b63c8eae4c50172cb50b612946ff1d2bc1c75c", + "rev": "0c9f468ff00576577d83f5019a66c557ede5acf6", "type": "github" }, "original": { @@ -88,11 +88,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1681932375, - "narHash": "sha256-tSXbYmpnKSSWpzOrs27ie8X3I0yqKA6AuCzCYNtwbCU=", + "lastModified": 1681269223, + "narHash": "sha256-i6OeI2f7qGvmLfD07l1Az5iBL+bFeP0RHixisWtpUGo=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3d302c67ab8647327dba84fbdb443cdbf0e82744", + "rev": "87edbd74246ccdfa64503f334ed86fa04010bab9", "type": "github" }, "original": { @@ -122,11 +122,11 @@ ] }, "locked": { - "lastModified": 1681957132, - "narHash": "sha256-52GaHyeLyyiT0u4OL3uGbo0vsUMKm33Z3zLkPyK/ZRY=", + "lastModified": 1681352318, + "narHash": "sha256-+kwy7bTsuW8GYrRqWRQ8T5hg6duZb5IJiHlKo1J+v9g=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "4771640d46c214d702512a8ece591f582ae507fa", + "rev": "aeaa11c65a5c5cebaa51652353ab3c497b9a7bbf", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 74f19f612f2..fc8e5fa6868 100644 --- a/flake.nix +++ b/flake.nix @@ -165,6 +165,9 @@ packages.default = noir; + # We expose the `cargo-artifacts` derivation so we can cache our cargo dependencies in CI + packages.cargo-artifacts = cargoArtifacts; + # TODO(#1197): Look into installable apps with Nix flakes # apps.default = flake-utils.lib.mkApp { drv = nargo; };