* Give a type to networking.interfaces.
* Simplified the pre-start script of the network-interfaces module. * Removed wireless support from the network-interfaces module. It only worked for static WEP configurations anyway, and AFAIK nobody used it. svn path=/nixos/branches/modular-nixos/; revision=16406
This commit is contained in:
parent
f53c9d70ec
commit
b58682401e
@ -53,22 +53,6 @@ in
|
|||||||
";
|
";
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.interfaces = mkOption {
|
|
||||||
default = [];
|
|
||||||
merge = mergeListOption;
|
|
||||||
example = [
|
|
||||||
{ name = "eth0";
|
|
||||||
ipAddress = "131.211.84.78";
|
|
||||||
subnetMask = "255.255.255.128";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
description = "
|
|
||||||
The configuration for each network interface. If
|
|
||||||
<option>networking.useDHCP</option> is true, then each interface
|
|
||||||
not listed here will be configured using DHCP.
|
|
||||||
";
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,168 +2,185 @@
|
|||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
inherit (pkgs.lib) mkOption;
|
inherit (pkgs.lib) mkOption types;
|
||||||
|
|
||||||
|
inherit (pkgs) nettools;
|
||||||
|
|
||||||
###### interface
|
cfg = config.networking;
|
||||||
|
|
||||||
|
in
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
###### interface
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
|
|
||||||
networking.hostName = mkOption {
|
networking.hostName = mkOption {
|
||||||
default = "nixos";
|
default = "nixos";
|
||||||
description = "
|
description = ''
|
||||||
The name of the machine. Leave it empty if you want to obtain
|
The name of the machine. Leave it empty if you want to obtain
|
||||||
it from a DHCP server (if using DHCP).
|
it from a DHCP server (if using DHCP).
|
||||||
";
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.nativeIPv6 = mkOption {
|
networking.nativeIPv6 = mkOption {
|
||||||
default = false;
|
default = false;
|
||||||
description = "
|
description = ''
|
||||||
Whether to use IPv6 even though gw6c is not used. For example,
|
Whether to use IPv6 even though gw6c is not used. For example,
|
||||||
for Postfix.
|
for Postfix.
|
||||||
";
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.defaultGateway = mkOption {
|
networking.defaultGateway = mkOption {
|
||||||
default = "";
|
default = "";
|
||||||
example = "131.211.84.1";
|
example = "131.211.84.1";
|
||||||
description = "
|
description = ''
|
||||||
The default gateway. It can be left empty if it is auto-detected through DHCP.
|
The default gateway. It can be left empty if it is auto-detected through DHCP.
|
||||||
";
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.nameservers = mkOption {
|
networking.nameservers = mkOption {
|
||||||
default = [];
|
default = [];
|
||||||
example = ["130.161.158.4" "130.161.33.17"];
|
example = ["130.161.158.4" "130.161.33.17"];
|
||||||
description = "
|
description = ''
|
||||||
The list of nameservers. It can be left empty if it is auto-detected through DHCP.
|
The list of nameservers. It can be left empty if it is auto-detected through DHCP.
|
||||||
";
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.domain = mkOption {
|
networking.domain = mkOption {
|
||||||
default = "";
|
default = "";
|
||||||
example = "home";
|
example = "home";
|
||||||
description = "
|
description = ''
|
||||||
The domain. It can be left empty if it is auto-detected through DHCP.
|
The domain. It can be left empty if it is auto-detected through DHCP.
|
||||||
";
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.localCommands = mkOption {
|
networking.localCommands = mkOption {
|
||||||
default = "";
|
default = "";
|
||||||
example = "text=anything; echo You can put $text here.";
|
example = "text=anything; echo You can put $text here.";
|
||||||
description = "
|
description = ''
|
||||||
Shell commands to be executed at the end of the
|
Shell commands to be executed at the end of the
|
||||||
<literal>network-interfaces</literal> Upstart job. Note that if
|
<literal>network-interfaces</literal> Upstart job. Note that if
|
||||||
you are using DHCP to obtain the network configuration,
|
you are using DHCP to obtain the network configuration,
|
||||||
interfaces may not be fully configured yet.
|
interfaces may not be fully configured yet.
|
||||||
";
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
networking.interfaces = mkOption {
|
||||||
|
default = [];
|
||||||
|
example = [
|
||||||
|
{ name = "eth0";
|
||||||
|
ipAddress = "131.211.84.78";
|
||||||
|
subnetMask = "255.255.255.128";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
description = ''
|
||||||
|
The configuration for each network interface. If
|
||||||
|
<option>networking.useDHCP</option> is true, then every
|
||||||
|
interface not listed here will be configured using DHCP.
|
||||||
|
'';
|
||||||
|
|
||||||
|
type = types.list types.optionSet;
|
||||||
|
|
||||||
|
options = {
|
||||||
|
|
||||||
|
name = mkOption {
|
||||||
|
example = "eth0";
|
||||||
|
type = types.string;
|
||||||
|
description = ''
|
||||||
|
Name of the interface.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
ipAddress = mkOption {
|
||||||
|
default = "";
|
||||||
|
example = "10.0.0.1";
|
||||||
|
type = types.string;
|
||||||
|
description = ''
|
||||||
|
IP address of the interface. Leave empty to configure the
|
||||||
|
interface using DHCP.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
subnetMask = mkOption {
|
||||||
|
default = "";
|
||||||
|
example = "255.255.255.0";
|
||||||
|
type = types.string;
|
||||||
|
description = ''
|
||||||
|
Subnet mask of the interface. Leave empty to use the
|
||||||
|
default subnet mask.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
inherit (pkgs) nettools wirelesstools bash writeText;
|
config = {
|
||||||
|
|
||||||
cfg = config.networking;
|
jobs = pkgs.lib.singleton
|
||||||
|
{ name = "network-interfaces";
|
||||||
|
|
||||||
# !!! use XML
|
startOn = "udev";
|
||||||
names = map (i: i.name) cfg.interfaces;
|
|
||||||
ipAddresses = map (i: if i ? ipAddress then i.ipAddress else "dhcp") 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;
|
|
||||||
wepKeys = map (i: if i ? wepKey then i.wepKey else "nokey") cfg.interfaces;
|
|
||||||
modprobe = config.system.sbin.modprobe;
|
|
||||||
|
|
||||||
in
|
preStart =
|
||||||
|
''
|
||||||
|
export PATH=${config.system.sbin.modprobe}/sbin:$PATH
|
||||||
|
modprobe af_packet || true
|
||||||
|
|
||||||
{
|
for i in $(cd /sys/class/net && ls -d *); do
|
||||||
require = [options];
|
echo "Bringing up network device $i..."
|
||||||
|
${nettools}/sbin/ifconfig $i up || true
|
||||||
|
done
|
||||||
|
|
||||||
services.extraJobs = [{
|
# Configure the manually specified interfaces.
|
||||||
name = "network-interfaces";
|
${pkgs.lib.concatMapStrings (i:
|
||||||
|
if i.ipAddress != "" then
|
||||||
job = ''
|
''
|
||||||
start on udev
|
echo "Configuring interface ${i.name}..."
|
||||||
stop on shutdown
|
|
||||||
|
|
||||||
start script
|
|
||||||
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..."
|
|
||||||
${nettools}/sbin/ifconfig $i up || true
|
|
||||||
done
|
|
||||||
|
|
||||||
# Configure the manually specified interfaces.
|
|
||||||
names=(${toString names})
|
|
||||||
ipAddresses=(${toString ipAddresses})
|
|
||||||
subnetMasks=(${toString subnetMasks})
|
|
||||||
essids=(${toString essids})
|
|
||||||
wepKeys=(${toString wepKeys})
|
|
||||||
|
|
||||||
for ((n = 0; n < ''${#names[*]}; n++)); do
|
|
||||||
name=''${names[$n]}
|
|
||||||
ipAddress=''${ipAddresses[$n]}
|
|
||||||
subnetMask=''${subnetMasks[$n]}
|
|
||||||
essid=''${essids[$n]}
|
|
||||||
wepKey=''${wepKeys[$n]}
|
|
||||||
|
|
||||||
# Set wireless networking stuff.
|
|
||||||
if test "$essid" != default; then
|
|
||||||
${wirelesstools}/sbin/iwconfig "$name" essid "$essid" || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test "$wepKey" != nokey; then
|
|
||||||
${wirelesstools}/sbin/iwconfig "$name" key "$(cat "$wepKey")" || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Set IP address / netmask.
|
|
||||||
if test "$ipAddress" != dhcp; then
|
|
||||||
echo "Configuring interface $name..."
|
|
||||||
extraFlags=
|
extraFlags=
|
||||||
if test "$subnetMask" != default; then
|
if test -n "${i.subnetMask}"; then
|
||||||
extraFlags="$extraFlags netmask $subnetMask"
|
extraFlags="$extraFlags netmask ${i.subnetMask}"
|
||||||
fi
|
fi
|
||||||
${nettools}/sbin/ifconfig "$name" "$ipAddress" $extraFlags || true
|
${nettools}/sbin/ifconfig "${i.name}" "${i.ipAddress}" $extraFlags || true
|
||||||
fi
|
''
|
||||||
|
else "") cfg.interfaces}
|
||||||
|
|
||||||
done
|
# Set the nameservers.
|
||||||
|
if test -n "${toString cfg.nameservers}"; then
|
||||||
|
rm -f /etc/resolv.conf
|
||||||
|
if test -n "${cfg.domain}"; then
|
||||||
|
echo "domain ${cfg.domain}" >> /etc/resolv.conf
|
||||||
|
fi
|
||||||
|
for i in ${toString cfg.nameservers}; do
|
||||||
|
echo "nameserver $i" >> /etc/resolv.conf
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
# Set the nameservers.
|
# Set the default gateway.
|
||||||
if test -n "${toString cfg.nameservers}"; then
|
if test -n "${cfg.defaultGateway}"; then
|
||||||
rm -f /etc/resolv.conf
|
${nettools}/sbin/route add default gw "${cfg.defaultGateway}" || true
|
||||||
if test -n "${cfg.domain}"; then
|
fi
|
||||||
echo "domain ${cfg.domain}" >> /etc/resolv.conf
|
|
||||||
fi
|
|
||||||
for i in ${toString cfg.nameservers}; do
|
|
||||||
echo "nameserver $i" >> /etc/resolv.conf
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Set the default gateway.
|
# Run any user-specified commands.
|
||||||
if test -n "${cfg.defaultGateway}"; then
|
${pkgs.stdenv.shell} ${pkgs.writeText "local-net-cmds" cfg.localCommands} || true
|
||||||
${nettools}/sbin/route add default gw "${cfg.defaultGateway}" || true
|
'';
|
||||||
fi
|
|
||||||
|
|
||||||
# Run any user-specified commands.
|
postStop =
|
||||||
${bash}/bin/sh ${writeText "local-net-cmds" cfg.localCommands} || true
|
''
|
||||||
|
#for i in $(cd /sys/class/net && ls -d *); do
|
||||||
|
# echo "Taking down network device $i..."
|
||||||
|
# ${nettools}/sbin/ifconfig $i down || true
|
||||||
|
#done
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
end script
|
};
|
||||||
|
|
||||||
# Hack: Upstart doesn't yet support what we want: a service that
|
|
||||||
# doesn't have a running process associated with it.
|
|
||||||
respawn sleep 100000
|
|
||||||
|
|
||||||
stop script
|
|
||||||
#for i in $(cd /sys/class/net && ls -d *); do
|
|
||||||
# echo "Taking down network device $i..."
|
|
||||||
# ${nettools}/sbin/ifconfig $i down || true
|
|
||||||
#done
|
|
||||||
end script
|
|
||||||
'';
|
|
||||||
}];
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user