From cb3ec28d12a48f1942e6d6ab2ee6c3a4ba06741e Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Wed, 11 Nov 2026 00:29:49 -0600 Subject: [PATCH] pkgs/atlas-search: split dependency compilation out of the package build with crane (code#8392) --- pkgs/atlas-search/default.nix | 115 +++++++++++++++++++++++++++++----- pkgs/atlas-search/flake.lock | 17 +++++ pkgs/atlas-search/flake.nix | 11 +++- 3 files changed, 125 insertions(+), 18 deletions(-) diff --git a/pkgs/atlas-search/default.nix b/pkgs/atlas-search/default.nix index 02e67e65ea..e8538fa16b 100644 --- a/pkgs/atlas-search/default.nix +++ b/pkgs/atlas-search/default.nix @@ -18,11 +18,21 @@ # part of this package's runtime closure (verify: # `nix-store -qR `), and the installCheck proves the load # works with no ATLAS_ORT_LIB set (fixtures/smoke_check.py). +# +# Dependency compilation is split from the package build when a +# craneLib is supplied (the package flake passes one): crane's +# buildDepsOnly compiles every registry dependency as its OWN +# derivation keyed only on Cargo.toml/Cargo.lock, so a change to +# workspace sources rebuilds just the workspace crates instead of +# the whole dependency tree (code#8392). Callers that do not pass +# craneLib (home/common) keep the monolithic buildRustPackage +# build below — same sources, same checks, no split. { lib, rustPlatform, callPackage, python3, + craneLib ? null, }: let @@ -32,24 +42,12 @@ let # that release; the library baked in below must be the same one # (code#6765, Drew's ruling 2026-11-08). onnxruntime = callPackage ./onnxruntime { }; -in - -rustPlatform.buildRustPackage { - pname = "atlas-search"; - version = "0.1.0"; - src = ./.; - - cargoLock.lockFile = ./Cargo.lock; - env.ATLAS_SEARCH_ORT_LIB_DEFAULT = "${onnxruntime}/lib/libonnxruntime.so"; + ortLibEnv = { + ATLAS_SEARCH_ORT_LIB_DEFAULT = "${onnxruntime}/lib/libonnxruntime.so"; + }; - nativeInstallCheckInputs = [ python3 ]; - doInstallCheck = true; - # The smoke: fixture FTS-only + embedded queries byte-compared - # with the recorded Python envelopes, plus the closure-ONNX - # load probe (an empty model dir must fail at the tokenizer, - # after runtime init — never at runtime resolution). - installCheckPhase = '' + installCheck = '' runHook preInstallCheck python3 ${./fixtures}/smoke_check.py $out/bin/atlas-search runHook postInstallCheck @@ -63,4 +61,87 @@ rustPlatform.buildRustPackage { ]; mainProgram = "atlas-search"; }; -} +in +if craneLib != null then + let + # Two source tiers. The dependency layer sees only what can + # change dependency compilation: the manifests, the lockfile, + # the crate sources and schema/ (atlas-core include_str!s the + # stage DDL from schema/). The package layer additionally sees + # fixtures/: the test suite reads fixtures by relative path + # (atlas-core's eval tests open ../../fixtures/eval-smoke.json), + # so the check phase needs them in the tree — but a fixture edit + # must not rebuild the dependency layer, so they stay out of + # the deps tier. eval/, worker/ and the in-tree target/ are in + # neither (the installCheck references ./fixtures as its own + # store path, above). + depsSrc = lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.unions [ + ./Cargo.toml + ./Cargo.lock + ./crates + ./schema + ]; + }; + + packageSrc = lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.unions [ + ./Cargo.toml + ./Cargo.lock + ./crates + ./schema + ./fixtures + ]; + }; + + commonArgs = { + strictDeps = true; + pname = "atlas-search"; + version = "0.1.0"; + env = ortLibEnv; + }; + + # The dependency layer: every registry crate compiled once, + # keyed on the deps tier above only. A workspace-source or + # fixture change leaves this derivation — and its store path — + # untouched. + cargoArtifacts = craneLib.buildDepsOnly (commonArgs // { src = depsSrc; }); + in + craneLib.buildPackage ( + commonArgs + // { + src = packageSrc; + inherit cargoArtifacts meta; + + # Preserve the buildRustPackage behaviour this package had: + # the test suite runs in the check phase, and the smoke + # installCheck runs against the installed tree. + doCheck = true; + + nativeInstallCheckInputs = [ python3 ]; + doInstallCheck = true; + installCheckPhase = installCheck; + } + ) +else + rustPlatform.buildRustPackage { + pname = "atlas-search"; + version = "0.1.0"; + src = ./.; + + cargoLock.lockFile = ./Cargo.lock; + + env = ortLibEnv; + + nativeInstallCheckInputs = [ python3 ]; + doInstallCheck = true; + # The smoke: fixture FTS-only + embedded queries byte-compared + # with the recorded Python envelopes, plus the closure-ONNX + # load probe (an empty model dir must fail at the tokenizer, + # after runtime init — never at runtime resolution). + installCheckPhase = installCheck; + + inherit meta; + } diff --git a/pkgs/atlas-search/flake.lock b/pkgs/atlas-search/flake.lock index 9b37927447..b02414eb75 100644 --- a/pkgs/atlas-search/flake.lock +++ b/pkgs/atlas-search/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "crane": { + "locked": { + "lastModified": 1766774972, + "narHash": "sha256-8qxEFpj4dVmIuPn9j9z6NTbU+hrcGjBOvaxTzre5HmM=", + "owner": "ipetkov", + "repo": "crane", + "rev": "01bc1d404a51a0a07e9d8759cd50a7903e218c82", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "rev": "01bc1d404a51a0a07e9d8759cd50a7903e218c82", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": [ @@ -38,6 +54,7 @@ }, "root": { "inputs": { + "crane": "crane", "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", "rust-overlay": "rust-overlay", diff --git a/pkgs/atlas-search/flake.nix b/pkgs/atlas-search/flake.nix index e00ed08fd8..45ec10884c 100644 --- a/pkgs/atlas-search/flake.nix +++ b/pkgs/atlas-search/flake.nix @@ -15,6 +15,13 @@ url = "github:numtide/flake-utils"; inputs.systems.follows = "systems"; }; + # Crane: splits dependency compilation out of the package build + # so workspace-source changes reuse the dependency layer + # (code#8392). Pinned to the rev the code repo's root lock + # already carries. + crane = { + url = "github:ipetkov/crane/01bc1d404a51a0a07e9d8759cd50a7903e218c82"; + }; }; outputs = @@ -23,6 +30,7 @@ nixpkgs, rust-overlay, flake-utils, + crane, ... }: flake-utils.lib.eachDefaultSystem ( @@ -41,7 +49,8 @@ cargo = rustToolchain; rustc = rustToolchain; }; - atlas-search = pkgs.callPackage ./default.nix { inherit rustPlatform; }; + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; + atlas-search = pkgs.callPackage ./default.nix { inherit rustPlatform craneLib; }; in { packages = {