Adding a wake on lan module.
svn path=/nixos/trunk/; revision=24958
This commit is contained in:
parent
651a38019d
commit
d5fb41795f
@ -10,9 +10,14 @@ let
|
|||||||
''
|
''
|
||||||
#! ${pkgs.stdenv.shell}
|
#! ${pkgs.stdenv.shell}
|
||||||
action="$1"
|
action="$1"
|
||||||
if [ "$action" = "resume" ]; then
|
case "$action" in
|
||||||
|
hibernate|suspend)
|
||||||
|
${cfg.powerDownCommands}
|
||||||
|
;;
|
||||||
|
thaw|resume)
|
||||||
${cfg.resumeCommands}
|
${cfg.resumeCommands}
|
||||||
${cfg.powerUpCommands}
|
${cfg.powerUpCommands}
|
||||||
|
;;
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
@ -51,6 +56,17 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
powerDownCommands = mkOption {
|
||||||
|
default = "";
|
||||||
|
example = "${pkgs.hdparm}/sbin/hdparm -B 255 /dev/sda";
|
||||||
|
description =
|
||||||
|
''
|
||||||
|
Commands executed when the machine powers down. That is,
|
||||||
|
they're executed both when the system shuts down and when
|
||||||
|
it goes to suspend or hibernation.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -107,6 +107,7 @@
|
|||||||
./services/networking/ssh/sshd.nix
|
./services/networking/ssh/sshd.nix
|
||||||
./services/networking/tftpd.nix
|
./services/networking/tftpd.nix
|
||||||
./services/networking/vsftpd.nix
|
./services/networking/vsftpd.nix
|
||||||
|
./services/networking/wakeonlan.nix
|
||||||
./services/networking/wicd.nix
|
./services/networking/wicd.nix
|
||||||
./services/networking/wpa_supplicant.nix
|
./services/networking/wpa_supplicant.nix
|
||||||
./services/networking/xinetd.nix
|
./services/networking/xinetd.nix
|
||||||
|
56
modules/services/networking/wakeonlan.nix
Normal file
56
modules/services/networking/wakeonlan.nix
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
{ config, pkgs, ... }:
|
||||||
|
|
||||||
|
with pkgs.lib;
|
||||||
|
|
||||||
|
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";
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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:
|
||||||
|
"magickey" and "password". The password has the shape of six bytes
|
||||||
|
in hexadecimal separated by a colon each. For more information,
|
||||||
|
check the ethtool manual.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
###### implementation
|
||||||
|
|
||||||
|
config.powerManagement.powerDownCommands = lines;
|
||||||
|
|
||||||
|
}
|
@ -30,6 +30,8 @@ with pkgs.lib;
|
|||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
${config.powerManagement.powerDownCommands}
|
||||||
|
|
||||||
export PATH=${pkgs.utillinux}/bin:${pkgs.utillinux}/sbin:$PATH
|
export PATH=${pkgs.utillinux}/bin:${pkgs.utillinux}/sbin:$PATH
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user