1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 interfaces = config.services.wakeonlan.interfaces;
7
8 ethtool = "${pkgs.ethtool}/sbin/ethtool";
9
10 passwordParameter = password : if (password == "") then "" else
11 "sopass ${password}";
12
13 methodParameter = {method, password} :
14 if method == "magicpacket" then "wol g"
15 else if method == "password" then "wol s so ${passwordParameter password}"
16 else throw "Wake-On-Lan method not supported";
17
18 line = { interface, method ? "magicpacket", password ? "" }: ''
19 ${ethtool} -s ${interface} ${methodParameter {inherit method password;}}
20 '';
21
22 concatStrings = fold (x: y: x + y) "";
23 lines = concatStrings (map (l: line l) interfaces);
24
25in
26{
27
28 ###### interface
29
30 options = {
31
32 services.wakeonlan.interfaces = mkOption {
33 default = [ ];
34 example = [
35 {
36 interface = "eth0";
37 method = "password";
38 password = "00:11:22:33:44:55";
39 }
40 ];
41 description = ''
42 Interfaces where to enable Wake-On-LAN, and how. Two methods available:
43 "magicpacket" and "password". The password has the shape of six bytes
44 in hexadecimal separated by a colon each. For more information,
45 check the ethtool manual.
46 '';
47 };
48
49 };
50
51
52 ###### implementation
53
54 config.powerManagement.powerDownCommands = lines;
55
56}