at 23.11-pre 2.1 kB view raw
1{ config, lib, pkgs, ... }: 2 3let 4 inherit (lib) 5 mkEnableOption 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 (lib.mdDoc "iwd"); 21 22 package = mkOption { 23 type = types.package; 24 default = pkgs.iwd; 25 defaultText = lib.literalExpression "pkgs.iwd"; 26 description = lib.mdDoc '' 27 The iwd package to use. 28 ''; 29 }; 30 31 settings = mkOption { 32 type = ini.type; 33 default = { }; 34 35 example = { 36 Settings.AutoConnect = true; 37 38 Network = { 39 EnableIPv6 = true; 40 RoutePriorityOffset = 300; 41 }; 42 }; 43 44 description = lib.mdDoc '' 45 Options passed to iwd. 46 See [here](https://iwd.wiki.kernel.org/networkconfigurationsettings) for supported options. 47 ''; 48 }; 49 }; 50 51 config = mkIf cfg.enable { 52 assertions = [{ 53 assertion = !config.networking.wireless.enable; 54 message = '' 55 Only one wireless daemon is allowed at the time: networking.wireless.enable and networking.wireless.iwd.enable are mutually exclusive. 56 ''; 57 }]; 58 59 environment.etc."iwd/${configFile.name}".source = configFile; 60 61 # for iwctl 62 environment.systemPackages = [ cfg.package ]; 63 64 services.dbus.packages = [ cfg.package ]; 65 66 systemd.packages = [ cfg.package ]; 67 68 systemd.network.links."80-iwd" = { 69 matchConfig.Type = "wlan"; 70 linkConfig.NamePolicy = "keep kernel"; 71 }; 72 73 systemd.services.iwd = { 74 wantedBy = [ "multi-user.target" ]; 75 restartTriggers = [ configFile ]; 76 }; 77 }; 78 79 meta.maintainers = with lib.maintainers; [ dtzWill ]; 80}