nixos/wpa_supplicant: make new behavior opt-in

This commit is contained in:
Maximilian Bosch 2021-04-15 18:13:18 +02:00
parent de0a39166b
commit 08ced9d67f
No known key found for this signature in database
GPG Key ID: 091DBF4D1FC46B8E
3 changed files with 31 additions and 6 deletions

View File

@ -3,6 +3,10 @@
with lib; with lib;
let let
package = if cfg.allowDeclarativeAndImperativeNetworks
then pkgs.wpa_supplicant_ro_ssids
else pkgs.wpa_supplicant;
cfg = config.networking.wireless; cfg = config.networking.wireless;
configFile = if cfg.networks != {} || cfg.extraConfig != "" || cfg.userControlled.enable then pkgs.writeText "wpa_supplicant.conf" '' configFile = if cfg.networks != {} || cfg.extraConfig != "" || cfg.userControlled.enable then pkgs.writeText "wpa_supplicant.conf" ''
${optionalString cfg.userControlled.enable '' ${optionalString cfg.userControlled.enable ''
@ -47,6 +51,16 @@ in {
description = "Force a specific wpa_supplicant driver."; description = "Force a specific wpa_supplicant driver.";
}; };
allowDeclarativeAndImperativeNetworks = mkEnableOption "support for imperative & declarative networks" // {
description = ''
Whether to allow configuring networks "imperatively" (e.g. via
<package>wpa_supplicant_gui</package>) and declaratively via
<xref linkend="opt-networking.wireless.networks" />.
Please note that this adds a custom patch to <package>wpa_supplicant</package>.
'';
};
networks = mkOption { networks = mkOption {
type = types.attrsOf (types.submodule { type = types.attrsOf (types.submodule {
options = { options = {
@ -211,9 +225,9 @@ in {
message = ''options networking.wireless."${name}".{psk,pskRaw,auth} are mutually exclusive''; message = ''options networking.wireless."${name}".{psk,pskRaw,auth} are mutually exclusive'';
}); });
environment.systemPackages = [ pkgs.wpa_supplicant ]; environment.systemPackages = [ package ];
services.dbus.packages = [ pkgs.wpa_supplicant ]; services.dbus.packages = [ package ];
services.udev.packages = [ pkgs.crda ]; services.udev.packages = [ pkgs.crda ];
# FIXME: start a separate wpa_supplicant instance per interface. # FIXME: start a separate wpa_supplicant instance per interface.
@ -230,13 +244,17 @@ in {
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
stopIfChanged = false; stopIfChanged = false;
path = [ pkgs.wpa_supplicant ]; path = [ package ];
script = '' script = let
configStr = if cfg.allowDeclarativeAndImperativeNetworks
then "-c /etc/wpa_supplicant.conf -I ${configFile}"
else "-c ${configFile}";
in ''
if [ -f /etc/wpa_supplicant.conf -a "/etc/wpa_supplicant.conf" != "${configFile}" ] if [ -f /etc/wpa_supplicant.conf -a "/etc/wpa_supplicant.conf" != "${configFile}" ]
then echo >&2 "<3>/etc/wpa_supplicant.conf present but ignored. Generated ${configFile} is used instead." then echo >&2 "<3>/etc/wpa_supplicant.conf present but ignored. Generated ${configFile} is used instead."
fi fi
iface_args="-s -u -D${cfg.driver} -c /etc/wpa_supplicant.conf -I ${configFile}" iface_args="-s -u -D${cfg.driver} ${configStr}"
${if ifaces == [] then '' ${if ifaces == [] then ''
for i in $(cd /sys/class/net && echo *); do for i in $(cd /sys/class/net && echo *); do
DEVTYPE= DEVTYPE=

View File

@ -1,5 +1,7 @@
{ lib, stdenv, fetchurl, fetchpatch, openssl, pkg-config, libnl { lib, stdenv, fetchurl, fetchpatch, openssl, pkg-config, libnl
, dbus, readline ? null, pcsclite ? null , dbus, readline ? null, pcsclite ? null
, readOnlyModeSSIDs ? false
}: }:
with lib; with lib;
@ -43,6 +45,7 @@ stdenv.mkDerivation rec {
url = "https://w1.fi/cgit/hostap/patch/?id=a0541334a6394f8237a4393b7372693cd7e96f15"; url = "https://w1.fi/cgit/hostap/patch/?id=a0541334a6394f8237a4393b7372693cd7e96f15";
sha256 = "1gbhlz41x1ar1hppnb76pqxj6vimiypy7c4kq6h658637s4am3xg"; sha256 = "1gbhlz41x1ar1hppnb76pqxj6vimiypy7c4kq6h658637s4am3xg";
}) })
] ++ lib.optionals readOnlyModeSSIDs [
# Allow read-only networks # Allow read-only networks
./0001-Implement-read-only-mode-for-ssids.patch ./0001-Implement-read-only-mode-for-ssids.patch
]; ];
@ -136,7 +139,7 @@ stdenv.mkDerivation rec {
homepage = "https://w1.fi/wpa_supplicant/"; homepage = "https://w1.fi/wpa_supplicant/";
description = "A tool for connecting to WPA and WPA2-protected wireless networks"; description = "A tool for connecting to WPA and WPA2-protected wireless networks";
license = licenses.bsd3; license = licenses.bsd3;
maintainers = with maintainers; [ marcweber ]; maintainers = with maintainers; [ marcweber ma27 ];
platforms = platforms.linux; platforms = platforms.linux;
}; };
} }

View File

@ -20859,6 +20859,10 @@ in
wpa_supplicant = callPackage ../os-specific/linux/wpa_supplicant { }; wpa_supplicant = callPackage ../os-specific/linux/wpa_supplicant { };
wpa_supplicant_ro_ssids = wpa_supplicant.override {
readOnlyModeSSIDs = true;
};
wpa_supplicant_gui = libsForQt5.callPackage ../os-specific/linux/wpa_supplicant/gui.nix { }; wpa_supplicant_gui = libsForQt5.callPackage ../os-specific/linux/wpa_supplicant/gui.nix { };
xf86_input_cmt = callPackage ../os-specific/linux/xf86-input-cmt { }; xf86_input_cmt = callPackage ../os-specific/linux/xf86-input-cmt { };