From 5961368c7d796752fe0b2b0c78204929a480f51d Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sun, 1 Nov 2026 09:31:59 -0800 Subject: [PATCH] perf(nix): the overlays share one nixpkgs and one crane build per system overlays.linux and overlays.forVmTests (which applies the first as well) ran mkPkgs, a new `import nixpkgs` with the rust overlay, and the whole crane mkKomorebiPackages once for every NixOS system an evaluation instantiated: every node of every VM suite and every module scenario, twice each. lib.mkPkgs now hands out one instance per system and the linux module builds the packages of each Linux system once (buildFor). The derivations are the same (drvPath of linux-clippy, vm-kwin and linux-run-kde equal to those before). Measured on a scratch copy of the same change: the stand-alone expression of 4 suites 2.15 -> 1.50 GB, 8 real suites 5.18 -> 4.79 GB, linux-nixos-module-eval 10.3 -> 8.5 GB, plasma guests 9.0 -> 8.7 GB. It does not make the heavy sets cheap: see docs/dev/flake-checks.md. --- nix/lib.nix | 18 ++++++++++++------ nix/linux/flake-module.nix | 11 +++++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/nix/lib.nix b/nix/lib.nix index 3cb46aa1..932d637a 100644 --- a/nix/lib.nix +++ b/nix/lib.nix @@ -56,10 +56,16 @@ rec { }; # nixpkgs with the rust overlay, for a system (x86_64-darwin: see the input nixpkgs-x86_64-darwin) - mkPkgs = - system: - import (if system == "x86_64-darwin" then inputs.nixpkgs-x86_64-darwin else inputs.nixpkgs) { - inherit system; - overlays = [ (import inputs.rust-overlay) ]; - }; + mkPkgs = system: pkgsOf.${system}; + pkgsOf = builtins.listToAttrs ( + map (system: { + name = system; + value = + import (if system == "x86_64-darwin" then inputs.nixpkgs-x86_64-darwin else inputs.nixpkgs) + { + inherit system; + overlays = [ (import inputs.rust-overlay) ]; + }; + }) (windowsSystems ++ linuxSystems ++ macosSystems) + ); } diff --git a/nix/linux/flake-module.nix b/nix/linux/flake-module.nix index 6ee57bcf..58d3876d 100644 --- a/nix/linux/flake-module.nix +++ b/nix/linux/flake-module.nix @@ -12,6 +12,13 @@ let inherit (inputs) nixpkgs; linux = import ./build.nix { inherit inputs self; }; inherit (lib') mkPkgs; + # The packages of each system, built from one nixpkgs instance: the overlays below run once for every + # NixOS system an evaluation instantiates (every node of every VM suite, every module scenario), and + # each run would import nixpkgs and build the crane derivations again. The same derivations, but + # an evaluation that has all the suites holds one copy of them: see docs/dev/flake-checks.md. + buildFor = lib.genAttrs lib'.linuxCheckSystems ( + system: linux.mkKomorebiPackages { pkgs = mkPkgs system; } + ); in { perSystem = @@ -383,7 +390,7 @@ in overlays.linux = final: _: let - build = linux.mkKomorebiPackages { pkgs = mkPkgs final.stdenv.hostPlatform.system; }; + build = buildFor.${final.stdenv.hostPlatform.system}; in { inherit (build) komorebi komorebic; @@ -396,7 +403,7 @@ in overlays.forVmTests = final: prev: let - build = linux.mkKomorebiPackages { pkgs = mkPkgs final.stdenv.hostPlatform.system; }; + build = buildFor.${final.stdenv.hostPlatform.system}; in (self.overlays.linux final prev) // {