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) // {