* Option `networking.localCommands' to specify shell commands to be

executed after the network interfaces have been initialised.

svn path=/nixos/trunk/; revision=8752
This commit is contained in:
Eelco Dolstra 2007-05-24 14:50:17 +00:00
parent 4f5de40814
commit aab8fda25a
4 changed files with 24 additions and 5 deletions

View File

@ -23,5 +23,5 @@ substituteAll {
udev udev
upstart upstart
]; ];
bootLocal = writeText "boot.local" bootLocal; bootLocal = writeText "local-cmds" bootLocal;
} }

View File

@ -257,6 +257,19 @@
} }
{
name = ["networking" "localCommands"];
default = "";
example = "text=anything; echo You can put $text here.";
description = "
Shell commands to be executed at the end of the
<literal>network-interfaces</literal> Upstart job. Note that if
you are using DHCP to obtain the network configuration,
interfaces may not be fully configured yet.
";
}
{ {
name = ["fileSystems"]; name = ["fileSystems"];
default = []; default = [];

View File

@ -67,10 +67,11 @@ import ../upstart-jobs/gather.nix {
# Network interfaces. # Network interfaces.
(import ../upstart-jobs/network-interfaces.nix { (import ../upstart-jobs/network-interfaces.nix {
inherit modprobe; inherit modprobe;
inherit (pkgs) nettools wirelesstools; inherit (pkgs) nettools wirelesstools bash writeText;
nameservers = config.get ["networking" "nameservers"]; nameservers = config.get ["networking" "nameservers"];
defaultGateway = config.get ["networking" "defaultGateway"]; defaultGateway = config.get ["networking" "defaultGateway"];
interfaces = config.get ["networking" "interfaces"]; interfaces = config.get ["networking" "interfaces"];
localCommands = config.get ["networking" "localCommands"];
}) })
# Nix daemon - required for multi-user Nix. # Nix daemon - required for multi-user Nix.

View File

@ -1,5 +1,6 @@
{ nettools, modprobe, wirelesstools { nettools, modprobe, wirelesstools, bash, writeText
, nameservers, defaultGateway, interfaces , nameservers, defaultGateway, interfaces
, localCommands
}: }:
let let
@ -21,7 +22,8 @@ start on hardware-scan
stop on shutdown stop on shutdown
start script start script
${modprobe}/sbin/modprobe af_packet || true export PATH=${modprobe}/sbin:$PATH
modprobe af_packet || true
for i in $(cd /sys/class/net && ls -d *); do for i in $(cd /sys/class/net && ls -d *); do
echo \"Bringing up network device $i...\" echo \"Bringing up network device $i...\"
@ -43,7 +45,7 @@ start script
wepKey=\${wepKeys[$n]} wepKey=\${wepKeys[$n]}
# Set wireless networking stuff. # Set wireless networking stuff.
if test \"$essid\" != dhcp; then if test \"$essid\" != default; then
${wirelesstools}/sbin/iwconfig \"$name\" essid \"$essid\" || true ${wirelesstools}/sbin/iwconfig \"$name\" essid \"$essid\" || true
fi fi
@ -76,6 +78,9 @@ start script
${nettools}/sbin/route add default gw \"${defaultGateway}\" || true ${nettools}/sbin/route add default gw \"${defaultGateway}\" || true
fi fi
# Run any user-specified commands.
${bash}/bin/sh ${writeText "local-net-cmds" localCommands} || true
end script end script
# Hack: Upstart doesn't yet support what we want: a service that # Hack: Upstart doesn't yet support what we want: a service that