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