Skip to content

Commit f535a5c

Browse files
committed
improve cache strategy
1 parent e5d11f7 commit f535a5c

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

.github/workflows/ci.yml

+28
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,35 @@ env:
1818
keep-outputs = true
1919
2020
jobs:
21+
cache:
22+
name: Cache nix store
23+
runs-on: ubuntu-24.04
24+
permissions:
25+
actions: write
26+
contents: read
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
ref: ${{ github.event.pull_request.head.sha }}
31+
- uses: nixbuild/nix-quick-install-action@v30
32+
with:
33+
nix_conf: ${{ env.nix_conf }}
34+
- name: Restore and save Nix store
35+
uses: nix-community/cache-nix-action@v6
36+
with:
37+
primary-key: build-${{ runner.os }}-${{ hashFiles('Cargo.lock', '**/Cargo.toml', 'flake.nix', 'flake.lock', 'rust-toolchain.toml') }}
38+
purge: true
39+
purge-prefixes: build-${{ runner.os }}-
40+
purge-created: 0
41+
purge-primary-key: never
42+
gc-max-store-size: 5G
43+
- name: Save flake attributes from garbage collection
44+
run: nix profile install .#saveFromGC
45+
2146
check:
2247
name: Run checks
2348
runs-on: ubuntu-24.04
49+
needs: cache
2450
permissions:
2551
actions: write
2652
contents: read
@@ -46,6 +72,7 @@ jobs:
4672
build:
4773
name: Build
4874
runs-on: ubuntu-24.04
75+
needs: cache
4976
permissions:
5077
actions: write
5178
contents: read
@@ -71,6 +98,7 @@ jobs:
7198
test:
7299
name: Run Tests
73100
runs-on: ubuntu-24.04
101+
needs: cache
74102
permissions:
75103
actions: write
76104
contents: read

flake.lock

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+17-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
inputs = {
55
nixpkgs.url = "github:nixos/nixpkgs/release-24.11";
66

7+
# Helper utility for keeping certain paths from garbage collection in CI
8+
cache-nix-action = {
9+
url = "github:nix-community/cache-nix-action";
10+
flake = false;
11+
};
12+
713
# Rust builder
814
crane.url = "github:ipetkov/crane";
915

@@ -19,11 +25,12 @@
1925

2026
outputs = {
2127
self,
28+
cache-nix-action,
2229
crane,
2330
nixpkgs,
2431
fenix,
2532
flake-utils,
26-
}:
33+
} @ inputs:
2734
flake-utils.lib.eachDefaultSystem (system: let
2835
pkgs = import nixpkgs {inherit system;};
2936
toolchain = fenix.packages.${system}.fromToolchainFile {
@@ -58,6 +65,12 @@
5865
# Supporting tools
5966
mcphost = pkgs.callPackage ./nix/mcphost.nix {};
6067
mcp-server-tools = pkgs.callPackage ./nix/mcp-server-tools {};
68+
69+
# CI options
70+
garbageCollector = import "${inputs.cache-nix-action}/saveFromGC.nix" {
71+
inherit pkgs inputs;
72+
derivations = [cargoArtifacts toolchain];
73+
};
6174
in {
6275
devShells.default = pkgs.mkShell {
6376
nativeBuildInputs = with pkgs; [pkg-config];
@@ -127,6 +140,9 @@
127140
cargoExtraArgs = "-p mcp-apollo-server";
128141
src = fileSetForCrate ./crates/mcp-apollo-server;
129142
});
143+
144+
# CI related packages
145+
inherit (garbageCollector) saveFromGC;
130146
};
131147
});
132148
}

0 commit comments

Comments
 (0)