diff --git a/lib/build-clan/machineModules/forSystem.nix b/lib/build-clan/machineModules/forSystem.nix deleted file mode 100644 index 8b3601e77..000000000 --- a/lib/build-clan/machineModules/forSystem.nix +++ /dev/null @@ -1,26 +0,0 @@ -{ - pkgs, - pkgsForSystem, - system, -}: -{ - lib, - ... -}: -{ - imports = [ - ( - { - # For vars we need to override the system so we run vars - # generators on the machine that runs `clan vars generate`. If a - # users is using the `pkgsForSystem`, we don't set - # nixpkgs.hostPlatform it would conflict with the `nixpkgs.pkgs` - # option. - nixpkgs.hostPlatform = lib.mkIf (system != null && (pkgsForSystem system) != null) ( - lib.mkForce system - ); - } - // lib.optionalAttrs (pkgs != null) { nixpkgs.pkgs = lib.mkForce pkgs; } - ) - ]; -} diff --git a/lib/build-clan/machineModules/overridePkgs.nix b/lib/build-clan/machineModules/overridePkgs.nix new file mode 100644 index 000000000..2949050e3 --- /dev/null +++ b/lib/build-clan/machineModules/overridePkgs.nix @@ -0,0 +1,17 @@ +{ + pkgs, +}: +{ + lib, + ... +}: +{ + imports = [ + ({ + # For vars we need to ensure that the system so we run vars generate on + # is in sync with the pkgs of the system + nixpkgs.hostPlatform = lib.mkForce pkgs.system; + nixpkgs.pkgs = lib.mkForce pkgs; + }) + ]; +} diff --git a/lib/build-clan/module.nix b/lib/build-clan/module.nix index 9e81556e5..048546aa5 100644 --- a/lib/build-clan/module.nix +++ b/lib/build-clan/module.nix @@ -49,62 +49,8 @@ let moduleSystemConstructor = { # TODO: remove default system once we have a hardware-config mechanism - nixos = - { - system ? null, - name, - pkgs ? null, - }: - nixpkgs.lib.nixosSystem { - modules = - let - innerModule = lib.modules.importApply ./machineModules/forSystem.nix { - inherit - pkgs - pkgsForSystem - system - ; - }; - in - [ - (config.outputs.moduleForMachine.${name} or { }) - - innerModule - { - config.clan.core.module = innerModule; - } - ]; - - specialArgs = { - inherit clan-core; - } // specialArgs; - }; - - darwin = - { - system ? null, - name, - pkgs ? null, - }: - nix-darwin.lib.darwinSystem { - modules = [ - (config.outputs.moduleForMachine.${name} or { }) - # This module depends on the system and pkgs - # It contains optional logic to override 'nixpkgs.pkgs' and 'nixpkgs.hostPlatform' - # and other 'system' related logic - (lib.modules.importApply ./machineModules/forSystem.nix { - inherit - pkgs - pkgsForSystem - system - ; - }) - ]; - - specialArgs = { - inherit clan-core; - } // specialArgs; - }; + nixos = nixpkgs.lib.nixosSystem; + darwin = nix-darwin.lib.darwinSystem; }; allMachines = inventoryClass.machines; # <- inventory.machines <- clan.machines @@ -114,7 +60,13 @@ let ) allMachines; configurations = lib.mapAttrs ( - name: _: moduleSystemConstructor.${machineClasses.${name}} { inherit name; } + name: _: + moduleSystemConstructor.${machineClasses.${name}} { + modules = [ (config.outputs.moduleForMachine.${name} or { }) ]; + specialArgs = { + inherit clan-core; + } // specialArgs; + } ) allMachines; nixosConfigurations = lib.filterAttrs (name: _: machineClasses.${name} == "nixos") configurations; @@ -130,8 +82,15 @@ let lib.mapAttrs ( name: _: moduleSystemConstructor.${machineClasses.${name}} { - inherit name system; - pkgs = pkgsFor.${system}; + modules = [ + (config.outputs.moduleForMachine.${name} or { }) + (lib.modules.importApply ./machineModules/overridePkgs.nix { + pkgs = pkgsFor.${system}; + }) + ]; + specialArgs = { + inherit clan-core; + } // specialArgs; } ) allMachines )