48 lines
1.5 KiB
Nix
48 lines
1.5 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
let
|
|
lib' = lib.extend (import ../../../lib.nix);
|
|
toPreserves = lib'.generators.toPreserves { };
|
|
in {
|
|
environment.etc = lib.pipe config.networking.interfaces [
|
|
(lib.attrsets.mapAttrs' (ifname:
|
|
{ ipv4, useDHCP, ... }: {
|
|
name = "syndicate/services/network-interface-${ifname}.pr";
|
|
value.text = let
|
|
|
|
addresses = map ({ address, prefixLength }: [
|
|
ifname
|
|
[ "${address}/${toString prefixLength}" { record = "static"; } ]
|
|
{ record = "configure-interface"; }
|
|
]) ipv4.addresses;
|
|
|
|
routes = map ({ address, options, prefixLength, type, via }: [
|
|
"ipv4"
|
|
"${address}/${toString prefixLength}"
|
|
ifname
|
|
via
|
|
{ record = "configure-route"; }
|
|
]) ipv4.routes;
|
|
|
|
dhcp = lib.optional
|
|
(useDHCP == true || (useDHCP == null && ipv4.addresses == [ ])) [
|
|
ifname
|
|
[{ record = "dhcp"; }]
|
|
{ record = "configure-interface"; }
|
|
];
|
|
|
|
in lib.pipe (addresses ++ routes ++ dhcp) [
|
|
(map toPreserves)
|
|
lib.strings.concatLines
|
|
];
|
|
}))
|
|
] // {
|
|
"syndicate/services/networking.pr".source = pkgs.substituteAll {
|
|
src = ./networking.pr;
|
|
ip = "${pkgs.busybox}/bin/ip";
|
|
interface_monitor =
|
|
"${pkgs.python3Packages.synit-daemons}/bin/interface-monitor";
|
|
udhcpc = "${pkgs.busybox}/bin/udhcpc";
|
|
};
|
|
};
|
|
}
|