Merge branch 'bridgeability' into 'main'
Some checks failed
build liminix / build_vm_qemu_mips (push) Failing after 27s

This commit is contained in:
Raito Bezarius 2024-09-07 21:53:20 +02:00
commit bc1f54e701
9 changed files with 73 additions and 5 deletions

View file

@ -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.";
};
};
};
}

16
modules/hostapd/ready.nix Normal file
View file

@ -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 ];
}

View file

@ -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

View file

@ -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;

8
pkgs/anoia/wlan.fnl Normal file
View file

@ -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 }

View file

@ -20,7 +20,6 @@ let packages = [
lualinux
netlink-lua
iwinfo
lua.pkgs.readline
];
join = ps: builtins.concatStringsSep ";" ps;
luapath = join (builtins.map (f:

View file

@ -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
''

View file

@ -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 }

View file

@ -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
'';