* Allow manual network configuration, i.e., specificying the IP
address, gateway, and nameservers in the system configuration. svn path=/nixos/trunk/; revision=7898
This commit is contained in:
parent
d4c172469d
commit
06a6116c44
|
@ -201,10 +201,9 @@
|
|||
name = ["networking" "interfaces"];
|
||||
default = [];
|
||||
example = [
|
||||
{ interface = "eth0";
|
||||
{ name = "eth0";
|
||||
ipAddress = "131.211.84.78";
|
||||
netmask = "255.255.255.128";
|
||||
gateway = "131.211.84.1";
|
||||
}
|
||||
];
|
||||
description = "
|
||||
|
@ -215,6 +214,26 @@
|
|||
}
|
||||
|
||||
|
||||
{
|
||||
name = ["networking" "defaultGateway"];
|
||||
default = "";
|
||||
example = "131.211.84.1";
|
||||
description = "
|
||||
The default gateway. It can be left empty if it is auto-detected through DHCP.
|
||||
";
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
name = ["networking" "nameservers"];
|
||||
default = [];
|
||||
example = ["130.161.158.4" "130.161.33.17"];
|
||||
description = "
|
||||
The list of nameservers. It can be left empty if it is auto-detected through DHCP.
|
||||
";
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
name = ["fileSystems"];
|
||||
default = [];
|
||||
|
|
|
@ -59,14 +59,11 @@ import ../upstart-jobs/gather.nix {
|
|||
# Network interfaces.
|
||||
(import ../upstart-jobs/network-interfaces.nix {
|
||||
inherit (pkgs) nettools kernel module_init_tools;
|
||||
nameservers = config.get ["networking" "nameservers"];
|
||||
defaultGateway = config.get ["networking" "defaultGateway"];
|
||||
interfaces = config.get ["networking" "interfaces"];
|
||||
})
|
||||
|
||||
# DHCP client.
|
||||
(import ../upstart-jobs/dhclient.nix {
|
||||
inherit (pkgs) nettools;
|
||||
dhcp = pkgs.dhcpWrapper;
|
||||
})
|
||||
|
||||
# Nix daemon - required for multi-user Nix.
|
||||
(import ../upstart-jobs/nix-daemon.nix {
|
||||
inherit nix;
|
||||
|
@ -93,6 +90,13 @@ import ../upstart-jobs/gather.nix {
|
|||
|
||||
]
|
||||
|
||||
# DHCP client.
|
||||
++ optional ["networking" "useDHCP"]
|
||||
(import ../upstart-jobs/dhclient.nix {
|
||||
inherit (pkgs) nettools;
|
||||
dhcp = pkgs.dhcpWrapper;
|
||||
})
|
||||
|
||||
# SSH daemon.
|
||||
++ optional ["services" "sshd" "enable"]
|
||||
(import ../upstart-jobs/sshd.nix {
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
# !!! Don't like it that I have to pass the kernel here.
|
||||
{nettools, kernel, module_init_tools}:
|
||||
{ nettools, kernel, module_init_tools
|
||||
, nameservers, defaultGateway, interfaces
|
||||
}:
|
||||
|
||||
let
|
||||
|
||||
# !!! use XML
|
||||
names = map (i: i.name) interfaces;
|
||||
ipAddresses = map (i: i.ipAddress) interfaces;
|
||||
|
||||
in
|
||||
|
||||
{
|
||||
name = "network-interfaces";
|
||||
|
@ -18,6 +28,30 @@ start script
|
|||
${nettools}/sbin/ifconfig $i up || true
|
||||
done
|
||||
|
||||
# Configure the manually specified interfaces.
|
||||
names=(${toString names})
|
||||
ipAddresses=(${toString ipAddresses})
|
||||
|
||||
for ((n = 0; n < \${#names[*]}; n++)); do
|
||||
name=\${names[$n]}
|
||||
ipAddress=\${ipAddresses[$n]}
|
||||
echo \"Configuring interface $i...\"
|
||||
${nettools}/sbin/ifconfig \"$name\" up \"$ipAddress\" || true
|
||||
done
|
||||
|
||||
# Set the nameservers.
|
||||
if test -n \"${toString nameservers}\"; then
|
||||
rm -f /etc/resolv.conf
|
||||
for i in ${toString nameservers}; do
|
||||
echo \"nameserver $i\" >> /etc/resolv.conf
|
||||
done
|
||||
fi
|
||||
|
||||
# Set the default gateway.
|
||||
if test -n \"${defaultGateway}\"; then
|
||||
${nettools}/sbin/route add default gw \"${defaultGateway}\" || true
|
||||
fi
|
||||
|
||||
end script
|
||||
|
||||
# Hack: Upstart doesn't yet support what we want: a service that
|
||||
|
|
Loading…
Reference in a new issue