diff --git a/modules/flake/checks/port-collector.nix b/modules/flake/checks/port-collector.nix index e8f2183a..222cb303 100644 --- a/modules/flake/checks/port-collector.nix +++ b/modules/flake/checks/port-collector.nix @@ -6,18 +6,14 @@ self, }: let - inherit (lib.attrsets) foldlAttrs; - inherit (lib.lists) filter length; + inherit (lib.attrsets) attrNames; + inherit (lib.lists) filter length groupBy; inherit (lib.strings) concatMapStringsSep concatStringsSep; + services = self.nixosConfigurations.amaterasu.config.garden.services; + # build {"3000" = ["pds" "kittr"]; "0" = [ ... ]; ...} in a single pass. - portsToServices = foldlAttrs ( - acc: name: srv: - let - port = toString (srv.port or 0); - in - acc // { ${port} = (acc.${port} or [ ]) ++ [ name ]; } - ) { } self.nixosConfigurations.amaterasu.config.garden.services; + portsToServices = groupBy (name: toString (services.${name}.port or 0)) (attrNames services); # "0" is the catch all for services that don't bind a port; we will drop it # before checking for collisions. diff --git a/modules/flake/lib/helpers.nix b/modules/flake/lib/helpers.nix index 4182215e..b963b2ac 100644 --- a/modules/flake/lib/helpers.nix +++ b/modules/flake/lib/helpers.nix @@ -122,7 +122,7 @@ let } ``` */ - mkPubs = host: keys: lib.foldl' (acc: key: acc // mkPub host key) { } keys; + mkPubs = host: keys: lib.attrsets.mergeAttrsList (map (mkPub host) keys); in { inherit