From e8fd5d4389104e73a79a13708d4f9e36d984e10b Mon Sep 17 00:00:00 2001 From: Ricardo Machado Date: Thu, 2 Nov 2023 01:03:48 +0100 Subject: [PATCH 1/3] fix: adds support for multiple IP configurations for one hostname in `hostctl.nix` --- src/modules/integrations/hostctl.nix | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/modules/integrations/hostctl.nix b/src/modules/integrations/hostctl.nix index 7fa5f4def..af3a52ab2 100644 --- a/src/modules/integrations/hostctl.nix +++ b/src/modules/integrations/hostctl.nix @@ -1,8 +1,11 @@ { pkgs, lib, config, ... }: let + reducerFn = (prev: curr: prev ++ (if builtins.typeOf curr.ip == "string" then [curr] else builtins.map (ip: { inherit ip; hostname = curr.hostname; }) curr.ip)); + reducer = lib.lists.foldl reducerFn []; entries = lib.mapAttrsToList (hostname: ip: { inherit hostname ip; }) config.hosts; - entriesByIp = builtins.groupBy ({ ip, ... }: ip) entries; + separateEntriesWithIps = reducer entries; + entriesByIp = builtins.groupBy ({ ip, ... }: ip) separateEntriesWithIps; hostnamesByIp = builtins.mapAttrs (hostname: entries: builtins.map ({ hostname, ... }: hostname) entries) entriesByIp; lines = lib.mapAttrsToList (ip: hostnames: "${ip} ${lib.concatStringsSep " " hostnames}") hostnamesByIp; hostContent = lib.concatStringsSep "\n" lines; @@ -21,11 +24,12 @@ in }; hosts = lib.mkOption { - type = lib.types.attrsOf lib.types.str; + type = lib.types.attrsOf (lib.types.either lib.types.str (lib.types.listOf lib.types.str)); default = { }; description = "List of hosts entries."; example = { "example.com" = "127.0.0.1"; + "another-example.com" = [ "::1" "127.0.0.1" ]; }; }; }; From d5fd391bbe4d9aea78b6971fec04436c9acf8544 Mon Sep 17 00:00:00 2001 From: Ricardo Machado Date: Thu, 2 Nov 2023 14:05:33 +0100 Subject: [PATCH 2/3] chore: adds examples on `examples/mkcert/devenv.nix` --- examples/mkcert/devenv.nix | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/mkcert/devenv.nix b/examples/mkcert/devenv.nix index 67e3e86d4..b9b60ccf8 100644 --- a/examples/mkcert/devenv.nix +++ b/examples/mkcert/devenv.nix @@ -3,10 +3,12 @@ { certificates = [ "example.com" + "another-example.com" ]; hosts = { "example.com" = "127.0.0.1"; + "another-example.com" = [ "127.0.0.1" "::1" ]; }; services.caddy.enable = true; @@ -14,7 +16,14 @@ extraConfig = '' tls ${config.env.DEVENV_STATE}/mkcert/example.com.pem ${config.env.DEVENV_STATE}/mkcert/example.com-key.pem - respond "Hello, world!" + respond "Hello, world from example.com!" + ''; + }; + services.caddy.virtualHosts."another-example.com" = { + extraConfig = '' + tls ${config.env.DEVENV_STATE}/mkcert/another-example.com.pem ${config.env.DEVENV_STATE}/mkcert/another-example.com-key.pem + + respond "Hello, world from another-example.com!" ''; }; } From 853bb50b8f7ba0830ec9265ae604fb87de43bddf Mon Sep 17 00:00:00 2001 From: Ricardo Machado Date: Thu, 2 Nov 2023 16:11:47 +0100 Subject: [PATCH 3/3] fix: fixed formatting issues --- src/modules/integrations/hostctl.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/integrations/hostctl.nix b/src/modules/integrations/hostctl.nix index af3a52ab2..4e1bea19e 100644 --- a/src/modules/integrations/hostctl.nix +++ b/src/modules/integrations/hostctl.nix @@ -1,8 +1,8 @@ { pkgs, lib, config, ... }: let - reducerFn = (prev: curr: prev ++ (if builtins.typeOf curr.ip == "string" then [curr] else builtins.map (ip: { inherit ip; hostname = curr.hostname; }) curr.ip)); - reducer = lib.lists.foldl reducerFn []; + reducerFn = (prev: curr: prev ++ (if builtins.typeOf curr.ip == "string" then [ curr ] else builtins.map (ip: { inherit ip; hostname = curr.hostname; }) curr.ip)); + reducer = lib.lists.foldl reducerFn [ ]; entries = lib.mapAttrsToList (hostname: ip: { inherit hostname ip; }) config.hosts; separateEntriesWithIps = reducer entries; entriesByIp = builtins.groupBy ({ ip, ... }: ip) separateEntriesWithIps;