diff --git a/modules/configurations/nixos.nix b/modules/configurations/nixos.nix new file mode 100644 index 0000000..03f5539 --- /dev/null +++ b/modules/configurations/nixos.nix @@ -0,0 +1,28 @@ +{ config, lib, ... }: +let + inherit (lib.trivial) pipe; + inherit (lib.attrsets) filterAttrs mapAttrs'; + inherit (lib.strings) removePrefix hasPrefix; + prefix = "nixos/"; + hosts = config.flake.hostSpec.hosts or { }; + mkSystem = + name: value: + let + hostName = removePrefix prefix name; + in + { + name = hostName; + value = lib.nixosSystem { + modules = [ + value + { networking = { inherit hostName; }; } + ]; + }; + }; +in +{ + flake.nixosConfigurations = pipe hosts [ + (filterAttrs (name: _: hasPrefix prefix name)) + (mapAttrs' mkSystem) + ]; +} diff --git a/modules/hostSpec.nix b/modules/hostSpec.nix new file mode 100644 index 0000000..1b914f3 --- /dev/null +++ b/modules/hostSpec.nix @@ -0,0 +1,3 @@ +{ + flake.hostSpec.hosts = { }; +} diff --git a/modules/hostSpec/default.nix b/modules/hostSpec/default.nix deleted file mode 100644 index 5bb06c6..0000000 --- a/modules/hostSpec/default.nix +++ /dev/null @@ -1,29 +0,0 @@ -{ - lib, - config, - inputs, - ... -}: -let - inherit (builtins) mapAttrs; - inherit (lib) mkOption; - inherit (lib.types) lazyAttrsOf submodule; - cfg = config.hostSpec; - hostOptions = submodule { }; - mkSystem = - hostName: _hostConfig: - inputs.nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ { networking = { inherit hostName; }; } ]; - }; -in -{ - options.hostSpec.hosts = mkOption { - type = lazyAttrsOf hostOptions; - default = { }; - }; - - config = { - flake.nixosConfigurations = mapAttrs mkSystem cfg.hosts; - }; -}