summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2023-11-27 09:56:05 +0530
committersinanmohd <sinan@sinanmohd.com>2023-11-27 20:54:02 +0530
commit0b8e24c80ad0a5e9e97b0aedd17357199b82c369 (patch)
tree90edff08ea21cdf02069028d2342709a32d7d2bf
parent821dbcbb0f0d6adf18cb95fc567826e2ab8f70e5 (diff)
modules/iwd: fix broken dhcp dns configuration
-rw-r--r--common.nix2
-rw-r--r--hosts/cez/configuration.nix11
-rw-r--r--modules/iwd.nix93
3 files changed, 104 insertions, 2 deletions
diff --git a/common.nix b/common.nix
index 796d05f..831b4aa 100644
--- a/common.nix
+++ b/common.nix
@@ -10,6 +10,7 @@ in
{
disabledModules = [
"services/networking/pppd.nix"
+ "services/networking/iwd.nix"
"system/boot/systemd/logind.nix"
];
imports = [
@@ -18,6 +19,7 @@ in
./modules/pppd.nix
./modules/seatd.nix
./modules/logind.nix
+ ./modules/iwd.nix
];
# boot
diff --git a/hosts/cez/configuration.nix b/hosts/cez/configuration.nix
index 05e7dd6..b8bbc3e 100644
--- a/hosts/cez/configuration.nix
+++ b/hosts/cez/configuration.nix
@@ -27,8 +27,15 @@ in
networking = {
hostName = "cez";
- dhcpcd.wait = "background";
- wireless.iwd.enable = true;
+ useDHCP = false;
+
+ wireless.iwd = {
+ enable = true;
+ settings = {
+ General.EnableNetworkConfiguration = true;
+ Network.NameResolvingService = "resolvconf";
+ };
+ };
};
services = {
diff --git a/modules/iwd.nix b/modules/iwd.nix
new file mode 100644
index 0000000..0c1c94a
--- /dev/null
+++ b/modules/iwd.nix
@@ -0,0 +1,93 @@
+{ config, lib, pkgs, ... }:
+
+let
+ inherit (lib)
+ mkEnableOption mkIf mkOption types
+ recursiveUpdate;
+
+ cfg = config.networking.wireless.iwd;
+ ini = pkgs.formats.ini { };
+ 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
+{
+ options.networking.wireless.iwd = {
+ enable = mkEnableOption (lib.mdDoc "iwd");
+
+ package = mkOption {
+ type = types.package;
+ default = pkgs.iwd;
+ defaultText = lib.literalExpression "pkgs.iwd";
+ description = lib.mdDoc ''
+ The iwd package to use.
+ '';
+ };
+
+ settings = mkOption {
+ type = ini.type;
+ default = { };
+
+ example = {
+ Settings.AutoConnect = true;
+
+ Network = {
+ EnableIPv6 = true;
+ RoutePriorityOffset = 300;
+ };
+ };
+
+ description = lib.mdDoc ''
+ Options passed to iwd.
+ See [here](https://iwd.wiki.kernel.org/networkconfigurationsettings) for supported options.
+ '';
+ };
+ };
+
+ config = lib.mkMerge [
+ (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.
+ '';
+ }];
+
+ environment.etc."iwd/${configFile.name}".source = configFile;
+
+ # for iwctl
+ environment.systemPackages = [ cfg.package ];
+ services.dbus.packages = [ cfg.package ];
+ systemd.packages = [ cfg.package ];
+
+ systemd.network.links."80-iwd" = {
+ matchConfig.Type = "wlan";
+ linkConfig.NamePolicy = "keep kernel";
+ };
+
+ systemd.services.iwd = {
+ wantedBy = [ "multi-user.target" ];
+ restartTriggers = [ configFile ];
+ };
+ })
+ (let
+ needResolv = cfg.enable
+ && lib.hasAttrByPath [ "Network" "NameResolvingService" ] cfg.settings
+ && cfg.settings.Network.NameResolvingService == "resolvconf";
+ in
+ mkIf needResolv {
+ environment.systemPackages = [ pkgs.openresolv ];
+
+ systemd.services.iwd = {
+ path = [ pkgs.openresolv ];
+ serviceConfig.ReadWritePaths = "/etc/resolv.conf";
+ };
+ })
+ ];
+
+ meta.maintainers = with lib.maintainers; [ dtzWill ];
+}