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}