75 lines
1.6 KiB
Nix
75 lines
1.6 KiB
Nix
{ 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;
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
}
|