From 540a1dfd766e0b2c3b1f9c2e5badb913ea11c3e5 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 27 Aug 2023 23:20:58 +0100 Subject: [PATCH] remove interface.device build-time uses can mostly be replaced with interface.name for runtime uses, switch to $(output ${interface} name) --- examples/rotuer.nix | 4 ++-- modules/bridge/service.nix | 15 ++++++++------- modules/dnsmasq/service.nix | 4 ++-- modules/hostapd/service.nix | 4 ++-- modules/ppp/pppoe.nix | 7 +++++-- pkgs/liminix-tools/networking/default.nix | 10 +++------- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/examples/rotuer.nix b/examples/rotuer.nix index 8d88ede..7e0cbfb 100644 --- a/examples/rotuer.nix +++ b/examples/rotuer.nix @@ -105,7 +105,7 @@ in rec { inherit interface; ranges = [ "10.8.0.10,10.8.0.240" - "::,constructor:${interface.device},ra-stateless" + "::,constructor:$(output ${interface} ifname),ra-stateless" ]; domain = "fake.liminix.org"; }; @@ -188,7 +188,7 @@ in rec { let script = pkgs.callPackage ./acquire-delegated-prefix.nix { }; in longrun { name = "acquire-lan-prefix"; - run = "${script} /run/service-state/dhcp6c.wan ${services.int.device}"; + run = "${script} /run/service-state/dhcp6c.wan $(output ${services.int} ifname)"; dependencies = [ services.dhcp6 ]; }; diff --git a/modules/bridge/service.nix b/modules/bridge/service.nix index 0c8fc1a..28194ae 100644 --- a/modules/bridge/service.nix +++ b/modules/bridge/service.nix @@ -13,14 +13,15 @@ let type = "bridge"; }; addif = member : - oneshot { - name = "add-${member.device}-to-br-${primary.device}"; - up = "${ifwait}/bin/ifwait ${member.device} running && ip link set dev ${member.device} master ${primary.device}"; - down = "ip link set dev ${member.device} nomaster"; + let ifname = "$(output ${member} ifname)"; + in oneshot { + name = "add-${member.name}-to-br-${primary.name}"; + up = "${ifwait}/bin/ifwait ${ifname} running && ip link set dev ${ifname} master $(output ${primary} ifname)"; + down = "ip link set dev ${ifname} nomaster"; dependencies = [ primary member ]; }; -in (bundle { - name = "bridge-${primary.device}-members"; +in bundle { + name = "bridge-${primary.name}-members"; contents = [ primary ] ++ map addif members; -}) // { device = primary.device; } +} diff --git a/modules/dnsmasq/service.nix b/modules/dnsmasq/service.nix index c446de2..02cf476 100644 --- a/modules/dnsmasq/service.nix +++ b/modules/dnsmasq/service.nix @@ -14,7 +14,7 @@ , resolvconf }: let - name = "${interface.device}.dnsmasq"; + name = "${interface.name}.dnsmasq"; inherit (liminix.services) longrun; inherit (lib) concatStringsSep; in @@ -27,7 +27,7 @@ longrun { --user=${user} \ --domain=${domain} \ --group=${group} \ - --interface=${interface.device} \ + --interface=$(output ${interface} ifname) \ ${lib.concatStringsSep " " (builtins.map (r: "--dhcp-range=${r}") ranges)} \ ${lib.concatStringsSep " " (builtins.map (r: "--server=${r}") upstreams)} \ --keep-in-foreground \ diff --git a/modules/hostapd/service.nix b/modules/hostapd/service.nix index 6c02daf..2bd5453 100644 --- a/modules/hostapd/service.nix +++ b/modules/hostapd/service.nix @@ -17,7 +17,7 @@ let # we'll add them as top-level attributes and rename params to # extraParams - name = "${interface.device}.hostapd"; + name = "${interface.name}.hostapd"; defaults = { driver = "nl80211"; logger_syslog = "-1"; @@ -35,5 +35,5 @@ let in longrun { inherit name; dependencies = [ interface ]; - run = "${hostapd}/bin/hostapd -i ${interface.device} -P /run/${name}.pid -S ${conf}"; + run = "${hostapd}/bin/hostapd -i $(output ${interface} ifname) -P /run/${name}.pid -S ${conf}"; } diff --git a/modules/ppp/pppoe.nix b/modules/ppp/pppoe.nix index 9aae986..848ddba 100644 --- a/modules/ppp/pppoe.nix +++ b/modules/ppp/pppoe.nix @@ -9,7 +9,7 @@ { interface, ppp-options }: let inherit (liminix.services) longrun; - name = "${interface.device}.pppoe"; + name = "${interface.name}.pppoe"; ip-up = writeAshScript "ip-up" {} '' . ${serviceFns} (in_outputs ${name} @@ -42,7 +42,10 @@ let in longrun { inherit name; - run = "${ppp}/bin/pppd pty '${pppoe}/bin/pppoe -I ${interface.device}' ${lib.concatStringsSep " " ppp-options'}" ; + run = '' + . ${serviceFns} + ${ppp}/bin/pppd pty "${pppoe}/bin/pppoe -I $(output ${interface} ifname)" ${lib.concatStringsSep " " ppp-options'} + ''; notification-fd = 10; dependencies = [ interface ]; } diff --git a/pkgs/liminix-tools/networking/default.nix b/pkgs/liminix-tools/networking/default.nix index d5cf68d..f0349b4 100644 --- a/pkgs/liminix-tools/networking/default.nix +++ b/pkgs/liminix-tools/networking/default.nix @@ -25,18 +25,14 @@ in { up = lib.concatStringsSep "\n" ups; down = "ip link set down dev ${device}"; dependencies = dependencies ++ lib.optional (primary != null) primary; - } // { - inherit device; }; address = interface: { family, dependencies ? [], prefixLength, address } @ args: let inherit (builtins) toString; in oneshot { dependencies = [ interface ] ++ dependencies; - 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} "; - } // { - inherit (interface) device; + name = "${interface.name}.addr.${address}"; + up = "ip address add ${address}/${toString prefixLength} dev $(output ${interface} ifname)"; + down = "ip address del ${address}/${toString prefixLength} dev $(output ${interface} ifname)"; }; route = { name, target, via, dependencies, dev ? null }: let with_dev = if dev != null then "dev ${dev}" else "";