at 25.11-pre 2.4 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7 8let 9 inherit (lib) 10 mkEnableOption 11 mkPackageOption 12 mkIf 13 mkOption 14 types 15 recursiveUpdate 16 ; 17 18 cfg = config.networking.wireless.iwd; 19 ini = pkgs.formats.ini { }; 20 defaults = { 21 # without UseDefaultInterface, sometimes wlan0 simply goes AWOL with NetworkManager 22 # https://iwd.wiki.kernel.org/interface_lifecycle#interface_management_in_iwd 23 DriverQuirks.UseDefaultInterface = 24 with config.networking.networkmanager; 25 (enable && (wifi.backend == "iwd")); 26 }; 27 configFile = ini.generate "main.conf" (recursiveUpdate defaults cfg.settings); 28 29in 30{ 31 options.networking.wireless.iwd = { 32 enable = mkEnableOption "iwd"; 33 34 package = mkPackageOption pkgs "iwd" { }; 35 36 settings = mkOption { 37 type = ini.type; 38 default = { }; 39 40 example = { 41 Settings.AutoConnect = true; 42 43 Network = { 44 EnableIPv6 = true; 45 RoutePriorityOffset = 300; 46 }; 47 }; 48 49 description = '' 50 Options passed to iwd. 51 See {manpage}`iwd.config(5)` for supported options. 52 ''; 53 }; 54 }; 55 56 config = mkIf cfg.enable { 57 assertions = [ 58 { 59 assertion = !config.networking.wireless.enable; 60 message = '' 61 Only one wireless daemon is allowed at the time: networking.wireless.enable and networking.wireless.iwd.enable are mutually exclusive. 62 ''; 63 } 64 { 65 assertion = !(cfg.settings ? General && cfg.settings.General ? UseDefaultInterface); 66 message = '' 67 `networking.wireless.iwd.settings.General.UseDefaultInterface` has been deprecated. Use `networking.wireless.iwd.settings.DriverQuirks.UseDefaultInterface` instead. 68 ''; 69 } 70 ]; 71 72 environment.etc."iwd/${configFile.name}".source = configFile; 73 74 # for iwctl 75 environment.systemPackages = [ cfg.package ]; 76 77 services.dbus.packages = [ cfg.package ]; 78 79 systemd.packages = [ cfg.package ]; 80 81 systemd.network.links."80-iwd" = { 82 matchConfig.Type = "wlan"; 83 linkConfig.NamePolicy = "keep kernel"; 84 }; 85 86 systemd.services.iwd = { 87 path = [ config.networking.resolvconf.package ]; 88 wantedBy = [ "multi-user.target" ]; 89 restartTriggers = [ configFile ]; 90 serviceConfig.ReadWritePaths = "-/etc/resolv.conf"; 91 }; 92 }; 93 94 meta.maintainers = with lib.maintainers; [ dtzWill ]; 95}