Author: viric
Date: Thu Dec 2 20:23:45 2010
New Revision: 24958
URL: https://svn.nixos.org/websvn/nix/?rev=24958&sc=1
Log:
Adding a wake on lan module.
Added:
nixos/trunk/modules/services/networking/wakeonlan.nix
Modified:
nixos/trunk/modules/config/power-management.nix
nixos/trunk/modules/module-list.nix
nixos/trunk/modules/system/upstart-events/shutdown.nix
Modified: nixos/trunk/modules/config/power-management.nix
==============================================================================
--- nixos/trunk/modules/config/power-management.nix Thu Dec 2 18:13:19
2010 (r24957)
+++ nixos/trunk/modules/config/power-management.nix Thu Dec 2 20:23:45
2010 (r24958)
@@ -10,9 +10,14 @@
''
#! ${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 @@
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.
+ '';
+ };
};
Modified: nixos/trunk/modules/module-list.nix
==============================================================================
--- nixos/trunk/modules/module-list.nix Thu Dec 2 18:13:19 2010 (r24957)
+++ nixos/trunk/modules/module-list.nix Thu Dec 2 20:23:45 2010 (r24958)
@@ -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
Added: nixos/trunk/modules/services/networking/wakeonlan.nix
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ nixos/trunk/modules/services/networking/wakeonlan.nix Thu Dec 2
20:23:45 2010 (r24958)
@@ -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;
+
+}
Modified: nixos/trunk/modules/system/upstart-events/shutdown.nix
==============================================================================
--- nixos/trunk/modules/system/upstart-events/shutdown.nix Thu Dec 2
18:13:19 2010 (r24957)
+++ nixos/trunk/modules/system/upstart-events/shutdown.nix Thu Dec 2
20:23:45 2010 (r24958)
@@ -29,9 +29,11 @@
echo "[1;32m<<< System shutdown >>>[0m"
fi
echo ""
+
+ ${config.powerManagement.powerDownCommands}
export PATH=${pkgs.utillinux}/bin:${pkgs.utillinux}/sbin:$PATH
-
+
# Do an initial sync just in case.
sync
_______________________________________________
nix-commits mailing list
[email protected]
http://mail.cs.uu.nl/mailman/listinfo/nix-commits