mirror of
https://git.sr.ht/~magic_rb/dotfiles
synced 2024-12-11 09:22:02 +01:00
6ad7df336e
Signed-off-by: magic_rb <magic_rb@redalder.org>
52 lines
1.4 KiB
Nix
52 lines
1.4 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}: {
|
|
systemd.services.ifstate-patch-pre = {
|
|
partOf = ["ifstate.service"];
|
|
wantedBy = ["ifstate.service"];
|
|
before = ["ifstate.service"];
|
|
|
|
path = [
|
|
pkgs.jq
|
|
pkgs.iproute2
|
|
];
|
|
|
|
script = ''
|
|
# create all network namespaces beforehand
|
|
${lib.concatMapStringsSep "\n" (
|
|
name: ''
|
|
if ! [ -f "/var/run/netns/${name}" ] ; then
|
|
ip netns add ${name}
|
|
fi
|
|
''
|
|
) (lib.attrNames config.services.ifstate.settings.namespaces)}
|
|
|
|
# move all dsa interfaces into their respective namespaces
|
|
${lib.concatMapStringsSep "\n" (
|
|
interface: ''
|
|
ifname="$(ip -json link | jq -r '.[] | select(.address == "${interface.link.permaddr}") | .ifname')"
|
|
|
|
if ! [ -z "$ifname" ] ; then
|
|
ip link set "$ifname" netns ${interface.namespace}
|
|
fi
|
|
''
|
|
) (lib.pipe config.services.ifstate.settings.namespaces [
|
|
(lib.mapAttrs (_: settings: settings.interfaces or []))
|
|
lib.attrsToList
|
|
(lib.concatMap ({
|
|
name,
|
|
value,
|
|
}:
|
|
lib.pipe value [
|
|
(lib.filter (interface: interface.link.kind == "dsa" && interface.link ? "permaddr"))
|
|
(map (interface: interface // {namespace = name;}))
|
|
]))
|
|
])}
|
|
'';
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
};
|
|
}
|