added defaultGateway

This commit is contained in:
Jakub Kropáček 2024-12-22 15:21:15 +01:00
parent b93cf25dea
commit 141c841c29
2 changed files with 21 additions and 7 deletions

View file

@ -5,6 +5,7 @@
ipv4 = {
address = "192.168.1.160";
prefixLength = 24;
defaultGateway = "192.168.1.1";
};
};
};

View file

@ -18,6 +18,12 @@ let
default = null;
example = if version == 4 then 24 else 64;
};
defaultGateway = lib.mkOption {
type = lib.types.nullOr lib.types.str;
description = "The defautl gateway IPv${version}";
default = null;
example = if version == 4 then "192.168.1.1" else null;
};
};
in
{
@ -34,9 +40,10 @@ in
assertions = [
{
assertion = !(cfg.ipv4.address == null || cfg.ipv4.prefixLength == null);
assertion =
!(cfg.ipv4.address == null || cfg.ipv4.prefixLength == null || cfg.ipv4.defaultGateway == null);
message = ''
You need to provide valid values for both `address` and `prefixLength` in `kropcloud.networking.ipv4`
You need to provide valid values for `address`, `prefixLength` and `defaultGateway` in `kropcloud.networking.ipv4`
when either is set.
'';
}
@ -57,11 +64,17 @@ in
];
};
};
useDHCP = (cfg.ipv4.address == null || cfg.ipv4.prefixLength == null);
nameservers = [
"8.8.8.8"
"1.1.1.1"
];
useDHCP = (
cfg.ipv4.address == null || cfg.ipv4.prefixLength == null || cfg.ipv4.defaultGateway == null
);
defaultGateway = lib.mkIf (cfg.ipv4.defaultGateway != null) { address = cfg.ipv4.defaultGateway; };
nameservers =
lib.mkIf
(cfg.ipv4.address != null || cfg.ipv4.prefixLength != null || cfg.ipv4.defaultGateway != null)
[
"8.8.8.8"
"1.1.1.1"
];
};
};
}