# Host construction. Every `configurations.nixos..module` (merged from all # files that set it, see modules/hosts//) becomes # `nixosConfigurations.`, and its toplevel becomes # `checks..nixos-`, so `nix flake check --no-build` evaluates # every host completely (plain `nix flake check` builds them). { config, inputs, lib, ... }: let hosts = config.configurations.nixos; inherit (config.flake) nixosConfigurations; in { options.configurations.nixos = lib.mkOption { description = "NixOS hosts, one deferred module per host."; default = { }; type = lib.types.lazyAttrsOf ( lib.types.submodule { options.module = lib.mkOption { type = lib.types.deferredModule; description = "The host's NixOS module: aspects to import plus host-only values."; }; } ); }; config = { flake.nixosConfigurations = lib.mapAttrs ( name: host: inputs.nixpkgs.lib.nixosSystem { specialArgs = { inherit inputs; }; modules = [ host.module { networking.hostName = lib.mkDefault name; } ]; } ) hosts; perSystem = { system, ... }: let hostsOnSystem = lib.filterAttrs ( name: _: nixosConfigurations.${name}.pkgs.stdenv.hostPlatform.system == system ) hosts; toplevel = name: nixosConfigurations.${name}.config.system.build.toplevel; in { checks = lib.mapAttrs' (name: _: lib.nameValuePair "nixos-${name}" (toplevel name)) hostsOnSystem; }; }; }