2009-10-12 19:27:57 +02:00
|
|
|
|
{ config, pkgs, ... }:
|
2009-03-06 13:27:38 +01:00
|
|
|
|
|
2009-10-12 19:27:57 +02:00
|
|
|
|
with pkgs.lib;
|
2007-02-12 17:00:55 +01:00
|
|
|
|
|
2009-10-12 19:27:57 +02:00
|
|
|
|
let
|
2009-05-28 18:03:48 +02:00
|
|
|
|
|
2009-07-16 19:18:54 +02:00
|
|
|
|
cfg = config.networking;
|
2012-11-02 17:08:11 +01:00
|
|
|
|
interfaces = attrValues cfg.interfaces;
|
|
|
|
|
hasVirtuals = any (i: i.virtual) interfaces;
|
|
|
|
|
|
|
|
|
|
interfaceOpts = { name, ... }: {
|
|
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
|
example = "eth0";
|
2013-10-30 11:02:04 +01:00
|
|
|
|
type = types.str;
|
2012-11-02 17:08:11 +01:00
|
|
|
|
description = "Name of the interface.";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ipAddress = mkOption {
|
|
|
|
|
default = null;
|
|
|
|
|
example = "10.0.0.1";
|
2013-10-30 11:02:04 +01:00
|
|
|
|
type = types.nullOr (types.str);
|
2012-11-02 17:08:11 +01:00
|
|
|
|
description = ''
|
|
|
|
|
IP address of the interface. Leave empty to configure the
|
|
|
|
|
interface using DHCP.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
prefixLength = mkOption {
|
|
|
|
|
default = null;
|
|
|
|
|
example = 24;
|
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
|
description = ''
|
|
|
|
|
Subnet mask of the interface, specified as the number of
|
|
|
|
|
bits in the prefix (<literal>24</literal>).
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
subnetMask = mkOption {
|
|
|
|
|
default = "";
|
|
|
|
|
example = "255.255.255.0";
|
2013-10-30 11:02:04 +01:00
|
|
|
|
type = types.str;
|
2012-11-02 17:08:11 +01:00
|
|
|
|
description = ''
|
|
|
|
|
Subnet mask of the interface, specified as a bitmask.
|
|
|
|
|
This is deprecated; use <option>prefixLength</option>
|
|
|
|
|
instead.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
macAddress = mkOption {
|
|
|
|
|
default = null;
|
|
|
|
|
example = "00:11:22:33:44:55";
|
2013-10-30 11:02:04 +01:00
|
|
|
|
type = types.nullOr (types.str);
|
2012-11-02 17:08:11 +01:00
|
|
|
|
description = ''
|
|
|
|
|
MAC address of the interface. Leave empty to use the default.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
virtual = mkOption {
|
|
|
|
|
default = false;
|
|
|
|
|
type = types.bool;
|
|
|
|
|
description = ''
|
|
|
|
|
Whether this interface is virtual and should be created by tunctl.
|
|
|
|
|
This is mainly useful for creating bridges between a host a virtual
|
|
|
|
|
network such as VPN or a virtual machine.
|
|
|
|
|
|
|
|
|
|
Defaults to tap device, unless interface contains "tun" in its name.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
virtualOwner = mkOption {
|
|
|
|
|
default = "root";
|
2013-10-30 11:02:04 +01:00
|
|
|
|
type = types.str;
|
2012-11-02 17:08:11 +01:00
|
|
|
|
description = ''
|
|
|
|
|
In case of a virtual device, the user who owns it.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
proxyARP = mkOption {
|
|
|
|
|
default = false;
|
|
|
|
|
type = types.bool;
|
|
|
|
|
description = ''
|
|
|
|
|
Turn on proxy_arp for this device (and proxy_ndp for ipv6).
|
|
|
|
|
This is mainly useful for creating pseudo-bridges between a real
|
|
|
|
|
interface and a virtual network such as VPN or a virtual machine for
|
|
|
|
|
interfaces that don't support real bridging (most wlan interfaces).
|
|
|
|
|
As ARP proxying acts slightly above the link-layer, below-ip traffic
|
|
|
|
|
isn't bridged, so things like DHCP won't work. The advantage above
|
|
|
|
|
using NAT lies in the fact that no IP addresses are shared, so all
|
|
|
|
|
hosts are reachable/routeable.
|
|
|
|
|
|
|
|
|
|
WARNING: turns on ip-routing, so if you have multiple interfaces, you
|
|
|
|
|
should think of the consequence and setup firewall rules to limit this.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
name = mkDefault name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
};
|
2009-07-16 19:18:54 +02:00
|
|
|
|
|
2011-09-14 20:20:50 +02:00
|
|
|
|
in
|
2009-07-16 19:18:54 +02:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
###### interface
|
2009-05-28 18:03:48 +02:00
|
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
|
|
networking.hostName = mkOption {
|
|
|
|
|
default = "nixos";
|
2009-07-16 19:18:54 +02:00
|
|
|
|
description = ''
|
2009-05-28 18:03:48 +02:00
|
|
|
|
The name of the machine. Leave it empty if you want to obtain
|
|
|
|
|
it from a DHCP server (if using DHCP).
|
2009-07-16 19:18:54 +02:00
|
|
|
|
'';
|
2009-05-28 18:03:48 +02:00
|
|
|
|
};
|
|
|
|
|
|
2011-02-19 18:21:29 +01:00
|
|
|
|
networking.enableIPv6 = mkOption {
|
|
|
|
|
default = true;
|
2009-07-16 19:18:54 +02:00
|
|
|
|
description = ''
|
2011-02-19 18:21:29 +01:00
|
|
|
|
Whether to enable support for IPv6.
|
2009-07-16 19:18:54 +02:00
|
|
|
|
'';
|
2009-05-28 18:03:48 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
networking.defaultGateway = mkOption {
|
|
|
|
|
default = "";
|
|
|
|
|
example = "131.211.84.1";
|
2009-07-16 19:18:54 +02:00
|
|
|
|
description = ''
|
2009-05-28 18:03:48 +02:00
|
|
|
|
The default gateway. It can be left empty if it is auto-detected through DHCP.
|
2009-07-16 19:18:54 +02:00
|
|
|
|
'';
|
2009-05-28 18:03:48 +02:00
|
|
|
|
};
|
|
|
|
|
|
2013-01-06 22:31:13 +01:00
|
|
|
|
networking.defaultGatewayWindowSize = mkOption {
|
2013-01-06 23:20:48 +01:00
|
|
|
|
default = null;
|
|
|
|
|
example = 524288;
|
|
|
|
|
type = types.nullOr types.int;
|
2013-01-06 22:31:13 +01:00
|
|
|
|
description = ''
|
|
|
|
|
The window size of the default gateway. It limits maximal data bursts that TCP peers
|
|
|
|
|
are allowed to send to us.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2009-05-28 18:03:48 +02:00
|
|
|
|
networking.nameservers = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
example = ["130.161.158.4" "130.161.33.17"];
|
2009-07-16 19:18:54 +02:00
|
|
|
|
description = ''
|
2009-05-28 18:03:48 +02:00
|
|
|
|
The list of nameservers. It can be left empty if it is auto-detected through DHCP.
|
2009-07-16 19:18:54 +02:00
|
|
|
|
'';
|
2009-05-28 18:03:48 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
networking.domain = mkOption {
|
|
|
|
|
default = "";
|
|
|
|
|
example = "home";
|
2009-07-16 19:18:54 +02:00
|
|
|
|
description = ''
|
2009-05-28 18:03:48 +02:00
|
|
|
|
The domain. It can be left empty if it is auto-detected through DHCP.
|
2009-07-16 19:18:54 +02:00
|
|
|
|
'';
|
2009-05-28 18:03:48 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
networking.localCommands = mkOption {
|
|
|
|
|
default = "";
|
|
|
|
|
example = "text=anything; echo You can put $text here.";
|
2009-07-16 19:18:54 +02:00
|
|
|
|
description = ''
|
2009-05-28 18:03:48 +02:00
|
|
|
|
Shell commands to be executed at the end of the
|
2013-04-11 14:23:35 +02:00
|
|
|
|
<literal>network-setup</literal> systemd service. Note that if
|
2009-05-28 18:03:48 +02:00
|
|
|
|
you are using DHCP to obtain the network configuration,
|
|
|
|
|
interfaces may not be fully configured yet.
|
2009-07-16 19:18:54 +02:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
networking.interfaces = mkOption {
|
2012-11-02 17:08:11 +01:00
|
|
|
|
default = {};
|
|
|
|
|
example =
|
|
|
|
|
{ eth0 = {
|
|
|
|
|
ipAddress = "131.211.84.78";
|
|
|
|
|
subnetMask = "255.255.255.128";
|
|
|
|
|
};
|
|
|
|
|
};
|
2009-07-16 19:18:54 +02:00
|
|
|
|
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.
|
|
|
|
|
'';
|
2012-11-02 17:08:11 +01:00
|
|
|
|
type = types.loaOf types.optionSet;
|
|
|
|
|
options = [ interfaceOpts ];
|
2010-05-21 16:12:03 +02:00
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
|
2011-03-15 16:13:48 +01:00
|
|
|
|
networking.bridges = mkOption {
|
|
|
|
|
default = { };
|
|
|
|
|
example =
|
|
|
|
|
{ br0.interfaces = [ "eth0" "eth1" ];
|
|
|
|
|
br1.interfaces = [ "eth2" "wlan0" ];
|
|
|
|
|
};
|
|
|
|
|
description =
|
|
|
|
|
''
|
|
|
|
|
This option allows you to define Ethernet bridge devices
|
|
|
|
|
that connect physical networks together. The value of this
|
|
|
|
|
option is an attribute set. Each attribute specifies a
|
|
|
|
|
bridge, with the attribute name specifying the name of the
|
|
|
|
|
bridge's network interface.
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
type = types.attrsOf types.optionSet;
|
|
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
|
|
interfaces = mkOption {
|
|
|
|
|
example = [ "eth0" "eth1" ];
|
|
|
|
|
type = types.listOf types.string;
|
|
|
|
|
description =
|
|
|
|
|
"The physical network interfaces connected by the bridge.";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
|
2011-03-15 16:13:48 +01:00
|
|
|
|
};
|
|
|
|
|
|
2012-02-20 15:29:21 +01:00
|
|
|
|
networking.useDHCP = mkOption {
|
2013-10-28 16:14:15 +01:00
|
|
|
|
type = types.bool;
|
2012-02-20 15:29:21 +01:00
|
|
|
|
default = true;
|
|
|
|
|
description = ''
|
2013-08-10 23:07:13 +02:00
|
|
|
|
Whether to use DHCP to obtain an IP address and other
|
2012-02-20 15:29:21 +01:00
|
|
|
|
configuration for all network interfaces that are not manually
|
|
|
|
|
configured.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2013-02-11 16:01:01 +01:00
|
|
|
|
|
2009-05-28 18:03:48 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2009-07-16 19:18:54 +02:00
|
|
|
|
###### implementation
|
2009-05-28 18:03:48 +02:00
|
|
|
|
|
2009-07-16 19:18:54 +02:00
|
|
|
|
config = {
|
2009-03-06 13:27:38 +01:00
|
|
|
|
|
2012-08-29 22:15:04 +02:00
|
|
|
|
boot.kernelModules = optional cfg.enableIPv6 "ipv6" ++ optional hasVirtuals "tun";
|
2011-02-19 18:21:29 +01:00
|
|
|
|
|
2009-09-29 17:43:52 +02:00
|
|
|
|
environment.systemPackages =
|
|
|
|
|
[ pkgs.host
|
|
|
|
|
pkgs.iproute
|
2010-06-04 16:00:56 +02:00
|
|
|
|
pkgs.iputils
|
2009-09-29 17:43:52 +02:00
|
|
|
|
pkgs.nettools
|
|
|
|
|
pkgs.wirelesstools
|
2013-06-02 14:27:39 +02:00
|
|
|
|
pkgs.iw
|
2010-04-21 13:37:52 +02:00
|
|
|
|
pkgs.rfkill
|
2012-02-20 01:00:50 +01:00
|
|
|
|
pkgs.openresolv
|
2011-09-14 20:20:50 +02:00
|
|
|
|
]
|
2011-03-24 17:23:28 +01:00
|
|
|
|
++ optional (cfg.bridges != {}) pkgs.bridge_utils
|
2012-08-29 22:15:04 +02:00
|
|
|
|
++ optional hasVirtuals pkgs.tunctl
|
2011-03-24 17:23:28 +01:00
|
|
|
|
++ optional cfg.enableIPv6 pkgs.ndisc6;
|
2010-06-02 23:10:48 +02:00
|
|
|
|
|
|
|
|
|
security.setuidPrograms = [ "ping" "ping6" ];
|
2011-09-14 20:20:50 +02:00
|
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
|
systemd.targets."network-interfaces" =
|
2012-10-11 22:18:48 +02:00
|
|
|
|
{ description = "All Network Interfaces";
|
2012-08-15 21:38:52 +02:00
|
|
|
|
wantedBy = [ "network.target" ];
|
2013-01-07 16:03:35 +01:00
|
|
|
|
unitConfig.X-StopOnReconfiguration = true;
|
2010-09-13 17:41:38 +02:00
|
|
|
|
};
|
|
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
|
systemd.services =
|
2012-10-10 23:55:42 +02:00
|
|
|
|
let
|
|
|
|
|
|
2012-10-11 22:18:48 +02:00
|
|
|
|
networkSetup =
|
|
|
|
|
{ description = "Networking Setup";
|
|
|
|
|
|
|
|
|
|
after = [ "network-interfaces.target" ];
|
|
|
|
|
before = [ "network.target" ];
|
|
|
|
|
wantedBy = [ "network.target" ];
|
|
|
|
|
|
|
|
|
|
path = [ pkgs.iproute ];
|
|
|
|
|
|
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
|
serviceConfig.RemainAfterExit = true;
|
|
|
|
|
|
|
|
|
|
script =
|
|
|
|
|
''
|
|
|
|
|
# Set the static DNS configuration, if given.
|
2013-04-21 20:02:26 +02:00
|
|
|
|
${pkgs.openresolv}/sbin/resolvconf -m 1 -a static <<EOF
|
2012-10-11 22:18:48 +02:00
|
|
|
|
${optionalString (cfg.nameservers != [] && cfg.domain != "") ''
|
|
|
|
|
domain ${cfg.domain}
|
|
|
|
|
''}
|
|
|
|
|
${flip concatMapStrings cfg.nameservers (ns: ''
|
|
|
|
|
nameserver ${ns}
|
|
|
|
|
'')}
|
|
|
|
|
EOF
|
|
|
|
|
|
2012-10-19 21:41:01 +02:00
|
|
|
|
# Disable or enable IPv6.
|
2012-12-11 13:14:17 +01:00
|
|
|
|
if [ -e /proc/sys/net/ipv6/conf/all/disable_ipv6 ]; then
|
|
|
|
|
echo ${if cfg.enableIPv6 then "0" else "1"} > /proc/sys/net/ipv6/conf/all/disable_ipv6
|
|
|
|
|
fi
|
2012-10-19 21:41:01 +02:00
|
|
|
|
|
2012-10-11 22:18:48 +02:00
|
|
|
|
# Set the default gateway.
|
|
|
|
|
${optionalString (cfg.defaultGateway != "") ''
|
|
|
|
|
# FIXME: get rid of "|| true" (necessary to make it idempotent).
|
2013-01-06 23:20:48 +01:00
|
|
|
|
ip route add default via "${cfg.defaultGateway}" ${
|
|
|
|
|
optionalString (cfg.defaultGatewayWindowSize != null)
|
|
|
|
|
"window ${cfg.defaultGatewayWindowSize}"} || true
|
2012-10-11 22:18:48 +02:00
|
|
|
|
''}
|
|
|
|
|
|
|
|
|
|
# Turn on forwarding if any interface has enabled proxy_arp.
|
2012-11-02 17:08:11 +01:00
|
|
|
|
${optionalString (any (i: i.proxyARP) interfaces) ''
|
2012-10-11 22:18:48 +02:00
|
|
|
|
echo 1 > /proc/sys/net/ipv4/ip_forward
|
|
|
|
|
''}
|
|
|
|
|
|
|
|
|
|
# Run any user-specified commands.
|
|
|
|
|
${cfg.localCommands}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2012-10-10 23:55:42 +02:00
|
|
|
|
# For each interface <foo>, create a job ‘<foo>-cfg.service"
|
|
|
|
|
# that performs static configuration. It has a "wants"
|
|
|
|
|
# dependency on ‘<foo>.service’, which is supposed to create
|
|
|
|
|
# the interface and need not exist (i.e. for hardware
|
|
|
|
|
# interfaces). It has a binds-to dependency on the actual
|
|
|
|
|
# network device, so it only gets started after the interface
|
|
|
|
|
# has appeared, and it's stopped when the interface
|
|
|
|
|
# disappears.
|
|
|
|
|
configureInterface = i: nameValuePair "${i.name}-cfg"
|
2012-10-11 21:36:52 +02:00
|
|
|
|
(let mask =
|
|
|
|
|
if i.prefixLength != null then toString i.prefixLength else
|
|
|
|
|
if i.subnetMask != "" then i.subnetMask else "32";
|
|
|
|
|
in
|
2012-10-10 23:55:42 +02:00
|
|
|
|
{ description = "Configuration of ${i.name}";
|
2012-10-11 22:18:48 +02:00
|
|
|
|
wantedBy = [ "network-interfaces.target" ];
|
2012-10-10 23:55:42 +02:00
|
|
|
|
bindsTo = [ "sys-subsystem-net-devices-${i.name}.device" ];
|
2012-10-11 04:47:50 +02:00
|
|
|
|
after = [ "sys-subsystem-net-devices-${i.name}.device" ];
|
2012-10-10 23:55:42 +02:00
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
|
serviceConfig.RemainAfterExit = true;
|
2012-10-11 21:36:52 +02:00
|
|
|
|
path = [ pkgs.iproute pkgs.gawk ];
|
2012-10-10 23:55:42 +02:00
|
|
|
|
script =
|
|
|
|
|
''
|
|
|
|
|
echo "bringing up interface..."
|
|
|
|
|
ip link set "${i.name}" up
|
|
|
|
|
''
|
2012-11-02 17:08:11 +01:00
|
|
|
|
+ optionalString (i.macAddress != null)
|
2012-10-10 23:55:42 +02:00
|
|
|
|
''
|
|
|
|
|
echo "setting MAC address to ${i.macAddress}..."
|
|
|
|
|
ip link set "${i.name}" address "${i.macAddress}"
|
|
|
|
|
''
|
2012-11-02 17:08:11 +01:00
|
|
|
|
+ optionalString (i.ipAddress != null)
|
2012-10-10 23:55:42 +02:00
|
|
|
|
''
|
2012-10-11 21:36:52 +02:00
|
|
|
|
cur=$(ip -4 -o a show dev "${i.name}" | awk '{print $4}')
|
|
|
|
|
# Only do a flush/add if it's necessary. This is
|
|
|
|
|
# useful when the Nix store is accessed via this
|
|
|
|
|
# interface (e.g. in a QEMU VM test).
|
|
|
|
|
if [ "$cur" != "${i.ipAddress}/${mask}" ]; then
|
|
|
|
|
echo "configuring interface..."
|
|
|
|
|
ip -4 addr flush dev "${i.name}"
|
|
|
|
|
ip -4 addr add "${i.ipAddress}/${mask}" dev "${i.name}"
|
2013-01-07 15:04:19 +01:00
|
|
|
|
# Ensure that the default gateway remains set.
|
|
|
|
|
# (Flushing this interface may have removed it.)
|
2013-01-16 13:17:57 +01:00
|
|
|
|
${config.systemd.package}/bin/systemctl try-restart --no-block network-setup.service
|
2012-10-11 21:36:52 +02:00
|
|
|
|
else
|
|
|
|
|
echo "skipping configuring interface"
|
|
|
|
|
fi
|
2013-01-16 13:17:57 +01:00
|
|
|
|
${config.systemd.package}/bin/systemctl start ip-up.target
|
2012-10-10 23:55:42 +02:00
|
|
|
|
''
|
|
|
|
|
+ optionalString i.proxyARP
|
|
|
|
|
''
|
|
|
|
|
echo 1 > /proc/sys/net/ipv4/conf/${i.name}/proxy_arp
|
|
|
|
|
''
|
|
|
|
|
+ optionalString (i.proxyARP && cfg.enableIPv6)
|
|
|
|
|
''
|
|
|
|
|
echo 1 > /proc/sys/net/ipv6/conf/${i.name}/proxy_ndp
|
|
|
|
|
'';
|
2012-10-11 21:36:52 +02:00
|
|
|
|
});
|
2012-10-10 23:55:42 +02:00
|
|
|
|
|
|
|
|
|
createTunDevice = i: nameValuePair "${i.name}"
|
|
|
|
|
{ description = "Virtual Network Interface ${i.name}";
|
2012-10-11 23:59:41 +02:00
|
|
|
|
requires = [ "dev-net-tun.device" ];
|
|
|
|
|
after = [ "dev-net-tun.device" ];
|
2013-04-19 22:32:48 +02:00
|
|
|
|
wantedBy = [ "network.target" ];
|
|
|
|
|
requiredBy = [ "sys-subsystem-net-devices-${i.name}.device" ];
|
2012-10-10 23:55:42 +02:00
|
|
|
|
serviceConfig =
|
|
|
|
|
{ Type = "oneshot";
|
|
|
|
|
RemainAfterExit = true;
|
|
|
|
|
ExecStart = "${pkgs.tunctl}/bin/tunctl -t '${i.name}' -u '${i.virtualOwner}'";
|
|
|
|
|
ExecStop = "${pkgs.tunctl}/bin/tunctl -d '${i.name}'";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
createBridgeDevice = n: v:
|
|
|
|
|
let
|
|
|
|
|
deps = map (i: "sys-subsystem-net-devices-${i}.device") v.interfaces;
|
|
|
|
|
in
|
|
|
|
|
{ description = "Bridge Interface ${n}";
|
2012-10-11 04:47:50 +02:00
|
|
|
|
wantedBy = [ "network.target" "sys-subsystem-net-devices-${n}.device" ];
|
2012-10-10 23:55:42 +02:00
|
|
|
|
bindsTo = deps;
|
|
|
|
|
after = deps;
|
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
|
serviceConfig.RemainAfterExit = true;
|
|
|
|
|
path = [ pkgs.bridge_utils pkgs.iproute ];
|
|
|
|
|
script =
|
|
|
|
|
''
|
|
|
|
|
brctl addbr "${n}"
|
|
|
|
|
|
|
|
|
|
# Set bridge's hello time to 0 to avoid startup delays.
|
|
|
|
|
brctl setfd "${n}" 0
|
|
|
|
|
|
|
|
|
|
${flip concatMapStrings v.interfaces (i: ''
|
|
|
|
|
brctl addif "${n}" "${i}"
|
2012-10-12 18:14:39 +02:00
|
|
|
|
ip link set "${i}" up
|
2012-10-10 23:55:42 +02:00
|
|
|
|
ip addr flush dev "${i}"
|
2013-03-02 10:24:46 +01:00
|
|
|
|
|
|
|
|
|
echo "bringing up network device ${n}..."
|
|
|
|
|
ip link set "${n}" up
|
2012-10-10 23:55:42 +02:00
|
|
|
|
'')}
|
|
|
|
|
|
|
|
|
|
# !!! Should delete (brctl delif) any interfaces that
|
|
|
|
|
# no longer belong to the bridge.
|
|
|
|
|
'';
|
|
|
|
|
postStop =
|
|
|
|
|
''
|
|
|
|
|
ip link set "${n}" down
|
|
|
|
|
brctl delbr "${n}"
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
in listToAttrs (
|
2012-11-02 17:08:11 +01:00
|
|
|
|
map configureInterface interfaces ++
|
|
|
|
|
map createTunDevice (filter (i: i.virtual) interfaces))
|
2012-10-11 22:18:48 +02:00
|
|
|
|
// mapAttrs createBridgeDevice cfg.bridges
|
|
|
|
|
// { "network-setup" = networkSetup; };
|
2012-10-10 23:55:42 +02:00
|
|
|
|
|
2013-05-22 01:30:24 +02:00
|
|
|
|
# Set the host and domain names in the activation script. Don't
|
|
|
|
|
# clear it if it's not configured in the NixOS configuration,
|
2013-10-29 17:34:43 +01:00
|
|
|
|
# since it may have been set by dhcpcd in the meantime.
|
2010-09-13 17:41:38 +02:00
|
|
|
|
system.activationScripts.hostname =
|
2010-09-14 13:58:55 +02:00
|
|
|
|
optionalString (config.networking.hostName != "") ''
|
2010-09-13 17:41:38 +02:00
|
|
|
|
hostname "${config.networking.hostName}"
|
2010-09-14 13:58:55 +02:00
|
|
|
|
'';
|
2013-05-22 01:30:24 +02:00
|
|
|
|
system.activationScripts.domain =
|
|
|
|
|
optionalString (config.networking.domain != "") ''
|
|
|
|
|
domainname "${config.networking.domain}"
|
|
|
|
|
'';
|
2009-07-16 19:18:54 +02:00
|
|
|
|
|
2012-10-11 23:59:41 +02:00
|
|
|
|
services.udev.extraRules =
|
|
|
|
|
''
|
|
|
|
|
KERNEL=="tun", TAG+="systemd"
|
|
|
|
|
'';
|
|
|
|
|
|
2009-07-16 19:18:54 +02:00
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
|
2006-11-20 18:06:44 +01:00
|
|
|
|
}
|