commit 648ea5613bf45424762d9f847e4ff1319f256a4e
parent 17abd42cf346d9d6b43022db4a8e00044e49151b
Author: Daniel Barlow <dan@telent.net>
Date: Sun, 16 Jul 2023 17:50:06 +0100
use module-based-service for hostapd
Diffstat:
4 files changed, 69 insertions(+), 43 deletions(-)
diff --git a/examples/rotuer.nix b/examples/rotuer.nix
@@ -11,7 +11,6 @@ let
secrets = import ./rotuer-secrets.nix;
inherit (pkgs.liminix.networking)
address
- hostapd
interface
route;
inherit (pkgs.liminix.services) oneshot longrun bundle target;
@@ -36,6 +35,7 @@ in rec {
../modules/ppp
../modules/dnsmasq
../modules/firewall
+ ../modules/hostapd
];
rootfsType = "jffs2";
hostname = "rotuer";
@@ -45,7 +45,8 @@ in rec {
};
};
- services.hostap = hostapd (config.hardware.networkInterfaces.wlan_24) {
+ services.hostap = config.system.service.hostapd {
+ interface = config.hardware.networkInterfaces.wlan_24;
params = {
ssid = "liminix";
country_code = "GB";
@@ -62,7 +63,8 @@ in rec {
};
};
- services.hostap5 = hostapd (config.hardware.networkInterfaces.wlan_5) {
+ services.hostap5 = config.system.service.hostapd {
+ interface = config.hardware.networkInterfaces.wlan_5;
params = rec {
ssid = "liminix_5";
country_code = "GB";
diff --git a/modules/hostapd/default.nix b/modules/hostapd/default.nix
@@ -0,0 +1,13 @@
+{ lib, pkgs, config, ...}:
+let
+ inherit (lib) mkOption types;
+in {
+ options = {
+ system.service.hostapd = mkOption {
+ type = types.functionTo types.package;
+ };
+ };
+ config = {
+ system.service.hostapd = pkgs.callPackage ./service.nix {};
+ };
+}
diff --git a/modules/hostapd/service.nix b/modules/hostapd/service.nix
@@ -0,0 +1,51 @@
+{
+ liminix
+, hostapd
+, writeText
+, lib
+}:
+let
+ inherit (liminix.services) longrun;
+ inherit (lib) concatStringsSep mapAttrsToList;
+ inherit (liminix.lib) typeChecked;
+ inherit (lib) mkOption types;
+
+ # 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
+
+ t = {
+ interface = mkOption {
+ type = liminix.lib.types.service;
+ };
+ params = mkOption {
+ type = types.attrs;
+ };
+ };
+in
+args:
+let
+ inherit (typeChecked "hostapd" t args)
+ interface params;
+ name = "${interface.device}.hostapd";
+ defaults = {
+ driver = "nl80211";
+ logger_syslog = "-1";
+ logger_syslog_level = 1;
+ ctrl_interface = "/run/hostapd";
+ ctrl_interface_group = 0;
+ };
+
+ conf = writeText "hostapd.conf"
+ (concatStringsSep
+ "\n"
+ (mapAttrsToList
+ (name: value: "${name}=${toString value}")
+ (defaults // params)));
+in longrun {
+ inherit name;
+ dependencies = [ interface ];
+ run = "${hostapd}/bin/hostapd -i ${interface.device} -P /run/${name}.pid -S ${conf}";
+}
diff --git a/pkgs/liminix-tools/networking/hostapd.nix b/pkgs/liminix-tools/networking/hostapd.nix
@@ -1,40 +0,0 @@
-# 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
-
-{
- liminix
-, hostapd
-, lib
-, writeText
-}:
-interface:
-{
- params ? {}
-}:
-let
- inherit (liminix.services) longrun;
- inherit (lib) concatStringsSep mapAttrsToList;
- inherit (builtins) toString;
-
- name = "${interface.device}.hostapd";
- defaults = {
- driver = "nl80211";
- logger_syslog = "-1";
- logger_syslog_level = 1;
- ctrl_interface = "/run/hostapd";
- ctrl_interface_group = 0;
- };
-
- conf = writeText "hostapd.conf"
- (concatStringsSep
- "\n"
- (mapAttrsToList
- (name: value: "${name}=${toString value}")
- (defaults // params)));
-in longrun {
- inherit name;
- dependencies = [ interface ];
- run = "${hostapd}/bin/hostapd -i ${interface.device} -P /run/${name}.pid -S ${conf}";
-}