git.delta.rocks / jrsonnet / refs/commits / 69498f520d8e

difftreelog

source

modules/nixos.nix3.2 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) deferredModule unspecified uniq str;14  inherit (lib.strings) escapeNixIdentifier;15  inherit (fleetLib.options) mkHostsOption;1617  _file = ./nixos.nix;18in19{20  options = {21    nixos = mkOption {22      description = ''23        Shared nixos configuration module for all hosts.24      '';25      type = deferredModule;26    };27    hosts = mkHostsOption (hostArgs: let28      hostName = hostArgs.config._module.args.name;29    in {30      inherit _file;31      options = {32        name = mkOption {33          description = ''34            Host name (alias)35          '';36          type = uniq str;37          default = hostName;38        };39        nixos = mkOption {40          description = ''41            Nixos configuration for the current host.42          '';43          type = deferredModule;44          apply =45            module:46            let47              modulesPath = "${config.nixpkgs.buildUsing}/nixos/modules";48            in49            config.nixpkgs.buildUsing.lib.evalModules {50              class = "nixos";51              prefix = [52                "fleetConfiguration"53                "hosts"54                hostName55                "nixos"56              ];57              modules = (import "${modulesPath}/module-list.nix") ++ [58                (module // { key = "attr<host.nixos>"; })59                (config.nixos // { key = "attr<fleet.nixos>"; })60              ];61              specialArgs = {62                inherit63                  fleetLib64                  inputs65                  self66                  modulesPath67                  ;68              };69            };70        };71        nixos_unchecked = mkOption {72          type = unspecified;73        };74      };75      config = {76        nixos =77          let78            inherit (hostArgs.config) system;79          in80          {81            _module.args = {82              nixosHosts = mapAttrs (_: value: value.nixos_unchecked.config) config.hosts;83              hosts = config.hosts;84              host = hostArgs.config;85              fleetConfiguration = config;8687              inputs' = mapAttrs (88                inputName: input:89                builtins.addErrorContext90                  "while retrieving system-dependent attributes for input ${escapeNixIdentifier inputName}"91                  (92                    if input._type or null == "flake" then93                      _fleetFlakeRootConfig.perInput system input94                    else95                      "input is not a flake, perhaps flake = false was added to te input declaration?"96                  )97              ) inputs;98              self' = builtins.addErrorContext "while retrieving system-dependent attributes for a flake's own outputs" (99                _fleetFlakeRootConfig.perInput system self100              );101            };102            nixpkgs.hostPlatform = system;103          };104        nixos_unchecked = hostArgs.config.nixos.extendModules {105          modules = [106            {107              _module.check = false;108            }109          ];110        };111      };112    });113  };114  config.nixos.imports = import ./nixos/module-list.nix;115}