From 052632fd15550d83fe98ed599c8504eaad67f0b5 Mon Sep 17 00:00:00 2001 From: Peter Hoeg Date: Sat, 16 Oct 2021 21:15:48 +0800 Subject: nixos/iwd: workaround for race condition where wlan device disappears --- nixos/modules/services/networking/iwd.nix | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/nixos/modules/services/networking/iwd.nix b/nixos/modules/services/networking/iwd.nix index 8835f7f9372..5c1480e7e2f 100644 --- a/nixos/modules/services/networking/iwd.nix +++ b/nixos/modules/services/networking/iwd.nix @@ -1,12 +1,21 @@ { config, lib, pkgs, ... }: -with lib; - let + inherit (lib) + mkEnableOption mkIf mkOption types + recursiveUpdate; + cfg = config.networking.wireless.iwd; ini = pkgs.formats.ini { }; - configFile = ini.generate "main.conf" cfg.settings; -in { + defaults = { + # without UseDefaultInterface, sometimes wlan0 simply goes AWOL with NetworkManager + # https://iwd.wiki.kernel.org/interface_lifecycle#interface_management_in_iwd + General.UseDefaultInterface = with config.networking.networkmanager; (enable && (wifi.backend == "iwd")); + }; + configFile = ini.generate "main.conf" (recursiveUpdate defaults cfg.settings); + +in +{ options.networking.wireless.iwd = { enable = mkEnableOption "iwd"; @@ -38,10 +47,10 @@ in { ''; }]; - environment.etc."iwd/main.conf".source = configFile; + environment.etc."iwd/${configFile.name}".source = configFile; # for iwctl - environment.systemPackages = [ pkgs.iwd ]; + environment.systemPackages = [ pkgs.iwd ]; services.dbus.packages = [ pkgs.iwd ]; -- cgit 1.4.1