* 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"];
|
name = ["networking" "interfaces"];
|
||||||
default = [];
|
default = [];
|
||||||
example = [
|
example = [
|
||||||
{ interface = "eth0";
|
{ name = "eth0";
|
||||||
ipAddress = "131.211.84.78";
|
ipAddress = "131.211.84.78";
|
||||||
netmask = "255.255.255.128";
|
netmask = "255.255.255.128";
|
||||||
gateway = "131.211.84.1";
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
description = "
|
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"];
|
name = ["fileSystems"];
|
||||||
default = [];
|
default = [];
|
||||||
|
@ -59,14 +59,11 @@ import ../upstart-jobs/gather.nix {
|
|||||||
# Network interfaces.
|
# Network interfaces.
|
||||||
(import ../upstart-jobs/network-interfaces.nix {
|
(import ../upstart-jobs/network-interfaces.nix {
|
||||||
inherit (pkgs) nettools kernel module_init_tools;
|
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.
|
# Nix daemon - required for multi-user Nix.
|
||||||
(import ../upstart-jobs/nix-daemon.nix {
|
(import ../upstart-jobs/nix-daemon.nix {
|
||||||
inherit 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.
|
# SSH daemon.
|
||||||
++ optional ["services" "sshd" "enable"]
|
++ optional ["services" "sshd" "enable"]
|
||||||
(import ../upstart-jobs/sshd.nix {
|
(import ../upstart-jobs/sshd.nix {
|
||||||
|
@ -1,5 +1,15 @@
|
|||||||
# !!! Don't like it that I have to pass the kernel here.
|
# !!! 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";
|
name = "network-interfaces";
|
||||||
@ -18,6 +28,30 @@ start script
|
|||||||
${nettools}/sbin/ifconfig $i up || true
|
${nettools}/sbin/ifconfig $i up || true
|
||||||
done
|
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
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user