From 2d6919438b6c99bd469b7748b3b150e588301657 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 17:57:23 -0700 Subject: [PATCH] perf(nix): keep the dependency derivations independent of the source files cargoLock, cargoToml and the vendor directory of the three flakes were taken as "${real}/Cargo.lock" and crane.vendorCargoDeps { src = real; }. A string that names a file inside the filtered source carries the whole source in its context, so every edit of any file in it (a .rs file, a doc) changed the dependency derivation (komorebi-workspace-deps, about 1000 crates) and the dependencies rebuilt on every change: the constant COMMIT_HASH alone did not help once the stubbed workspace source was introduced. The lock and the root manifest are now builtins.path copies of those two files (lockFile, tomlFile) and the vendor directory is made from the lock (vendorCargoDeps { cargoLock = lockFile; }), so the dependencies depend on Cargo.lock, Cargo.toml and the manifests the dummy source keeps, as before. Verified (nix eval of drvPath in a throwaway git copy, three commits: unchanged tree, an edit of crates/komorebi-config, a docs edit): Windows deps and kfde deps are identical in all three (before: both changed with any edit); Windows clippy changes with the source edit and the docs edit (docs are in the Windows source), kfde clippy and vm stacks change with the komorebi-config edit only; the kfm deny attribute still evaluates. The kfm deps and clippy cannot be evaluated on this Linux host (the same change was made there by analogy). Not built: one cold build, then a second commit must be a cache hit. --- flake.nix | 19 +++++++++++++++---- komorebi-for-kde/flake.nix | 18 ++++++++++++++---- komorebi-for-mac/flake.nix | 18 ++++++++++++++---- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/flake.nix b/flake.nix index 6433156d..7b867cbe 100644 --- a/flake.nix +++ b/flake.nix @@ -239,12 +239,23 @@ isReal = member: !(pkgs.lib.hasPrefix "komorebi-for-" member); }; + lockFile = builtins.path { + path = ./Cargo.lock; + name = "Cargo.lock"; + }; + tomlFile = builtins.path { + path = ./Cargo.toml; + name = "Cargo.toml"; + }; + commonArgs = { inherit src version; - cargoLock = "${real}/Cargo.lock"; - cargoToml = "${real}/Cargo.toml"; - # vendored from the filtered source, not the stubbed one: no build is needed to evaluate - cargoVendorDir = craneLib.vendorCargoDeps { src = real; }; + # the lock and the root manifest as files of their own: a path inside the filtered source would put the + # whole filtered source into the context of every derivation, and then an edit of any file + # would change the dependencies + cargoLock = lockFile; + cargoToml = tomlFile; + cargoVendorDir = craneLib.vendorCargoDeps { cargoLock = lockFile; }; strictDeps = true; # applications.json is committed now; this copies the pinned asc input over it, so that the # embedded file is the pinned one even when the committed copy is older diff --git a/komorebi-for-kde/flake.nix b/komorebi-for-kde/flake.nix index ea310c93..13dab98e 100644 --- a/komorebi-for-kde/flake.nix +++ b/komorebi-for-kde/flake.nix @@ -145,14 +145,24 @@ || member == "komorebi-daemon" || builtins.any (crate: member == crate || pkgs.lib.hasPrefix "${crate}/" member) rootCrates; }; + lockFile = builtins.path { + path = repoRoot + "/Cargo.lock"; + name = "Cargo.lock"; + }; + tomlFile = builtins.path { + path = repoRoot + "/Cargo.toml"; + name = "Cargo.toml"; + }; packages = "-p komorebi -p komorebi-linux -p komorebic -p komorebi-client -p komorebi-hotkeys"; workspaceArgs = { pname = "komorebi-workspace"; version = (builtins.fromTOML (builtins.readFile ./komorebi/Cargo.toml)).package.version; - cargoLock = "${real}/Cargo.lock"; - cargoToml = "${real}/Cargo.toml"; - # vendored from the filtered source, not the stubbed one: no build is needed to evaluate - cargoVendorDir = craneLib.vendorCargoDeps { src = real; }; + # the lock and the root manifest as files of their own: a path inside the filtered source + # would put all of it into the context of every derivation, and an edit of any file + # would then change the dependencies + cargoLock = lockFile; + cargoToml = tomlFile; + cargoVendorDir = craneLib.vendorCargoDeps { cargoLock = lockFile; }; }; commonArgs = workspaceArgs // { diff --git a/komorebi-for-mac/flake.nix b/komorebi-for-mac/flake.nix index 4ca2e262..c5009670 100644 --- a/komorebi-for-mac/flake.nix +++ b/komorebi-for-mac/flake.nix @@ -129,14 +129,24 @@ || member == "komorebi-bar" || builtins.any (crate: member == crate || pkgs.lib.hasPrefix "${crate}/" member) rootCrates; }; + lockFile = builtins.path { + path = repoRoot + "/Cargo.lock"; + name = "Cargo.lock"; + }; + tomlFile = builtins.path { + path = repoRoot + "/Cargo.toml"; + name = "Cargo.toml"; + }; packages = "-p komorebi -p komorebi-macos -p komorebic -p komorebi-client -p komorebi-bar"; workspaceArgs = { pname = "komorebi-workspace"; inherit version; - cargoLock = "${real}/Cargo.lock"; - cargoToml = "${real}/Cargo.toml"; - # vendored from the filtered source, not the stubbed one: no build is needed to evaluate - cargoVendorDir = craneLib.vendorCargoDeps { src = real; }; + # the lock and the root manifest as files of their own: a path inside the filtered source + # would put all of it into the context of every derivation, and an edit of any file + # would then change the dependencies + cargoLock = lockFile; + cargoToml = tomlFile; + cargoVendorDir = craneLib.vendorCargoDeps { cargoLock = lockFile; }; }; commonArgs = workspaceArgs // {