2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2010-12-02 21:23:45 +01:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2010-12-02 21:23:45 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
interfaces = config.services.wakeonlan.interfaces;
|
|
|
|
|
|
|
|
ethtool = "${pkgs.ethtool}/sbin/ethtool";
|
|
|
|
|
|
|
|
passwordParameter = password : if (password == "") then "" else
|
|
|
|
"sopass ${password}";
|
|
|
|
|
|
|
|
methodParameter = {method, password} :
|
|
|
|
if method == "magicpacket" then "wol g"
|
|
|
|
else if method == "password" then "wol s so ${passwordParameter password}"
|
|
|
|
else throw "Wake-On-Lan method not supported";
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2010-12-02 21:23:45 +01:00
|
|
|
line = { interface, method ? "magicpacket", password ? "" }: ''
|
|
|
|
${ethtool} -s ${interface} ${methodParameter {inherit method password;}}
|
|
|
|
'';
|
|
|
|
|
2021-01-25 07:57:48 +01:00
|
|
|
concatStrings = foldr (x: y: x + y) "";
|
2010-12-02 21:23:45 +01:00
|
|
|
lines = concatStrings (map (l: line l) interfaces);
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2010-12-02 21:23:45 +01:00
|
|
|
options = {
|
|
|
|
|
|
|
|
services.wakeonlan.interfaces = mkOption {
|
|
|
|
default = [ ];
|
2021-01-31 12:33:27 +01:00
|
|
|
type = types.listOf (types.submodule { options = {
|
|
|
|
interface = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "Interface to enable for Wake-On-Lan.";
|
|
|
|
};
|
|
|
|
method = mkOption {
|
|
|
|
type = types.enum [ "magicpacket" "password"];
|
|
|
|
description = "Wake-On-Lan method for this interface.";
|
|
|
|
};
|
|
|
|
password = mkOption {
|
|
|
|
type = types.strMatching "[a-fA-F0-9]{2}:([a-fA-F0-9]{2}:){4}[a-fA-F0-9]{2}";
|
|
|
|
description = "The password has the shape of six bytes in hexadecimal separated by a colon each.";
|
|
|
|
};
|
|
|
|
};});
|
2010-12-02 21:23:45 +01:00
|
|
|
example = [
|
|
|
|
{
|
|
|
|
interface = "eth0";
|
|
|
|
method = "password";
|
|
|
|
password = "00:11:22:33:44:55";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
description = ''
|
|
|
|
Interfaces where to enable Wake-On-LAN, and how. Two methods available:
|
2015-10-31 12:55:34 +01:00
|
|
|
"magicpacket" and "password". The password has the shape of six bytes
|
2010-12-02 21:23:45 +01:00
|
|
|
in hexadecimal separated by a colon each. For more information,
|
|
|
|
check the ethtool manual.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2020-09-07 14:47:28 +02:00
|
|
|
config.powerManagement.powerUpCommands = lines;
|
2010-12-02 21:23:45 +01:00
|
|
|
|
|
|
|
}
|