Convert "nework-interfaces"
svn path=/nixos/branches/fix-style/; revision=14403
This commit is contained in:
parent
ed8bfc1c78
commit
4963abf63e
@ -423,6 +423,7 @@ in
|
|||||||
(import ../upstart-jobs/filesystems.nix) # Mount file systems.
|
(import ../upstart-jobs/filesystems.nix) # Mount file systems.
|
||||||
|
|
||||||
(import ../upstart-jobs/swap.nix)
|
(import ../upstart-jobs/swap.nix)
|
||||||
|
(import ../upstart-jobs/network-interfaces.nix)
|
||||||
|
|
||||||
|
|
||||||
# security
|
# security
|
||||||
|
@ -71,12 +71,6 @@ let
|
|||||||
jobs = map makeJob
|
jobs = map makeJob
|
||||||
([
|
([
|
||||||
|
|
||||||
# Network interfaces.
|
|
||||||
(import ../upstart-jobs/network-interfaces.nix {
|
|
||||||
inherit modprobe config;
|
|
||||||
inherit (pkgs) nettools wirelesstools bash writeText;
|
|
||||||
})
|
|
||||||
|
|
||||||
# Name service cache daemon.
|
# Name service cache daemon.
|
||||||
(import ../upstart-jobs/nscd.nix {
|
(import ../upstart-jobs/nscd.nix {
|
||||||
inherit (pkgs) glibc;
|
inherit (pkgs) glibc;
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
{nettools, modprobe, wirelesstools, bash, writeText, config}:
|
{pkgs, config, ...}:
|
||||||
|
|
||||||
|
###### implementation
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
|
inherit (pkgs) nettools wirelesstools bash writeText;
|
||||||
|
|
||||||
cfg = config.networking;
|
cfg = config.networking;
|
||||||
|
|
||||||
# !!! use XML
|
# !!! use XML
|
||||||
@ -10,91 +14,96 @@ let
|
|||||||
subnetMasks = map (i: if i ? subnetMask then i.subnetMask else "default") cfg.interfaces;
|
subnetMasks = map (i: if i ? subnetMask then i.subnetMask else "default") cfg.interfaces;
|
||||||
essids = map (i: if i ? essid then i.essid else "default") cfg.interfaces;
|
essids = map (i: if i ? essid then i.essid else "default") cfg.interfaces;
|
||||||
wepKeys = map (i: if i ? wepKey then i.wepKey else "nokey") cfg.interfaces;
|
wepKeys = map (i: if i ? wepKey then i.wepKey else "nokey") cfg.interfaces;
|
||||||
|
modprobe = config.system.sbin.modprobe;
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
name = "network-interfaces";
|
services = {
|
||||||
|
extraJobs = [{
|
||||||
job = ''
|
name = "network-interfaces";
|
||||||
start on udev
|
|
||||||
stop on shutdown
|
job = ''
|
||||||
|
start on udev
|
||||||
start script
|
stop on shutdown
|
||||||
export PATH=${modprobe}/sbin:$PATH
|
|
||||||
modprobe af_packet || true
|
start script
|
||||||
|
export PATH=${modprobe}/sbin:$PATH
|
||||||
for i in $(cd /sys/class/net && ls -d *); do
|
modprobe af_packet || true
|
||||||
echo "Bringing up network device $i..."
|
|
||||||
${nettools}/sbin/ifconfig $i up || true
|
for i in $(cd /sys/class/net && ls -d *); do
|
||||||
done
|
echo "Bringing up network device $i..."
|
||||||
|
${nettools}/sbin/ifconfig $i up || true
|
||||||
# Configure the manually specified interfaces.
|
done
|
||||||
names=(${toString names})
|
|
||||||
ipAddresses=(${toString ipAddresses})
|
# Configure the manually specified interfaces.
|
||||||
subnetMasks=(${toString subnetMasks})
|
names=(${toString names})
|
||||||
essids=(${toString essids})
|
ipAddresses=(${toString ipAddresses})
|
||||||
wepKeys=(${toString wepKeys})
|
subnetMasks=(${toString subnetMasks})
|
||||||
|
essids=(${toString essids})
|
||||||
for ((n = 0; n < ''${#names[*]}; n++)); do
|
wepKeys=(${toString wepKeys})
|
||||||
name=''${names[$n]}
|
|
||||||
ipAddress=''${ipAddresses[$n]}
|
for ((n = 0; n < ''${#names[*]}; n++)); do
|
||||||
subnetMask=''${subnetMasks[$n]}
|
name=''${names[$n]}
|
||||||
essid=''${essids[$n]}
|
ipAddress=''${ipAddresses[$n]}
|
||||||
wepKey=''${wepKeys[$n]}
|
subnetMask=''${subnetMasks[$n]}
|
||||||
|
essid=''${essids[$n]}
|
||||||
# Set wireless networking stuff.
|
wepKey=''${wepKeys[$n]}
|
||||||
if test "$essid" != default; then
|
|
||||||
${wirelesstools}/sbin/iwconfig "$name" essid "$essid" || true
|
# Set wireless networking stuff.
|
||||||
fi
|
if test "$essid" != default; then
|
||||||
|
${wirelesstools}/sbin/iwconfig "$name" essid "$essid" || true
|
||||||
if test "$wepKey" != nokey; then
|
fi
|
||||||
${wirelesstools}/sbin/iwconfig "$name" key "$(cat "$wepKey")" || true
|
|
||||||
fi
|
if test "$wepKey" != nokey; then
|
||||||
|
${wirelesstools}/sbin/iwconfig "$name" key "$(cat "$wepKey")" || true
|
||||||
# Set IP address / netmask.
|
fi
|
||||||
if test "$ipAddress" != dhcp; then
|
|
||||||
echo "Configuring interface $name..."
|
# Set IP address / netmask.
|
||||||
extraFlags=
|
if test "$ipAddress" != dhcp; then
|
||||||
if test "$subnetMask" != default; then
|
echo "Configuring interface $name..."
|
||||||
extraFlags="$extraFlags netmask $subnetMask"
|
extraFlags=
|
||||||
fi
|
if test "$subnetMask" != default; then
|
||||||
${nettools}/sbin/ifconfig "$name" "$ipAddress" $extraFlags || true
|
extraFlags="$extraFlags netmask $subnetMask"
|
||||||
fi
|
fi
|
||||||
|
${nettools}/sbin/ifconfig "$name" "$ipAddress" $extraFlags || true
|
||||||
done
|
fi
|
||||||
|
|
||||||
# Set the nameservers.
|
done
|
||||||
if test -n "${toString cfg.nameservers}"; then
|
|
||||||
rm -f /etc/resolv.conf
|
# Set the nameservers.
|
||||||
if test -n "${cfg.domain}"; then
|
if test -n "${toString cfg.nameservers}"; then
|
||||||
echo "domain ${cfg.domain}" >> /etc/resolv.conf
|
rm -f /etc/resolv.conf
|
||||||
fi
|
if test -n "${cfg.domain}"; then
|
||||||
for i in ${toString cfg.nameservers}; do
|
echo "domain ${cfg.domain}" >> /etc/resolv.conf
|
||||||
echo "nameserver $i" >> /etc/resolv.conf
|
fi
|
||||||
done
|
for i in ${toString cfg.nameservers}; do
|
||||||
fi
|
echo "nameserver $i" >> /etc/resolv.conf
|
||||||
|
done
|
||||||
# Set the default gateway.
|
fi
|
||||||
if test -n "${cfg.defaultGateway}"; then
|
|
||||||
${nettools}/sbin/route add default gw "${cfg.defaultGateway}" || true
|
# Set the default gateway.
|
||||||
fi
|
if test -n "${cfg.defaultGateway}"; then
|
||||||
|
${nettools}/sbin/route add default gw "${cfg.defaultGateway}" || true
|
||||||
# Run any user-specified commands.
|
fi
|
||||||
${bash}/bin/sh ${writeText "local-net-cmds" cfg.localCommands} || true
|
|
||||||
|
# Run any user-specified commands.
|
||||||
end script
|
${bash}/bin/sh ${writeText "local-net-cmds" cfg.localCommands} || true
|
||||||
|
|
||||||
# Hack: Upstart doesn't yet support what we want: a service that
|
end script
|
||||||
# doesn't have a running process associated with it.
|
|
||||||
respawn sleep 100000
|
# Hack: Upstart doesn't yet support what we want: a service that
|
||||||
|
# doesn't have a running process associated with it.
|
||||||
stop script
|
respawn sleep 100000
|
||||||
for i in $(cd /sys/class/net && ls -d *); do
|
|
||||||
echo "Taking down network device $i..."
|
stop script
|
||||||
${nettools}/sbin/ifconfig $i down || true
|
for i in $(cd /sys/class/net && ls -d *); do
|
||||||
done
|
echo "Taking down network device $i..."
|
||||||
end script
|
${nettools}/sbin/ifconfig $i down || true
|
||||||
'';
|
done
|
||||||
|
end script
|
||||||
|
'';
|
||||||
|
}];
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user