2022-10-01 17:53:20 +00:00
|
|
|
{
|
|
|
|
liminix
|
2024-08-15 22:00:41 +00:00
|
|
|
, svc
|
2022-10-01 17:53:20 +00:00
|
|
|
, hostapd
|
2024-08-12 21:57:21 +00:00
|
|
|
, output-template
|
2022-10-01 17:53:20 +00:00
|
|
|
, writeText
|
2023-07-16 16:50:06 +00:00
|
|
|
, lib
|
2022-10-01 17:53:20 +00:00
|
|
|
}:
|
2023-08-05 11:21:18 +00:00
|
|
|
{ interface, params} :
|
2022-10-01 17:53:20 +00:00
|
|
|
let
|
|
|
|
inherit (liminix.services) longrun;
|
2024-08-20 20:49:11 +00:00
|
|
|
inherit (lib) concatStringsSep mapAttrsToList unique ;
|
2024-08-17 21:22:33 +00:00
|
|
|
inherit (builtins) map filter attrValues length head typeOf;
|
2023-07-16 16:50:06 +00:00
|
|
|
|
|
|
|
# This is not a friendly interface to configuring a wireless AP: it
|
|
|
|
# just passes everything straight through to the hostapd config.
|
|
|
|
# When we've worked out what the sensible options are to expose,
|
|
|
|
# we'll add them as top-level attributes and rename params to
|
|
|
|
# extraParams
|
2022-10-01 17:53:20 +00:00
|
|
|
|
2023-08-27 22:20:58 +00:00
|
|
|
name = "${interface.name}.hostapd";
|
2022-10-01 17:53:20 +00:00
|
|
|
defaults = {
|
|
|
|
driver = "nl80211";
|
|
|
|
logger_syslog = "-1";
|
|
|
|
logger_syslog_level = 1;
|
2024-08-14 21:57:02 +00:00
|
|
|
ctrl_interface = "/run/${name}";
|
2022-10-01 17:53:20 +00:00
|
|
|
ctrl_interface_group = 0;
|
|
|
|
};
|
2024-08-12 21:57:21 +00:00
|
|
|
attrs = defaults // params ;
|
2024-08-14 21:56:01 +00:00
|
|
|
literal_or_output = o: ({
|
|
|
|
string = builtins.toJSON;
|
|
|
|
int = builtins.toJSON;
|
2024-08-23 21:25:57 +00:00
|
|
|
lambda = (o: "output(${builtins.toJSON (o "service")}, ${builtins.toJSON (o "path")})");
|
2024-08-14 21:56:01 +00:00
|
|
|
}.${builtins.typeOf o}) o;
|
2024-08-20 22:26:11 +00:00
|
|
|
|
2024-08-12 21:57:21 +00:00
|
|
|
conf =
|
|
|
|
(writeText "hostapd.conf.in"
|
|
|
|
((concatStringsSep
|
|
|
|
"\n"
|
|
|
|
(mapAttrsToList
|
2024-08-20 22:26:11 +00:00
|
|
|
(n : v : "${n}={{ ${literal_or_output v} }}")
|
2024-08-12 21:57:21 +00:00
|
|
|
attrs)) + "\n"));
|
2024-08-15 22:00:41 +00:00
|
|
|
service = longrun {
|
|
|
|
inherit name;
|
|
|
|
dependencies = [ interface ];
|
|
|
|
run = ''
|
|
|
|
mkdir -p /run/${name}
|
|
|
|
chmod 0700 /run/${name}
|
2024-08-17 21:22:33 +00:00
|
|
|
${output-template}/bin/output-template '{{' '}}' < ${conf} > /run/${name}/hostapd.conf
|
|
|
|
exec ${hostapd}/bin/hostapd -i $(output ${interface} ifname) -P /run/${name}/hostapd.pid -S /run/${name}/hostapd.conf
|
2024-08-15 22:00:41 +00:00
|
|
|
'';
|
|
|
|
};
|
2024-08-30 19:46:48 +00:00
|
|
|
watch = filter (f: typeOf f == "lambda") (attrValues attrs);
|
2024-08-15 22:00:41 +00:00
|
|
|
in svc.secrets.subscriber.build {
|
2024-08-30 19:46:48 +00:00
|
|
|
inherit service watch;
|
2024-08-15 22:00:41 +00:00
|
|
|
action = "restart-all";
|
2022-10-01 17:53:20 +00:00
|
|
|
}
|