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!" ''; }; } diff --git a/src/modules/integrations/hostctl.nix b/src/modules/integrations/hostctl.nix index 7fa5f4def..4e1bea19e 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" ]; }; }; };