git.delta.rocks / fleet / refs/commits / 7bbada6c128c

difftreelog

fix buildUsing should be overridable at host level

ovzwlypkYaroslav Bolyukin2026-05-30parent: #46fb5c0.patch.diff

1 file changed

modifiedmodules/nixos.nixdiffbeforeafterboth
before · modules/nixos.nix
1{2  lib,3  fleetLib,4  inputs,5  self,6  config,7  _fleetFlakeRootConfig,8  ...9}:10let11  inherit (lib.attrsets) mapAttrs;12  inherit (lib.options) mkOption;13  inherit (lib.types)14    deferredModule15    unspecified16    uniq17    str18    ;19  inherit (lib.strings) escapeNixIdentifier;20  inherit (fleetLib.options) mkHostsOption;2122  _file = ./nixos.nix;23in24{25  options = {26    nixos = mkOption {27      description = ''28        Shared nixos configuration module for all hosts.29      '';30      type = deferredModule;31    };32    hosts = mkHostsOption (33      hostArgs:34      let35        hostName = hostArgs.config._module.args.name;36      in37      {38        inherit _file;39        options = {40          name = mkOption {41            description = ''42              Host name (alias)43            '';44            type = uniq str;45            default = hostName;46          };47          nixos = mkOption {48            description = ''49              Nixos configuration for the current host.50            '';51            type = deferredModule;52            apply =53              module:54              let55                modulesPath = "${config.nixpkgs.buildUsing}/nixos/modules";56                baseModules = (import "${modulesPath}/module-list.nix");57                modules = baseModules ++ [58                  (module // { key = "attr<host.nixos>"; })59                  (config.nixos // { key = "attr<fleet.nixos>"; })60                ];61              in62              config.nixpkgs.buildUsing.lib.evalModules {63                class = "nixos";64                prefix = [65                  "fleetConfiguration"66                  "hosts"67                  hostName68                  "nixos"69                ];70                inherit modules;71                specialArgs = {72                  inherit73                    fleetLib74                    inputs75                    self76                    modulesPath77                    baseModules78                    modules79                    ;80                  noUserModules = baseModules;81                  extraModules = [ ];82                };83              };84          };85          nixos_unchecked = mkOption {86            type = unspecified;87          };88        };89        config = {90          nixos =91            let92              inherit (hostArgs.config) system;93            in94            {95              _module.args = {96                nixosHosts = mapAttrs (_: value: value.nixos_unchecked.config) config.hosts;97                hosts = config.hosts;98                host = hostArgs.config;99                fleetConfiguration = config;100101                inputs' = mapAttrs (102                  inputName: input:103                  builtins.addErrorContext104                    "while retrieving system-dependent attributes for input ${escapeNixIdentifier inputName}"105                    (106                      if input._type or null == "flake" then107                        _fleetFlakeRootConfig.perInput system input108                      else109                        "input is not a flake, perhaps flake = false was added to te input declaration?"110                    )111                ) inputs;112                self' = builtins.addErrorContext "while retrieving system-dependent attributes for a flake's own outputs" (113                  _fleetFlakeRootConfig.perInput system self114                );115              };116              nixpkgs.hostPlatform = system;117            };118          nixos_unchecked = hostArgs.config.nixos.extendModules {119            modules = [120              {121                _module.check = false;122              }123            ];124          };125        };126      }127    );128  };129  config.nixos.imports = import ./nixos/module-list.nix;130}
after · modules/nixos.nix
1{2  lib,3  fleetLib,4  inputs,5  self,6  config,7  _fleetFlakeRootConfig,8  ...9}:10let11  inherit (lib.attrsets) mapAttrs;12  inherit (lib.options) mkOption;13  inherit (lib.types)14    deferredModule15    unspecified16    uniq17    str18    ;19  inherit (lib.strings) escapeNixIdentifier;20  inherit (fleetLib.options) mkHostsOption;2122  _file = ./nixos.nix;23in24{25  options = {26    nixos = mkOption {27      description = ''28        Shared nixos configuration module for all hosts.29      '';30      type = deferredModule;31    };32    hosts = mkHostsOption (33      hostArgs:34      let35        hostName = hostArgs.config._module.args.name;36        hostConfig = hostArgs.config;37      in38      {39        inherit _file;40        options = {41          name = mkOption {42            description = ''43              Host name (alias)44            '';45            type = uniq str;46            default = hostName;47          };48          nixos = mkOption {49            description = ''50              Nixos configuration for the current host.51            '';52            type = deferredModule;53            apply =54              module:55              let56                modulesPath = "${hostConfig.nixpkgs.buildUsing}/nixos/modules";57                baseModules = (import "${modulesPath}/module-list.nix");58                modules = baseModules ++ [59                  (module // { key = "attr<host.nixos>"; })60                  (config.nixos // { key = "attr<fleet.nixos>"; })61                ];62                normalEval = hostConfig.nixpkgs.buildUsing.lib.evalModules {63                  class = "nixos";64                  prefix = [65                    "fleetConfiguration"66                    "hosts"67                    hostName68                    "nixos"69                  ];70                  inherit modules;71                  specialArgs = {72                    inherit73                      fleetLib74                      inputs75                      self76                      modulesPath77                      baseModules78                      modules79                      ;80                    noUserModules = baseModules;81                    extraModules = [ ];82                  };83                };84              in85              normalEval;86          };87          nixos_unchecked = mkOption {88            type = unspecified;89          };90        };91        config = {92          nixos =93            let94              inherit (hostArgs.config) system;95            in96            {97              _module.args = {98                nixosHosts = mapAttrs (_: value: value.nixos_unchecked.config) config.hosts;99                hosts = config.hosts;100                host = hostArgs.config;101                fleetConfiguration = config;102103                inputs' = mapAttrs (104                  inputName: input:105                  builtins.addErrorContext106                    "while retrieving system-dependent attributes for input ${escapeNixIdentifier inputName}"107                    (108                      if input._type or null == "flake" then109                        _fleetFlakeRootConfig.perInput system input110                      else111                        "input is not a flake, perhaps flake = false was added to te input declaration?"112                    )113                ) inputs;114                self' = builtins.addErrorContext "while retrieving system-dependent attributes for a flake's own outputs" (115                  _fleetFlakeRootConfig.perInput system self116                );117              };118              nixpkgs.hostPlatform = system;119            };120          nixos_unchecked = hostArgs.config.nixos.extendModules {121            modules = [122              {123                _module.check = false;124              }125            ];126          };127        };128      }129    );130  };131  config.nixos.imports = import ./nixos/module-list.nix;132}