use module-based-service for hostapd

This commit is contained in:
Daniel Barlow 2023-07-16 17:50:06 +01:00
parent 17abd42cf3
commit 648ea5613b
3 changed files with 40 additions and 14 deletions

View file

@ -11,7 +11,6 @@ let
secrets = import ./rotuer-secrets.nix; secrets = import ./rotuer-secrets.nix;
inherit (pkgs.liminix.networking) inherit (pkgs.liminix.networking)
address address
hostapd
interface interface
route; route;
inherit (pkgs.liminix.services) oneshot longrun bundle target; inherit (pkgs.liminix.services) oneshot longrun bundle target;
@ -36,6 +35,7 @@ in rec {
../modules/ppp ../modules/ppp
../modules/dnsmasq ../modules/dnsmasq
../modules/firewall ../modules/firewall
../modules/hostapd
]; ];
rootfsType = "jffs2"; rootfsType = "jffs2";
hostname = "rotuer"; 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 = { params = {
ssid = "liminix"; ssid = "liminix";
country_code = "GB"; 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 { params = rec {
ssid = "liminix_5"; ssid = "liminix_5";
country_code = "GB"; country_code = "GB";

View file

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

View file

@ -1,23 +1,34 @@
# 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 liminix
, hostapd , hostapd
, lib
, writeText , writeText
}: , lib
interface:
{
params ? {}
}: }:
let let
inherit (liminix.services) longrun; inherit (liminix.services) longrun;
inherit (lib) concatStringsSep mapAttrsToList; inherit (lib) concatStringsSep mapAttrsToList;
inherit (builtins) toString; 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"; name = "${interface.device}.hostapd";
defaults = { defaults = {
driver = "nl80211"; driver = "nl80211";