Adding a wake on lan module.

svn path=/nixos/trunk/; revision=24958
This commit is contained in:
Lluís Batlle i Rossell 2010-12-02 20:23:45 +00:00
parent 651a38019d
commit d5fb41795f
4 changed files with 79 additions and 4 deletions

View file

@ -10,9 +10,14 @@ let
''
#! ${pkgs.stdenv.shell}
action="$1"
if [ "$action" = "resume" ]; then
${cfg.resumeCommands}
${cfg.powerUpCommands}
case "$action" in
hibernate|suspend)
${cfg.powerDownCommands}
;;
thaw|resume)
${cfg.resumeCommands}
${cfg.powerUpCommands}
;;
fi
'';
@ -50,6 +55,17 @@ in
it resumes from suspend or hibernation.
'';
};
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.
'';
};
};

View file

@ -107,6 +107,7 @@
./services/networking/ssh/sshd.nix
./services/networking/tftpd.nix
./services/networking/vsftpd.nix
./services/networking/wakeonlan.nix
./services/networking/wicd.nix
./services/networking/wpa_supplicant.nix
./services/networking/xinetd.nix

View 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;
}

View file

@ -29,9 +29,11 @@ with pkgs.lib;
echo "<<< System shutdown >>>"
fi
echo ""
${config.powerManagement.powerDownCommands}
export PATH=${pkgs.utillinux}/bin:${pkgs.utillinux}/sbin:$PATH
# Do an initial sync just in case.
sync