2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2010-12-02 20:23:45 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2010-12-02 20:23:45 +00: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 18:20:50 +00:00
|
|
|
|
2010-12-02 20:23:45 +00:00
|
|
|
line = { interface, method ? "magicpacket", password ? "" }: ''
|
|
|
|
${ethtool} -s ${interface} ${methodParameter {inherit method password;}}
|
|
|
|
'';
|
|
|
|
|
|
|
|
concatStrings = fold (x: y: x + y) "";
|
|
|
|
lines = concatStrings (map (l: line l) interfaces);
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-12-02 20:23:45 +00:00
|
|
|
options = {
|
|
|
|
|
|
|
|
services.wakeonlan.interfaces = mkOption {
|
|
|
|
default = [ ];
|
|
|
|
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 11:55:34 +00:00
|
|
|
"magicpacket" and "password". The password has the shape of six bytes
|
2010-12-02 20:23:45 +00:00
|
|
|
in hexadecimal separated by a colon each. For more information,
|
|
|
|
check the ethtool manual.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config.powerManagement.powerDownCommands = lines;
|
|
|
|
|
|
|
|
}
|