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