From e0336d1367a68ba9ff30f47d7d67d7ee188c30bc Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Sat, 21 Aug 2021 11:56:01 +0200 Subject: [PATCH] modules: wakeonwlan: setup simple wakeonwlan --- modules/default.nix | 1 + modules/wakeonwlan.nix | 63 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 modules/wakeonwlan.nix diff --git a/modules/default.nix b/modules/default.nix index 0b7755f..761f84e 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -2,5 +2,6 @@ { imports = [ ./sddm.nix + ./wakeonwlan.nix ]; } diff --git a/modules/wakeonwlan.nix b/modules/wakeonwlan.nix new file mode 100644 index 0000000..8243671 --- /dev/null +++ b/modules/wakeonwlan.nix @@ -0,0 +1,63 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.my.wakeonwlan; + + mkWowlanService = name: cfg: + nameValuePair "wowlan-${name}" { + description = "Enable WoWLAN for interface ${name}"; + requires = [ "network.target" ]; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + Type = "oneshot"; + }; + script = '' + ${pkgs.iw}/bin/iw ${name} wowlan enable ${concatStringsSep " " cfg.methods} + ''; + }; +in +{ + options.my.wakeonwlan = { + interfaces = mkOption { + default = { }; + description = "Wireless interfaces where you want to enable WoWLAN"; + example = literalExample '' + { + phy0.methods = [ + "magic-packet" + "disconnect" + "gtk-rekey-failure" + "eap-identity-request" + "rfkill-release" + ]; + phy2.methods = [ "any" ]; + } + ''; + type = types.attrsOf ( + types.submodule { + options = { + methods = mkOption { + type = types.listOf (types.enum [ + "4way-handshake" + "any" + "disconnect" + "eap-identity-request" + "gtk-rekey-failure" + "magic-packet" + "rfkill-release" + ]); + description = "Wake-On-WiFiLan methods for this interface."; + }; + }; + } + ); + }; + }; + + config = mkIf (cfg.interfaces != {}) { + systemd.services = mapAttrs' mkWowlanService cfg.interfaces; + }; +}