Replace mapHqHosts and mapPublicHosts with mergeHostsFile

This commit is contained in:
Ehmry - 2022-01-18 23:07:39 +01:00
parent 539cfb8d3b
commit 06f9033bdb
6 changed files with 29 additions and 49 deletions

View File

@ -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.
};

View File

@ -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"
}
'';

View File

@ -68,7 +68,7 @@
c3d2 = {
isInHq = true;
mapHqHosts = true;
mergeHostsFile = true;
hq.interface = "eth0";
hq.statistics.enable = true;
};

View File

@ -35,7 +35,7 @@ in
c3d2 = {
isInHq = true;
mapHqHosts = true;
mergeHostsFile = true;
hq.interface = "eth0";
hq.statistics.enable = true;
};

View File

@ -15,7 +15,7 @@ in
c3d2 = {
k-ot.enable = true;
isInHq = true;
mapHqHosts = true;
mergeHostsFile = true;
hq.interface = eth0;
mountCeph = "/mnt/cephfs";
};

View File

@ -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 <literal>c3d2.hosts</literal> 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);