Skip to content

Commit 17c9eb5

Browse files
committed
feat(flake): crane dep-split so releases recompile only the abgen crate
Dependency crates now build in their own derivation keyed on the manifests/lockfile (verified drv-stable across source edits), which is what makes the magic nix cache pay: warm linux legs replay the deps derivation and compile just the abgen crate (132s local vs 13min full). crane is pinned to the v0.23.4 release tag + narHash; audited 2026-07-22: pure-nix lib (~3k lines, no binaries), network access only through fixed-output fetches pinned by our own Cargo.lock checksums. Magic nix cache returns to the linux legs alongside it.
1 parent fb859b0 commit 17c9eb5

4 files changed

Lines changed: 48 additions & 13 deletions

File tree

.github/workflows/release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ jobs:
4949
steps:
5050
- if: matrix.builder == 'nix'
5151
uses: DeterminateSystems/nix-installer-action@ef8a148080ab6020fd15196c2084a2eea5ff2d25 # v22
52+
# pays off only with the crane dep-split in the flake: the deps
53+
# derivation is what gets replayed across releases
54+
- if: matrix.builder == 'nix'
55+
uses: DeterminateSystems/magic-nix-cache-action@908b263ff629f4cc17666315b7fd3ec127c6244d # v14
5256

5357
- name: setup (checkout + toolchains)
5458
run: |

DEVELOPMENT.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,12 @@ the lib sets `#[global_allocator] mimalloc`; any downstream embedding the lib in
184184
## Releasing
185185

186186
The release pipeline (`.github/workflows/release.yml`) is plain shell on GitHub-hosted
187-
runners; the only non-shell steps are Determinate Systems' sha-pinned nix installer on
188-
the linux legs and first-party actions/cache for the mac legs' cargo caches (measured:
189-
warm mac caches cut those legs 2-4x; a nix binary cache moved nothing because the whole
190-
build is one derivation, and its ~9GB would evict the mac caches from the 10GB budget). Every target builds **once**: Linux via
187+
runners; the only non-shell steps are Determinate Systems' sha-pinned nix installer +
188+
Magic Nix Cache on the linux legs and first-party actions/cache for the mac legs' cargo
189+
caches. Measured rationale: warm mac cargo caches cut those legs 2-4x, and the nix cache
190+
only pays because the flake splits dependency compilation into its own crane derivation
191+
(keyed on manifests/lockfile, stable across source edits) - without the split, a store
192+
cache replayed nothing. Every target builds **once**: Linux via
191193
`nix build` from the committed flake.lock (hermetic; reproduce locally with `nix build` -
192194
the archives bundle the loader + libs behind the `abgen` entry script and run on any
193195
Linux, including NixOS); Windows and macOS via the pinned rustup toolchain with

flake.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@
33

44
inputs = {
55
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
# cargo dep-split: dependency crates compile in their own derivation keyed
7+
# on the manifests/lockfile, so releases only recompile the abgen crate.
8+
# Release-tag pin + narHash in flake.lock; audited 2026-07-22 (pure nix
9+
# lib, ~3k lines, only Cargo.lock-checksum-pinned fixed-output fetches).
10+
crane.url = "github:ipetkov/crane/v0.23.4";
611
};
712

8-
outputs = { self, nixpkgs }:
13+
outputs = { self, nixpkgs, crane }:
914
let
1015
systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
1116

1217
perSystem = nixpkgs.lib.genAttrs systems (system:
1318
let
1419
pkgs = import nixpkgs { inherit system; };
20+
craneLib = crane.mkLib pkgs;
1521

1622
nativeDeps = with pkgs; [
1723
cargo
@@ -28,18 +34,22 @@
2834
crateVersion = (builtins.fromTOML (builtins.readFile ./crate/Cargo.toml)).package.version;
2935
gitCommit = if self ? rev then builtins.substring 0 12 self.rev else "unknown";
3036

31-
abgenPkg = pkgs.rustPlatform.buildRustPackage {
37+
commonArgs = {
3238
pname = "abgen";
3339
version = crateVersion;
34-
env.ABGEN_GIT_COMMIT = gitCommit;
3540
src = self;
36-
cargoLock = {
37-
lockFile = ./Cargo.lock;
38-
};
3941
nativeBuildInputs = with pkgs; [ cmake pkg-config git ];
40-
cargoBuildFlags = [ "--bin" "abgen" ];
4142
doCheck = false;
4243
};
44+
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
45+
46+
abgenPkg = craneLib.buildPackage (commonArgs // {
47+
inherit cargoArtifacts;
48+
# final derivation only: on cargoArtifacts this would defeat
49+
# commit-to-commit dep caching
50+
env.ABGEN_GIT_COMMIT = gitCommit;
51+
cargoExtraArgs = "--bin abgen";
52+
});
4353
in
4454
{
4555
devShells.default = pkgs.mkShell {
@@ -53,9 +63,11 @@
5363

5464
packages.default = abgenPkg;
5565

56-
packages.abgen-corpus = abgenPkg.overrideAttrs (old: {
66+
packages.abgen-corpus = craneLib.buildPackage (commonArgs // {
67+
inherit cargoArtifacts;
5768
pname = "abgen-corpus";
58-
cargoBuildFlags = [ "--bin" "abgen-corpus" ];
69+
env.ABGEN_GIT_COMMIT = gitCommit;
70+
cargoExtraArgs = "--bin abgen-corpus";
5971
});
6072

6173
packages.dockerImage =

0 commit comments

Comments
 (0)