diff --git a/README.md b/README.md index 8ab826ef..1ba88fc0 100644 --- a/README.md +++ b/README.md @@ -187,7 +187,7 @@ in { c3d2 = { isInHq = false; # not in HQ, this is the default. - mapHqHosts = true; # Make entries in /etc/hosts for *.hq internal addresses. + mergeHostsFile = true; # Make entries in /etc/hosts form hosts.nix enableMotd = true; # Set the login shell message to the <<> logo. }; diff --git a/config/c3d2.nix b/config/c3d2.nix index c04e53b4..b9e4ef53 100644 --- a/config/c3d2.nix +++ b/config/c3d2.nix @@ -41,12 +41,12 @@ in { message = "Root passwords not allowed in HQ"; } { - assertion = cfg.hq.enableBinaryCache -> cfg.mapHqHosts; - message = "mapHqHosts must be enabled for enableBinaryCache"; + assertion = cfg.hq.enableBinaryCache -> cfg.mergeHostsFile; + message = "mergeHostsFile must be enabled for enableBinaryCache"; } { - assertion = cfg.hq.enableMpdProxy -> cfg.mapHqHosts; - message = "mapHqHosts must be enabled for enableMpdProxy"; + assertion = cfg.hq.enableMpdProxy -> cfg.mergeHostsFile; + message = "mergeHostsFile must be enabled for enableMpdProxy"; } { assertion = cfg.isInHq -> builtins.hasAttr config.networking.hostName cfg.hosts; @@ -96,29 +96,6 @@ in { networking.domain = mkIfIsInHq "hq.c3d2.de"; - networking.hosts = let - getHost = hostName: builtins.getAttr hostName cfg.hosts; - - hqLocalHosts = with builtins; - let - f = hostName: - let - host = getHost hostName; - ip6 = if host.ip6 != null then - host.ip6 - else - toHqPrivateAddress hostName; - in [{ - name = ip6; - value = [ "${hostName}.hq" hostName ]; - }] ++ lib.optional (host.ip4 != null) { - name = host.ip4; - value = [ "${hostName}.hq" hostName ]; - }; - in listToAttrs (concatLists (map f (attrNames cfg.hosts))); - - in if cfg.mapHqHosts then hqLocalHosts else { }; - systemd.network.networks = if cfg.hq.interface != null && config.networking.useNetworkd then { @@ -230,7 +207,7 @@ in { services.mpd.extraConfig = lib.mkIf cfg.hq.enableMpdProxy '' database { plugin "proxy" - host "mpd-index.hq" + host "mpd-index.c3d2" } ''; diff --git a/hosts/dacbert/default.nix b/hosts/dacbert/default.nix index 7bd890d9..a2138f08 100644 --- a/hosts/dacbert/default.nix +++ b/hosts/dacbert/default.nix @@ -68,7 +68,7 @@ c3d2 = { isInHq = true; - mapHqHosts = true; + mergeHostsFile = true; hq.interface = "eth0"; hq.statistics.enable = true; }; diff --git a/hosts/pulsebert/default.nix b/hosts/pulsebert/default.nix index 70b95454..ca08c8f2 100644 --- a/hosts/pulsebert/default.nix +++ b/hosts/pulsebert/default.nix @@ -35,7 +35,7 @@ in c3d2 = { isInHq = true; - mapHqHosts = true; + mergeHostsFile = true; hq.interface = "eth0"; hq.statistics.enable = true; }; diff --git a/hosts/storage-ng/default.nix b/hosts/storage-ng/default.nix index b2ec44fe..087c2d61 100644 --- a/hosts/storage-ng/default.nix +++ b/hosts/storage-ng/default.nix @@ -15,7 +15,7 @@ in c3d2 = { k-ot.enable = true; isInHq = true; - mapHqHosts = true; + mergeHostsFile = true; hq.interface = eth0; mountCeph = "/mnt/cephfs"; }; diff --git a/modules/c3d2.nix b/modules/c3d2.nix index 5c82b96d..bdf8c112 100644 --- a/modules/c3d2.nix +++ b/modules/c3d2.nix @@ -48,19 +48,11 @@ in defaultText = literalExample "config.c3d2.isInHq"; }; - mapPublicHosts = mkOption { - type = bool; - default = false; - description = '' - Whether to add all external HQ host mappings to /etc/hosts. - ''; - }; - - mapHqHosts = mkOption { + mergeHostsFile = mkOption { type = bool; default = cfg.isInHq; description = '' - Whether to add all internal HQ host mappings to /etc/hosts. + Whether to add c3d2.hosts to /etc/hosts. ''; }; @@ -141,14 +133,16 @@ in users = mkOption { - type = attrsOf (submodule { - options = { - sshKeys = mkOption { - type = listOf types.str; - default = [ ]; + type = attrsOf + (submodule { + options = { + sshKeys = mkOption { + type = with types; + listOf str; + default = [ ]; + }; }; - }; - }); + }); }; }; @@ -161,6 +155,15 @@ in )); in { + networking.hosts = lib.mkIf cfg.mergeHostsFile + (( + lib.attrsets.mapAttrs' (n: v: { name = v.ip4; value = [ "${n}.c3d2" ]; }) + (lib.attrsets.filterAttrs (n: v: v.ip4 != null) cfg.hosts) + ) // ( + lib.attrsets.mapAttrs' (n: v: { name = v.ip6; value = [ "${n}.c3d2" ]; }) + (lib.attrsets.filterAttrs (n: v: v.ip6 != null) cfg.hosts) + )); + programs.nncp.settings = lib.mkIf cfg.mergeNncpSettings cfg.nncp; users.motd = lib.mkIf cfg.enableMotd (builtins.readFile ./motd);