1
0
vcp-bula-nixfiles/modules/uplink-selector/default.nix

75 lines
1.6 KiB
Nix
Raw Normal View History

2022-07-15 01:16:51 +02:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.clerie.uplink-selector;
in
{
options = {
clerie.uplink-selector = {
enable = mkOption {
type = types.bool;
default = false;
description =
''
Select a default gateway for each interface manually
'';
};
uplinks = mkOption {
default = { };
type = with types; attrsOf (submodule {
options = {
table = mkOption {
type = types.str;
example = "5001";
description = "Route table containing the gateway route of this uplink";
};
};
});
description =
''
Uplink interface name
'';
};
interfaces = mkOption {
default = { };
type = with types; attrsOf (submodule {
options = {
uplink = mkOption {
type = types.nullOr types.str;
example = "uplink-a";
description = "Name of the uplink that should used as a default gateway by this interface";
};
};
});
description =
''
Interface
'';
};
};
};
config = mkIf cfg.enable {
clerie.policyrouting.enable = true;
2022-07-15 01:16:51 +02:00
clerie.policyrouting.rules = [
{ rule = "lookup main suppress_prefixlength 0"; prio = 10000; }
] ++ (mapAttrsToList (iface: ifacecfg: {
rule = "iif ${iface} lookup ${cfg.uplinks.${ifacecfg.uplink}.table}"; prio = 20000;
}) cfg.interfaces);
2022-07-15 01:16:51 +02:00
};
}