nix-config/modules/dump-dvb/net.nix

59 lines
1.6 KiB
Nix
Raw Normal View History

2022-10-02 21:39:37 +02:00
{ lib, config, checks, utils, ... }:
let
cfg = config.deployment-dvb.net;
in
{
options.deployment-dvb.net = with lib; {
iface.uplink = {
name = mkOption {
2022-10-02 21:39:37 +02:00
type = types.nullOr types.str;
default = null;
};
useDHCP = mkOption {
type = types.bool;
default = true;
};
addr4 = mkOption {
2022-10-02 21:39:37 +02:00
type = types.nullOr types.str;
default = null;
description = "address with prefix in CIDR notation";
};
routes =
with utils.systemdUtils.unitOptions;
with utils.systemdUtils.lib;
with lib;
mkOption {
2022-10-02 21:39:37 +02:00
#type = with types; listOf (submodule routeOptions);
type = types.listOf (types.attrsOf unitOption);
default = [ ];
description = "default gateway";
};
dns = mkOption {
type = types.listOf types.str;
default = [ "9.9.9.9" "1.1.1.1" "8.8.8.8" ];
};
};
};
config = let
upname = "30-${cfg.iface.uplink.name}";
upconf = if cfg.iface.uplink.useDHCP == false then {
2022-10-02 21:39:37 +02:00
matchConfig = { Name = "${cfg.iface.uplink.name}"; };
networkConfig = {
DHCP = "no";
Address = cfg.iface.uplink.addr4;
2022-10-02 21:39:37 +02:00
DNS = cfg.iface.uplink.dns;
};
routes = cfg.iface.uplink.routes;
} else {
2022-10-02 21:39:37 +02:00
matchConfig = { Name = "${cfg.iface.uplink.name}"; };
networkConfig = {
DHCP = "yes";
};
};
in
{
2022-10-02 21:39:37 +02:00
systemd.network.networks."${upname}" = upconf;
};
}