2022-09-26 13:26:54 +02:00
|
|
|
{
|
|
|
|
callPackage
|
|
|
|
, liminix
|
2023-03-01 18:55:52 +01:00
|
|
|
, ifwait
|
2023-02-25 00:49:05 +01:00
|
|
|
, lib
|
2022-09-26 13:26:54 +02:00
|
|
|
}:
|
2023-02-25 00:49:05 +01:00
|
|
|
let
|
|
|
|
inherit (liminix.services) oneshot longrun;
|
|
|
|
inherit (lib) concatStringsSep optional;
|
2022-09-26 13:26:54 +02:00
|
|
|
in {
|
2023-02-25 00:49:05 +01:00
|
|
|
interface = { type, device, primary ? null, dependencies ? [] } @ args:
|
|
|
|
let ups =
|
|
|
|
[]
|
|
|
|
++ optional (type == "bridge")
|
|
|
|
"ip link add name ${device} type bridge"
|
2023-03-01 18:55:52 +01:00
|
|
|
++ ["${ifwait}/bin/ifwait -v ${device} present"]
|
2023-02-25 00:49:05 +01:00
|
|
|
++ ["ip link set up dev ${device}"]
|
|
|
|
++ optional (primary != null)
|
|
|
|
"ip link set dev ${device} master ${primary.device}";
|
|
|
|
in oneshot {
|
|
|
|
name = "${device}.link";
|
|
|
|
up = lib.concatStringsSep "\n" ups;
|
|
|
|
down = "ip link set down dev ${device}";
|
|
|
|
dependencies = dependencies ++ lib.optional (primary != null) primary;
|
|
|
|
} // {
|
|
|
|
inherit device;
|
|
|
|
};
|
2022-09-26 13:26:54 +02:00
|
|
|
address = interface: { family, prefixLength, address } @ args:
|
|
|
|
let inherit (builtins) toString;
|
|
|
|
in oneshot {
|
|
|
|
dependencies = [ interface ];
|
|
|
|
name = "${interface.device}.addr.${address}";
|
|
|
|
up = "ip address add ${address}/${toString prefixLength} dev ${interface.device} ";
|
|
|
|
down = "ip address del ${address}/${toString prefixLength} dev ${interface.device} ";
|
2022-09-28 22:33:18 +02:00
|
|
|
} // {
|
|
|
|
inherit (interface) device;
|
2022-09-26 13:26:54 +02:00
|
|
|
};
|
|
|
|
udhcpc = callPackage ./udhcpc.nix {};
|
|
|
|
odhcpc = interface: { ... } @ args: longrun {
|
|
|
|
name = "${interface.device}.odhcp";
|
|
|
|
run = "odhcpcd ${interface.device}";
|
|
|
|
};
|
|
|
|
pppoe = callPackage ./pppoe.nix {};
|
2022-09-28 22:33:18 +02:00
|
|
|
dnsmasq = callPackage ./dnsmasq.nix {};
|
2022-10-01 19:53:20 +02:00
|
|
|
hostapd = callPackage ./hostapd.nix {};
|
2022-09-26 13:55:10 +02:00
|
|
|
route = { name, target, via, dependencies }:
|
|
|
|
oneshot {
|
|
|
|
inherit name;
|
|
|
|
up = ''
|
|
|
|
ip route add ${target} via ${via}
|
|
|
|
'';
|
|
|
|
down = ''
|
|
|
|
ip route del ${target} via ${via}
|
|
|
|
'';
|
|
|
|
inherit dependencies;
|
|
|
|
};
|
2022-09-26 13:26:54 +02:00
|
|
|
}
|