diff --git a/boot/boot-stage-2.nix b/boot/boot-stage-2.nix index d5f4f4bacf6..bdccabc3605 100644 --- a/boot/boot-stage-2.nix +++ b/boot/boot-stage-2.nix @@ -23,5 +23,5 @@ substituteAll { udev upstart ]; - bootLocal = writeText "boot.local" bootLocal; + bootLocal = writeText "local-cmds" bootLocal; } diff --git a/system/options.nix b/system/options.nix index ad916a2008f..3cdcf96e092 100644 --- a/system/options.nix +++ b/system/options.nix @@ -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 + network-interfaces Upstart job. Note that if + you are using DHCP to obtain the network configuration, + interfaces may not be fully configured yet. + "; + } + + { name = ["fileSystems"]; default = []; diff --git a/upstart-jobs/default.nix b/upstart-jobs/default.nix index 70193768378..956dacab0e2 100644 --- a/upstart-jobs/default.nix +++ b/upstart-jobs/default.nix @@ -67,10 +67,11 @@ import ../upstart-jobs/gather.nix { # Network interfaces. (import ../upstart-jobs/network-interfaces.nix { inherit modprobe; - inherit (pkgs) nettools wirelesstools; + inherit (pkgs) nettools wirelesstools bash writeText; nameservers = config.get ["networking" "nameservers"]; defaultGateway = config.get ["networking" "defaultGateway"]; interfaces = config.get ["networking" "interfaces"]; + localCommands = config.get ["networking" "localCommands"]; }) # Nix daemon - required for multi-user Nix. diff --git a/upstart-jobs/network-interfaces.nix b/upstart-jobs/network-interfaces.nix index c3f3bfad5ad..b3f06124310 100644 --- a/upstart-jobs/network-interfaces.nix +++ b/upstart-jobs/network-interfaces.nix @@ -1,5 +1,6 @@ -{ nettools, modprobe, wirelesstools +{ nettools, modprobe, wirelesstools, bash, writeText , nameservers, defaultGateway, interfaces +, localCommands }: let @@ -21,7 +22,8 @@ start on hardware-scan stop on shutdown 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 echo \"Bringing up network device $i...\" @@ -43,7 +45,7 @@ start script wepKey=\${wepKeys[$n]} # Set wireless networking stuff. - if test \"$essid\" != dhcp; then + if test \"$essid\" != default; then ${wirelesstools}/sbin/iwconfig \"$name\" essid \"$essid\" || true fi @@ -76,6 +78,9 @@ start script ${nettools}/sbin/route add default gw \"${defaultGateway}\" || true fi + # Run any user-specified commands. + ${bash}/bin/sh ${writeText "local-net-cmds" localCommands} || true + end script # Hack: Upstart doesn't yet support what we want: a service that