From 24b53785cce8f81e2171c2e4042bfd4e3d0b2606 Mon Sep 17 00:00:00 2001 From: Jonas Heinrich Date: Wed, 13 Apr 2022 19:20:37 +0200 Subject: [PATCH] nixos/create_ap: add module --- .../from_md/release-notes/rl-2205.section.xml | 8 +++ .../manual/release-notes/rl-2205.section.md | 2 + nixos/modules/module-list.nix | 1 + .../modules/services/networking/create_ap.nix | 50 +++++++++++++++++++ .../linux/linux-wifi-hotspot/default.nix | 15 ++++-- 5 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 nixos/modules/services/networking/create_ap.nix diff --git a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml index af2aecda0da..05b3822cab7 100644 --- a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml +++ b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml @@ -375,6 +375,14 @@ services.headscale + + + create_ap, + a module for creating wifi hotspots using the program + linux-wifi-hotspot. Available as + services.create_ap. + + blocky, diff --git a/nixos/doc/manual/release-notes/rl-2205.section.md b/nixos/doc/manual/release-notes/rl-2205.section.md index 6d22973fb9b..16c59ce3ddd 100644 --- a/nixos/doc/manual/release-notes/rl-2205.section.md +++ b/nixos/doc/manual/release-notes/rl-2205.section.md @@ -107,6 +107,8 @@ In addition to numerous new and upgraded packages, this release has the followin - [headscale](https://github.com/juanfont/headscale), an Open Source implementation of the [Tailscale](https://tailscale.io) Control Server. Available as [services.headscale](options.html#opt-services.headscale.enable) +- [create_ap](https://github.com/lakinduakash/linux-wifi-hotspot), a module for creating wifi hotspots using the program linux-wifi-hotspot. Available as [services.create_ap](options.html#opt-services.create_ap.enable). + - [blocky](https://0xerr0r.github.io/blocky/), fast and lightweight DNS proxy as ad-blocker for local network with many features. - [pacemaker](https://clusterlabs.org/pacemaker/) cluster resource manager diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 9aa8817ca51..132416d865f 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -740,6 +740,7 @@ ./services/networking/coredns.nix ./services/networking/corerad.nix ./services/networking/coturn.nix + ./services/networking/create_ap.nix ./services/networking/croc.nix ./services/networking/dante.nix ./services/networking/ddclient.nix diff --git a/nixos/modules/services/networking/create_ap.nix b/nixos/modules/services/networking/create_ap.nix new file mode 100644 index 00000000000..a3c330fab00 --- /dev/null +++ b/nixos/modules/services/networking/create_ap.nix @@ -0,0 +1,50 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.create_ap; + configFile = pkgs.writeText "create_ap.conf" (generators.toKeyValue { } cfg.settings); +in { + options = { + services.create_ap = { + enable = mkEnableOption "setup wifi hotspots using create_ap"; + settings = mkOption { + type = with types; attrsOf (oneOf [ int bool str ]); + default = {}; + description = '' + Configuration for create_ap. + See upstream example configuration + for supported values. + ''; + example = { + INTERNET_IFACE = "eth0"; + WIFI_IFACE = "wlan0"; + SSID = "My Wifi Hotspot"; + PASSPHRASE = "12345678"; + }; + }; + }; + }; + + config = mkIf cfg.enable { + + systemd = { + services.create_ap = { + wantedBy = [ "multi-user.target" ]; + description = "Create AP Service"; + after = [ "network.target" ]; + restartTriggers = [ configFile ]; + serviceConfig = { + ExecStart = "${pkgs.linux-wifi-hotspot}/bin/create_ap --config ${configFile}"; + KillSignal = "SIGINT"; + Restart = "on-failure"; + }; + }; + }; + + }; + + meta.maintainers = with lib.maintainers; [ onny ]; + +} diff --git a/pkgs/os-specific/linux/linux-wifi-hotspot/default.nix b/pkgs/os-specific/linux/linux-wifi-hotspot/default.nix index 2cefc9b0216..a29fe923f60 100644 --- a/pkgs/os-specific/linux/linux-wifi-hotspot/default.nix +++ b/pkgs/os-specific/linux/linux-wifi-hotspot/default.nix @@ -8,7 +8,13 @@ , iw , makeWrapper , qrencode -, hostapd }: +, hostapd +, getopt +, dnsmasq +, iproute2 +, flock +, iptables +, gawk }: stdenv.mkDerivation rec { pname = "linux-wifi-hotspot"; @@ -41,9 +47,6 @@ stdenv.mkDerivation rec { --replace "etc" "$out/etc" substituteInPlace ./src/scripts/wihotspot \ --replace "/usr" "$out" - substituteInPlace ./src/scripts/create_ap.service \ - --replace "/usr/bin/create_ap" "$out/bin/create_cap" \ - --replace "/etc/create_ap.conf" "$out/etc/create_cap.conf" ''; makeFlags = [ @@ -52,7 +55,9 @@ stdenv.mkDerivation rec { postInstall = '' wrapProgram $out/bin/create_ap \ - --prefix PATH : ${lib.makeBinPath [ hostapd ]} + --prefix PATH : ${lib.makeBinPath [ + hostapd getopt iw which dnsmasq iproute2 flock iptables gawk + ]} wrapProgram $out/bin/wihotspot-gui \ --prefix PATH : ${lib.makeBinPath [ iw ]} \