diff --git a/modules/configurations/nixos.nix b/modules/configurations/nixos.nix index a251852..16e8ba6 100644 --- a/modules/configurations/nixos.nix +++ b/modules/configurations/nixos.nix @@ -1,44 +1,9 @@ -{ - config, - lib, - inputs, - ... -}: +{ config, ... }: let - inherit (lib.trivial) pipe; - inherit (lib.attrsets) filterAttrs mapAttrs'; - inherit (lib.strings) removePrefix hasPrefix; + inherit (cfg.lib) extractConfigurations; cfg = config.flake; - prefix = "nixos/"; hosts = cfg.hostSpec.hosts or { }; - mkSystem = - name: value: - let - hostName = removePrefix prefix name; - hostConfig = value; - flakeConfig = config; - in - { - name = hostName; - value = lib.nixosSystem { - specialArgs = { - inherit - inputs - hostName - hostConfig - flakeConfig - ; - }; - modules = [ - cfg.profiles.nixos.common - (value.extraCfg or { }) - ] ++ (value.profiles or [ ]); - }; - }; in { - flake.nixosConfigurations = pipe hosts [ - (filterAttrs (name: _: hasPrefix prefix name)) - (mapAttrs' mkSystem) - ]; + flake.nixosConfigurations = extractConfigurations "nixos/" hosts; } diff --git a/modules/lib/default.nix b/modules/lib/default.nix index 710a658..691e3fd 100644 --- a/modules/lib/default.nix +++ b/modules/lib/default.nix @@ -1,9 +1,46 @@ -{ lib, ... }: +{ + lib, + config, + inputs, + ... +}: let - inherit (lib.attrsets) concatMapAttrs; + inherit (lib.trivial) pipe; + inherit (lib.strings) removePrefix hasPrefix; + inherit (lib.attrsets) concatMapAttrs mapAttrs' filterAttrs; + mkSystem = + prefix: name: value: + let + hostName = removePrefix prefix name; + hostConfig = value; + flakeConfig = config; + in + { + name = hostName; + value = lib.nixosSystem { + specialArgs = { + inherit + inputs + hostName + hostConfig + flakeConfig + ; + }; + modules = [ + config.flake.profiles.nixos.common + (value.extraCfg or { }) + ] ++ (value.profiles or [ ]); + }; + }; in { flake.lib = { flattenAttrs = attrset: concatMapAttrs (_: v: v) attrset; + extractConfigurations = + prefix: hosts: + pipe hosts [ + (filterAttrs (name: _: hasPrefix prefix name)) + (mapAttrs' (mkSystem prefix)) + ]; }; }