From 26d2812aa4985d9b3f181ae678a5b2cfbf57074f Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Sat, 7 Sep 2024 19:44:31 +0200 Subject: [PATCH 1/4] fennerepl: remove readline Signed-off-by: Raito Bezarius --- pkgs/fennelrepl/default.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/pkgs/fennelrepl/default.nix b/pkgs/fennelrepl/default.nix index 152c605..f35abc9 100644 --- a/pkgs/fennelrepl/default.nix +++ b/pkgs/fennelrepl/default.nix @@ -20,7 +20,6 @@ let packages = [ lualinux netlink-lua iwinfo - lua.pkgs.readline ]; join = ps: builtins.concatStringsSep ";" ps; luapath = join (builtins.map (f: From c39bfc2bb56bbb7f4fb5b31d5e8fb9035b010709 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Sat, 7 Sep 2024 20:59:51 +0200 Subject: [PATCH 2/4] fix(write-fennel): escape binary path for PATH otherwise, escapeShellArg might just do nothing! Signed-off-by: Raito Bezarius --- pkgs/write-fennel/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/write-fennel/default.nix b/pkgs/write-fennel/default.nix index 67d1908..e72762d 100644 --- a/pkgs/write-fennel/default.nix +++ b/pkgs/write-fennel/default.nix @@ -27,7 +27,7 @@ name : echo "#!${lua}/bin/lua ${luaFlags}" echo "package.path = ${lib.strings.escapeShellArg (builtins.concatStringsSep "" luapath)} .. package.path" echo "package.cpath = ${lib.strings.escapeShellArg (builtins.concatStringsSep "" luacpath)} .. package.cpath" - echo "local ok, stdlib = pcall(require,'posix.stdlib'); if ok then stdlib.setenv('PATH',${lib.escapeShellArg (lib.makeBinPath packages)} .. \":\" .. os.getenv('PATH')) end" + echo "local ok, stdlib = pcall(require,'posix.stdlib'); if ok then stdlib.setenv('PATH', \"${lib.makeBinPath packages}\" .. \":\" .. os.getenv('PATH')) end" fennel ${if correlate then "--correlate" else ""} --compile ${source} ) > ${name}.lua ''; From 5590fea16e6e14de9084cdad7f0804d2bef74279 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Sat, 7 Sep 2024 20:26:40 +0200 Subject: [PATCH 3/4] feat(ifwait): add ifbridgeable script This enable to wait for bridgeability of a WLAN interface via `iwinfo`. Signed-off-by: Raito Bezarius --- pkgs/anoia/Makefile | 2 +- pkgs/anoia/default.nix | 3 ++- pkgs/anoia/wlan.fnl | 8 ++++++++ pkgs/ifwait/default.nix | 5 ++++- pkgs/ifwait/ifbridgeable.fnl | 30 ++++++++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 pkgs/anoia/wlan.fnl create mode 100644 pkgs/ifwait/ifbridgeable.fnl diff --git a/pkgs/anoia/Makefile b/pkgs/anoia/Makefile index f68e596..1c1a406 100644 --- a/pkgs/anoia/Makefile +++ b/pkgs/anoia/Makefile @@ -1,5 +1,5 @@ -default: fs.lua init.lua nl.lua svc.lua net/constants.lua +default: wlan.lua fs.lua init.lua nl.lua svc.lua net/constants.lua test: ln -s . anoia diff --git a/pkgs/anoia/default.nix b/pkgs/anoia/default.nix index b981f48..3488e66 100644 --- a/pkgs/anoia/default.nix +++ b/pkgs/anoia/default.nix @@ -4,6 +4,7 @@ , linotify , lua , lualinux +, iwinfo , cpio }: let pname = "anoia"; @@ -12,7 +13,7 @@ in stdenv.mkDerivation { version = "0.1"; src = ./.; nativeBuildInputs = [ fennel cpio ]; - buildInputs = with lua.pkgs; [ linotify lualinux ]; + buildInputs = with lua.pkgs; [ linotify lualinux iwinfo ]; outputs = [ "out" "dev" ]; doCheck = true; diff --git a/pkgs/anoia/wlan.fnl b/pkgs/anoia/wlan.fnl new file mode 100644 index 0000000..39eeeb6 --- /dev/null +++ b/pkgs/anoia/wlan.fnl @@ -0,0 +1,8 @@ +(local { : nl80211 } (require :iwinfo)) + +(fn is-bridgeable [ifname] + (let [mode (nl80211.mode ifname)] + (or (= mode "Master") (= mode "Master (VLAN)")) +)) + +{ : is-bridgeable } diff --git a/pkgs/ifwait/default.nix b/pkgs/ifwait/default.nix index 19f76d0..b99eb54 100644 --- a/pkgs/ifwait/default.nix +++ b/pkgs/ifwait/default.nix @@ -1,11 +1,14 @@ { lua , netlink-lua +, lualinux +, iwinfo , writeFennelScript , runCommand , anoia }: runCommand "ifwait" {} '' mkdir -p $out/bin - cp -p ${writeFennelScript "ifwait" [anoia netlink-lua] ./ifwait.fnl} $out/bin/ifwait + cp -p ${writeFennelScript "ifwait" [ anoia netlink-lua ] ./ifwait.fnl} $out/bin/ifwait + cp -p ${writeFennelScript "ifbridgeable" [ anoia lualinux iwinfo ] ./ifbridgeable.fnl} $out/bin/ifbridgeable '' diff --git a/pkgs/ifwait/ifbridgeable.fnl b/pkgs/ifwait/ifbridgeable.fnl new file mode 100644 index 0000000..3ddfd4b --- /dev/null +++ b/pkgs/ifwait/ifbridgeable.fnl @@ -0,0 +1,30 @@ +(local wlan (require :anoia.wlan)) +(local { : assoc } (require :anoia)) +(local { : msleep } (require :lualinux)) + +(fn parse-args [args] + (match args + ["-v" & rest] (assoc (parse-args rest) :verbose true) + [linkname] {:link linkname} + _ nil)) + +(fn run [args poll-fn] + (let [parameters + (assert (parse-args args) + (.. "Usage: ifbridgeable [-v] ifname"))] + (when parameters.verbose + (print (.. "ifbridgeable: waiting for " + parameters.link " to be bridgeable"))) + + (while (not (poll-fn parameters.link)) + (when parameters.verbose + (print (.. "ifbridgeable: waiting for " parameters.link " to be bridgeable"))) + (msleep 500) + ) + ) +) + +(when (not (= (. arg 0) "test")) + (run arg wlan.is-bridgeable)) + +{ : run } From 13069415fd5cc69ab71432b1bc588b150d13a500 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Sat, 7 Sep 2024 21:12:36 +0200 Subject: [PATCH 4/4] feat(modules/hostapd): offer readiness oneshot WLAN oper wait until the WLAN interface is ready. Signed-off-by: Raito Bezarius --- modules/hostapd/default.nix | 11 +++++++++++ modules/hostapd/ready.nix | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 modules/hostapd/ready.nix diff --git a/modules/hostapd/default.nix b/modules/hostapd/default.nix index 4338e74..67f4f72 100644 --- a/modules/hostapd/default.nix +++ b/modules/hostapd/default.nix @@ -20,6 +20,10 @@ in { system.service.hostapd = mkOption { type = liminix.lib.types.serviceDefn; }; + + system.service.hostapd-ready = mkOption { + type = liminix.lib.types.serviceDefn; + }; }; config = { system.service.hostapd = liminix.callService ./service.nix { @@ -34,5 +38,12 @@ in { type = types.attrs; }; }; + + system.service.hostapd-ready = liminix.callService ./ready.nix { + interface = mkOption { + type = liminix.lib.types.interface; + description = "Interface for which to wait that the oper state Master or Master (VLAN) has been reached."; + }; + }; }; } diff --git a/modules/hostapd/ready.nix b/modules/hostapd/ready.nix new file mode 100644 index 0000000..7c10c32 --- /dev/null +++ b/modules/hostapd/ready.nix @@ -0,0 +1,16 @@ +{ + liminix +, ifwait +, lib +}: +{ interface } : +let + inherit (liminix.services) oneshot; +in oneshot { + name = "${interface.name}.wlan-oper"; + up = '' + ${ifwait}/bin/ifbridgeable -v $(output ${interface} ifname) + ''; + + dependencies = [ interface ]; +}