2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
2022-03-30 09:31:56 +00:00
|
|
|
inherit (lib)
|
|
|
|
mkEnableOption mkIf mkOption types
|
|
|
|
recursiveUpdate;
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
cfg = config.networking.wireless.iwd;
|
2021-08-05 21:33:18 +00:00
|
|
|
ini = pkgs.formats.ini { };
|
2022-03-30 09:31:56 +00:00
|
|
|
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
|
|
|
|
{
|
2021-08-05 21:33:18 +00:00
|
|
|
options.networking.wireless.iwd = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "iwd");
|
2021-08-05 21:33:18 +00:00
|
|
|
|
2022-10-21 18:38:19 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.iwd;
|
|
|
|
defaultText = lib.literalExpression "pkgs.iwd";
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
The iwd package to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-08-05 21:33:18 +00:00
|
|
|
settings = mkOption {
|
|
|
|
type = ini.type;
|
|
|
|
default = { };
|
|
|
|
|
|
|
|
example = {
|
|
|
|
Settings.AutoConnect = true;
|
|
|
|
|
|
|
|
Network = {
|
|
|
|
EnableIPv6 = true;
|
|
|
|
RoutePriorityOffset = 300;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-08-05 21:33:18 +00:00
|
|
|
Options passed to iwd.
|
2022-08-12 12:06:08 +00:00
|
|
|
See [here](https://iwd.wiki.kernel.org/networkconfigurationsettings) for supported options.
|
2021-08-05 21:33:18 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
assertions = [{
|
|
|
|
assertion = !config.networking.wireless.enable;
|
|
|
|
message = ''
|
|
|
|
Only one wireless daemon is allowed at the time: networking.wireless.enable and networking.wireless.iwd.enable are mutually exclusive.
|
|
|
|
'';
|
|
|
|
}];
|
|
|
|
|
2022-03-30 09:31:56 +00:00
|
|
|
environment.etc."iwd/${configFile.name}".source = configFile;
|
2021-08-05 21:33:18 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
# for iwctl
|
2022-10-21 18:38:19 +00:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-10-21 18:38:19 +00:00
|
|
|
services.dbus.packages = [ cfg.package ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-10-21 18:38:19 +00:00
|
|
|
systemd.packages = [ cfg.package ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
systemd.network.links."80-iwd" = {
|
|
|
|
matchConfig.Type = "wlan";
|
|
|
|
linkConfig.NamePolicy = "keep kernel";
|
|
|
|
};
|
|
|
|
|
2021-08-05 21:33:18 +00:00
|
|
|
systemd.services.iwd = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
restartTriggers = [ configFile ];
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2022-10-21 18:38:19 +00:00
|
|
|
meta.maintainers = with lib.maintainers; [ dtzWill ];
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|