git.delta.rocks / jrsonnet / refs/commits / faec7071817b

difftreelog

source

modules/nixos.nix3.0 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;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: {28      inherit _file;29      options = {30        nixos = mkOption {31          description = ''32            Nixos configuration for the current host.33          '';34          type = deferredModule;35          apply =36            module:37            let38              modulesPath = "${config.nixpkgs.buildUsing}/nixos/modules";39            in40            config.nixpkgs.buildUsing.lib.evalModules {41              class = "nixos";42              prefix = [43                "fleetConfiguration"44                "hosts"45                hostArgs.config._module.args.name46                "nixos"47              ];48              modules = (import "${modulesPath}/module-list.nix") ++ [49                (module // { key = "attr<host.nixos>"; })50                (config.nixos // { key = "attr<fleet.nixos>"; })51              ];52              specialArgs = {53                inherit54                  fleetLib55                  inputs56                  self57                  modulesPath58                  ;59              };60            };61        };62        nixos_unchecked = mkOption {63          type = unspecified;64        };65      };66      config = {67        nixos =68          let69            inherit (hostArgs.config) system;70          in71          {72            _module.args = {73              nixosHosts = mapAttrs (_: value: value.nixos_unchecked.config) config.hosts;74              hosts = config.hosts;75              host = hostArgs.config;76              fleetConfiguration = config;7778              inputs' = mapAttrs (79                inputName: input:80                builtins.addErrorContext81                  "while retrieving system-dependent attributes for input ${escapeNixIdentifier inputName}"82                  (83                    if input._type or null == "flake" then84                      _fleetFlakeRootConfig.perInput system input85                    else86                      "input is not a flake, perhaps flake = false was added to te input declaration?"87                  )88              ) inputs;89              self' = builtins.addErrorContext "while retrieving system-dependent attributes for a flake's own outputs" (90                _fleetFlakeRootConfig.perInput system self91              );92            };93            nixpkgs.hostPlatform = system;94          };95        nixos_unchecked = hostArgs.config.nixos.extendModules {96          modules = [97            {98              _module.check = false;99            }100          ];101        };102      };103    });104  };105  config.nixos.imports = import ./nixos/module-list.nix;106}