git.delta.rocks / fleet / refs/commits / 2a48f3899c28

difftreelog

source

modules/nixos.nix3.7 KiBsourcehistory
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}