2018-07-20 22:56:59 +02:00
|
|
|
{ config, options, lib, pkgs, utils, ... }:
|
2009-03-06 13:27:38 +01:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2014-08-29 00:27:20 +02:00
|
|
|
with utils;
|
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;
|
2014-06-26 07:13:21 +02:00
|
|
|
hasSits = cfg.sits != { };
|
2013-12-30 10:14:41 +01:00
|
|
|
hasBonds = cfg.bonds != { };
|
2012-11-02 17:08:11 +01:00
|
|
|
|
2014-11-30 07:34:50 +01:00
|
|
|
slaves = concatMap (i: i.interfaces) (attrValues cfg.bonds)
|
2015-09-22 15:49:17 +02:00
|
|
|
++ concatMap (i: i.interfaces) (attrValues cfg.bridges)
|
2018-12-29 11:16:51 +01:00
|
|
|
++ concatMap (i: attrNames (filterAttrs (name: config: ! (config.type == "internal" || hasAttr name cfg.interfaces)) i.interfaces)) (attrValues cfg.vswitches);
|
2014-11-30 07:34:50 +01:00
|
|
|
|
2014-11-30 14:16:07 +01:00
|
|
|
slaveIfs = map (i: cfg.interfaces.${i}) (filter (i: cfg.interfaces ? ${i}) slaves);
|
2014-11-30 07:34:50 +01:00
|
|
|
|
2015-01-14 01:10:39 +01:00
|
|
|
rstpBridges = flip filterAttrs cfg.bridges (_: { rstp, ... }: rstp);
|
|
|
|
|
|
|
|
needsMstpd = rstpBridges != { };
|
|
|
|
|
|
|
|
bridgeStp = optional needsMstpd (pkgs.writeTextFile {
|
|
|
|
name = "bridge-stp";
|
|
|
|
executable = true;
|
|
|
|
destination = "/bin/bridge-stp";
|
|
|
|
text = ''
|
2018-03-01 20:38:53 +01:00
|
|
|
#!${pkgs.runtimeShell} -e
|
2015-01-14 01:10:39 +01:00
|
|
|
export PATH="${pkgs.mstpd}/bin"
|
|
|
|
|
|
|
|
BRIDGES=(${concatStringsSep " " (attrNames rstpBridges)})
|
|
|
|
for BRIDGE in $BRIDGES; do
|
|
|
|
if [ "$BRIDGE" = "$1" ]; then
|
|
|
|
if [ "$2" = "start" ]; then
|
|
|
|
mstpctl addbridge "$BRIDGE"
|
|
|
|
exit 0
|
|
|
|
elif [ "$2" = "stop" ]; then
|
|
|
|
mstpctl delbridge "$BRIDGE"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
exit 1
|
|
|
|
'';
|
|
|
|
});
|
|
|
|
|
2014-11-24 21:06:07 +01:00
|
|
|
# We must escape interfaces due to the systemd interpretation
|
|
|
|
subsystemDevice = interface:
|
|
|
|
"sys-subsystem-net-devices-${escapeSystemdPath interface}.device";
|
|
|
|
|
2014-08-31 18:46:16 +02:00
|
|
|
addrOpts = v:
|
|
|
|
assert v == 4 || v == 6;
|
2016-09-11 12:45:24 +02:00
|
|
|
{ options = {
|
|
|
|
address = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
2017-07-27 16:23:20 +02:00
|
|
|
IPv${toString v} address of the interface. Leave empty to configure the
|
2016-09-11 12:45:24 +02:00
|
|
|
interface using DHCP.
|
|
|
|
'';
|
|
|
|
};
|
2014-08-31 18:46:16 +02:00
|
|
|
|
2016-09-11 12:45:24 +02:00
|
|
|
prefixLength = mkOption {
|
|
|
|
type = types.addCheck types.int (n: n >= 0 && n <= (if v == 4 then 32 else 128));
|
|
|
|
description = ''
|
|
|
|
Subnet mask of the interface, specified as the number of
|
|
|
|
bits in the prefix (<literal>${if v == 4 then "24" else "64"}</literal>).
|
|
|
|
'';
|
|
|
|
};
|
2014-08-31 18:46:16 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-07-27 16:23:20 +02:00
|
|
|
routeOpts = v:
|
|
|
|
{ options = {
|
|
|
|
address = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "IPv${toString v} address of the network.";
|
|
|
|
};
|
|
|
|
|
|
|
|
prefixLength = mkOption {
|
|
|
|
type = types.addCheck types.int (n: n >= 0 && n <= (if v == 4 then 32 else 128));
|
|
|
|
description = ''
|
|
|
|
Subnet mask of the network, specified as the number of
|
|
|
|
bits in the prefix (<literal>${if v == 4 then "24" else "64"}</literal>).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-07-28 16:45:58 +02:00
|
|
|
via = mkOption {
|
2017-07-27 16:23:20 +02:00
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = "IPv${toString v} address of the next hop.";
|
|
|
|
};
|
|
|
|
|
|
|
|
options = mkOption {
|
2017-07-28 16:45:58 +02:00
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = { };
|
|
|
|
example = { mtu = "1492"; window = "524288"; };
|
2017-07-27 16:23:20 +02:00
|
|
|
description = ''
|
2018-03-10 16:16:56 +01:00
|
|
|
Other route options. See the symbol <literal>OPTIONS</literal>
|
2017-07-27 16:23:20 +02:00
|
|
|
in the <literal>ip-route(8)</literal> manual page for the details.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-01-14 02:14:16 +01:00
|
|
|
gatewayCoerce = address: { inherit address; };
|
|
|
|
|
|
|
|
gatewayOpts = { ... }: {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
address = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "The default gateway address.";
|
|
|
|
};
|
|
|
|
|
|
|
|
interface = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "enp0s3";
|
|
|
|
description = "The default gateway interface.";
|
|
|
|
};
|
|
|
|
|
2017-02-09 23:09:07 +01:00
|
|
|
metric = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
example = 42;
|
|
|
|
description = "The default gateway metric/preference.";
|
|
|
|
};
|
|
|
|
|
2017-01-14 02:14:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-11-02 17:08:11 +01:00
|
|
|
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.";
|
|
|
|
};
|
|
|
|
|
2020-01-30 11:55:50 +01:00
|
|
|
tempAddress = mkOption {
|
|
|
|
type = types.enum [ "default" "enabled" "disabled" ];
|
|
|
|
default = if cfg.enableIPv6 then "default" else "disabled";
|
|
|
|
defaultText = literalExample ''if cfg.enableIPv6 then "default" else "disabled"'';
|
2018-02-01 12:13:17 +01:00
|
|
|
description = ''
|
2020-01-30 11:55:50 +01:00
|
|
|
When IPv6 is enabled with SLAAC, this option controls the use of
|
|
|
|
temporary address (aka privacy extensions). This is used to reduce tracking.
|
|
|
|
The three possible values are:
|
|
|
|
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<literal>"default"</literal> to generate temporary addresses and use
|
|
|
|
them by default;
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<literal>"enabled"</literal> to generate temporary addresses but keep
|
|
|
|
using the standard EUI-64 ones by default;
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<literal>"disabled"</literal> to completely disable temporary addresses.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
2018-02-01 12:13:17 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-11-20 11:37:48 +01:00
|
|
|
useDHCP = mkOption {
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Whether this interface should be configured with dhcp.
|
|
|
|
Null implies the old behavior which depends on whether ip addresses
|
|
|
|
are specified or not.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-12-03 05:13:14 +01:00
|
|
|
ipv4.addresses = mkOption {
|
2014-08-31 18:46:16 +02:00
|
|
|
default = [ ];
|
|
|
|
example = [
|
|
|
|
{ address = "10.0.0.1"; prefixLength = 16; }
|
|
|
|
{ address = "192.168.1.1"; prefixLength = 24; }
|
|
|
|
];
|
2016-09-11 12:45:24 +02:00
|
|
|
type = with types; listOf (submodule (addrOpts 4));
|
2014-08-31 18:46:16 +02:00
|
|
|
description = ''
|
|
|
|
List of IPv4 addresses that will be statically assigned to the interface.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-12-03 05:13:14 +01:00
|
|
|
ipv6.addresses = mkOption {
|
2014-08-31 18:46:16 +02:00
|
|
|
default = [ ];
|
|
|
|
example = [
|
|
|
|
{ address = "fdfd:b3f0:482::1"; prefixLength = 48; }
|
|
|
|
{ address = "2001:1470:fffd:2098::e006"; prefixLength = 64; }
|
|
|
|
];
|
2016-09-11 12:45:24 +02:00
|
|
|
type = with types; listOf (submodule (addrOpts 6));
|
2014-08-31 18:46:16 +02:00
|
|
|
description = ''
|
|
|
|
List of IPv6 addresses that will be statically assigned to the interface.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-12-03 05:13:14 +01:00
|
|
|
ipv4.routes = mkOption {
|
2017-07-27 16:23:20 +02:00
|
|
|
default = [];
|
|
|
|
example = [
|
|
|
|
{ address = "10.0.0.0"; prefixLength = 16; }
|
2017-07-28 16:45:58 +02:00
|
|
|
{ address = "192.168.2.0"; prefixLength = 24; via = "192.168.1.1"; }
|
2017-07-27 16:23:20 +02:00
|
|
|
];
|
|
|
|
type = with types; listOf (submodule (routeOpts 4));
|
|
|
|
description = ''
|
|
|
|
List of extra IPv4 static routes that will be assigned to the interface.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-12-03 05:13:14 +01:00
|
|
|
ipv6.routes = mkOption {
|
2017-07-27 16:23:20 +02:00
|
|
|
default = [];
|
|
|
|
example = [
|
|
|
|
{ address = "fdfd:b3f0::"; prefixLength = 48; }
|
2017-07-28 16:45:58 +02:00
|
|
|
{ address = "2001:1470:fffd:2098::"; prefixLength = 64; via = "fdfd:b3f0::1"; }
|
2017-07-27 16:23:20 +02:00
|
|
|
];
|
|
|
|
type = with types; listOf (submodule (routeOpts 6));
|
|
|
|
description = ''
|
|
|
|
List of extra IPv6 static routes that will be assigned to the interface.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2012-11-02 17:08:11 +01:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-12-30 03:58:59 +01:00
|
|
|
mtu = mkOption {
|
|
|
|
default = null;
|
|
|
|
example = 9000;
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
description = ''
|
|
|
|
MTU size for packets leaving the interface. Leave empty to use the default.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2012-11-02 17:08:11 +01:00
|
|
|
virtual = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Whether this interface is virtual and should be created by tunctl.
|
2016-09-13 08:04:00 +02:00
|
|
|
This is mainly useful for creating bridges between a host and a virtual
|
2012-11-02 17:08:11 +01:00
|
|
|
network such as VPN or a virtual machine.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-08-24 03:38:29 +02:00
|
|
|
virtualType = mkOption {
|
2018-01-31 05:51:09 +01:00
|
|
|
default = if hasPrefix "tun" name then "tun" else "tap";
|
2018-02-01 10:51:35 +01:00
|
|
|
defaultText = literalExample ''if hasPrefix "tun" name then "tun" else "tap"'';
|
2018-01-31 05:51:09 +01:00
|
|
|
type = with types; enum [ "tun" "tap" ];
|
2014-08-24 03:38:29 +02:00
|
|
|
description = ''
|
2018-01-31 05:51:09 +01:00
|
|
|
The type of interface to create.
|
|
|
|
The default is TUN for an interface name starting
|
|
|
|
with "tun", otherwise TAP.
|
2014-08-24 03:38:29 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2012-11-02 17:08:11 +01:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2017-12-03 05:13:14 +01:00
|
|
|
# Renamed or removed options
|
|
|
|
imports =
|
|
|
|
let
|
|
|
|
defined = x: x != "_mkMergedOptionModule";
|
|
|
|
in [
|
2020-01-30 11:55:50 +01:00
|
|
|
(mkChangedOptionModule [ "preferTempAddress" ] [ "tempAddress" ]
|
|
|
|
(config:
|
|
|
|
let bool = getAttrFromPath [ "preferTempAddress" ] config;
|
|
|
|
in if bool then "default" else "enabled"
|
|
|
|
))
|
2017-12-03 05:13:14 +01:00
|
|
|
(mkRenamedOptionModule [ "ip4" ] [ "ipv4" "addresses"])
|
|
|
|
(mkRenamedOptionModule [ "ip6" ] [ "ipv6" "addresses"])
|
|
|
|
(mkRemovedOptionModule [ "subnetMask" ] ''
|
|
|
|
Supply a prefix length instead; use option
|
|
|
|
networking.interfaces.<name>.ipv{4,6}.addresses'')
|
|
|
|
(mkMergedOptionModule
|
|
|
|
[ [ "ipAddress" ] [ "prefixLength" ] ]
|
|
|
|
[ "ipv4" "addresses" ]
|
|
|
|
(cfg: with cfg;
|
|
|
|
optional (defined ipAddress && defined prefixLength)
|
|
|
|
{ address = ipAddress; prefixLength = prefixLength; }))
|
|
|
|
(mkMergedOptionModule
|
|
|
|
[ [ "ipv6Address" ] [ "ipv6PrefixLength" ] ]
|
|
|
|
[ "ipv6" "addresses" ]
|
|
|
|
(cfg: with cfg;
|
|
|
|
optional (defined ipv6Address && defined ipv6PrefixLength)
|
|
|
|
{ address = ipv6Address; prefixLength = ipv6PrefixLength; }))
|
|
|
|
|
2019-09-25 17:13:29 +02:00
|
|
|
({ options.warnings = options.warnings; options.assertions = options.assertions; })
|
2017-12-03 05:13:14 +01:00
|
|
|
];
|
|
|
|
|
2012-11-02 17:08:11 +01:00
|
|
|
};
|
2009-07-16 19:18:54 +02:00
|
|
|
|
2018-12-29 11:16:51 +01:00
|
|
|
vswitchInterfaceOpts = {name, ...}: {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
description = "Name of the interface";
|
|
|
|
example = "eth0";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
vlan = mkOption {
|
|
|
|
description = "Vlan tag to apply to interface";
|
|
|
|
example = 10;
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
type = mkOption {
|
|
|
|
description = "Openvswitch type to assign to interface";
|
|
|
|
example = "internal";
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
nixos: Add system-wide option to set the hostid
The old boot.spl.hostid option was not working correctly due to an
upstream bug.
Instead, now we will create the /etc/hostid file so that all applications
(including the ZFS kernel modules, ZFS user-space applications and other
unrelated programs) pick-up the same system-wide host id. Note that glibc
(and by extension, the `hostid` program) also respect the host id configured in
/etc/hostid, if it exists.
The hostid option is now mandatory when using ZFS because otherwise, ZFS will
require you to force-import your ZFS pools if you want to use them, which is
undesirable because it disables some of the checks that ZFS does to make sure it
is safe to import a ZFS pool.
The /etc/hostid file must also exist when booting the initrd, before the SPL
kernel module is loaded, so that ZFS picks up the hostid correctly.
The complexity in creating the /etc/hostid file is due to having to
write the host ID as a 32-bit binary value, taking into account the
endianness of the machine, while using only shell commands and/or simple
utilities (to avoid exploding the size of the initrd).
2014-10-23 04:59:06 +02:00
|
|
|
hexChars = stringToCharacters "0123456789abcdef";
|
|
|
|
|
|
|
|
isHexString = s: all (c: elem c hexChars) (stringToCharacters (toLower s));
|
|
|
|
|
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";
|
2014-11-20 11:37:48 +01:00
|
|
|
type = types.str;
|
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
|
|
|
};
|
|
|
|
|
nixos: Add system-wide option to set the hostid
The old boot.spl.hostid option was not working correctly due to an
upstream bug.
Instead, now we will create the /etc/hostid file so that all applications
(including the ZFS kernel modules, ZFS user-space applications and other
unrelated programs) pick-up the same system-wide host id. Note that glibc
(and by extension, the `hostid` program) also respect the host id configured in
/etc/hostid, if it exists.
The hostid option is now mandatory when using ZFS because otherwise, ZFS will
require you to force-import your ZFS pools if you want to use them, which is
undesirable because it disables some of the checks that ZFS does to make sure it
is safe to import a ZFS pool.
The /etc/hostid file must also exist when booting the initrd, before the SPL
kernel module is loaded, so that ZFS picks up the hostid correctly.
The complexity in creating the /etc/hostid file is due to having to
write the host ID as a 32-bit binary value, taking into account the
endianness of the machine, while using only shell commands and/or simple
utilities (to avoid exploding the size of the initrd).
2014-10-23 04:59:06 +02:00
|
|
|
networking.hostId = mkOption {
|
|
|
|
default = null;
|
|
|
|
example = "4e98920d";
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
description = ''
|
|
|
|
The 32-bit host ID of the machine, formatted as 8 hexadecimal characters.
|
|
|
|
|
|
|
|
You should try to make this ID unique among your machines. You can
|
2014-12-18 22:52:29 +01:00
|
|
|
generate a random 32-bit ID using the following commands:
|
nixos: Add system-wide option to set the hostid
The old boot.spl.hostid option was not working correctly due to an
upstream bug.
Instead, now we will create the /etc/hostid file so that all applications
(including the ZFS kernel modules, ZFS user-space applications and other
unrelated programs) pick-up the same system-wide host id. Note that glibc
(and by extension, the `hostid` program) also respect the host id configured in
/etc/hostid, if it exists.
The hostid option is now mandatory when using ZFS because otherwise, ZFS will
require you to force-import your ZFS pools if you want to use them, which is
undesirable because it disables some of the checks that ZFS does to make sure it
is safe to import a ZFS pool.
The /etc/hostid file must also exist when booting the initrd, before the SPL
kernel module is loaded, so that ZFS picks up the hostid correctly.
The complexity in creating the /etc/hostid file is due to having to
write the host ID as a 32-bit binary value, taking into account the
endianness of the machine, while using only shell commands and/or simple
utilities (to avoid exploding the size of the initrd).
2014-10-23 04:59:06 +02:00
|
|
|
|
2018-09-10 21:44:48 +02:00
|
|
|
<literal>head -c 8 /etc/machine-id</literal>
|
2016-09-30 10:45:48 +02:00
|
|
|
|
2014-12-18 22:52:29 +01:00
|
|
|
(this derives it from the machine-id that systemd generates) or
|
2016-09-30 10:45:48 +02:00
|
|
|
|
nixos: Add system-wide option to set the hostid
The old boot.spl.hostid option was not working correctly due to an
upstream bug.
Instead, now we will create the /etc/hostid file so that all applications
(including the ZFS kernel modules, ZFS user-space applications and other
unrelated programs) pick-up the same system-wide host id. Note that glibc
(and by extension, the `hostid` program) also respect the host id configured in
/etc/hostid, if it exists.
The hostid option is now mandatory when using ZFS because otherwise, ZFS will
require you to force-import your ZFS pools if you want to use them, which is
undesirable because it disables some of the checks that ZFS does to make sure it
is safe to import a ZFS pool.
The /etc/hostid file must also exist when booting the initrd, before the SPL
kernel module is loaded, so that ZFS picks up the hostid correctly.
The complexity in creating the /etc/hostid file is due to having to
write the host ID as a 32-bit binary value, taking into account the
endianness of the machine, while using only shell commands and/or simple
utilities (to avoid exploding the size of the initrd).
2014-10-23 04:59:06 +02:00
|
|
|
<literal>head -c4 /dev/urandom | od -A none -t x4</literal>
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2011-02-19 18:21:29 +01:00
|
|
|
networking.enableIPv6 = mkOption {
|
|
|
|
default = true;
|
2014-11-20 11:37:48 +01:00
|
|
|
type = types.bool;
|
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 {
|
2014-11-20 11:37:48 +01:00
|
|
|
default = null;
|
2017-01-14 02:14:16 +01:00
|
|
|
example = {
|
|
|
|
address = "131.211.84.1";
|
2017-02-21 15:41:37 +01:00
|
|
|
interface = "enp3s0";
|
2017-01-14 02:14:16 +01:00
|
|
|
};
|
|
|
|
type = types.nullOr (types.coercedTo types.str gatewayCoerce (types.submodule gatewayOpts));
|
2009-07-16 19:18:54 +02:00
|
|
|
description = ''
|
2017-01-14 02:14:16 +01:00
|
|
|
The default gateway. It can be left empty if it is auto-detected through DHCP.
|
|
|
|
It can be specified as a string or an option set along with a network interface.
|
2009-07-16 19:18:54 +02:00
|
|
|
'';
|
2009-05-28 18:03:48 +02:00
|
|
|
};
|
|
|
|
|
2014-12-18 02:54:06 +01:00
|
|
|
networking.defaultGateway6 = mkOption {
|
|
|
|
default = null;
|
2017-01-14 02:14:16 +01:00
|
|
|
example = {
|
|
|
|
address = "2001:4d0:1e04:895::1";
|
2017-02-21 15:41:37 +01:00
|
|
|
interface = "enp3s0";
|
2017-01-14 02:14:16 +01:00
|
|
|
};
|
|
|
|
type = types.nullOr (types.coercedTo types.str gatewayCoerce (types.submodule gatewayOpts));
|
2014-12-18 02:54:06 +01:00
|
|
|
description = ''
|
2017-01-14 02:14:16 +01:00
|
|
|
The default ipv6 gateway. It can be left empty if it is auto-detected through DHCP.
|
|
|
|
It can be specified as a string or an option set along with a network interface.
|
2014-12-18 02:54:06 +01: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 {
|
2016-01-17 19:34:55 +01:00
|
|
|
type = types.listOf types.str;
|
2009-05-28 18:03:48 +02:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2014-04-25 00:46:12 +02:00
|
|
|
networking.search = mkOption {
|
|
|
|
default = [];
|
|
|
|
example = [ "example.com" "local.domain" ];
|
|
|
|
type = types.listOf types.str;
|
|
|
|
description = ''
|
|
|
|
The list of search paths used when resolving domain names.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-05-28 18:03:48 +02:00
|
|
|
networking.domain = mkOption {
|
2014-11-20 11:37:48 +01:00
|
|
|
default = null;
|
2009-05-28 18:03:48 +02:00
|
|
|
example = "home";
|
2014-11-20 11:37:48 +01:00
|
|
|
type = types.nullOr types.str;
|
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
|
|
|
};
|
|
|
|
|
2014-04-18 16:40:27 +02:00
|
|
|
networking.useHostResolvConf = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
In containers, whether to use the
|
|
|
|
<filename>resolv.conf</filename> supplied by the host.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-05-28 18:03:48 +02:00
|
|
|
networking.localCommands = mkOption {
|
2016-09-20 13:29:40 +02:00
|
|
|
type = types.lines;
|
2009-05-28 18:03:48 +02:00
|
|
|
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 =
|
2018-03-16 17:06:20 +01:00
|
|
|
{ eth0.ipv4.addresses = [ {
|
2014-08-31 18:46:16 +02:00
|
|
|
address = "131.211.84.78";
|
|
|
|
prefixLength = 25;
|
|
|
|
} ];
|
2012-11-02 17:08:11 +01:00
|
|
|
};
|
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.
|
|
|
|
'';
|
2016-09-11 12:45:24 +02:00
|
|
|
type = with types; loaOf (submodule interfaceOpts);
|
2010-05-21 16:12:03 +02:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2015-09-22 15:49:17 +02:00
|
|
|
networking.vswitches = mkOption {
|
|
|
|
default = { };
|
|
|
|
example =
|
2018-12-29 11:16:51 +01:00
|
|
|
{ vs0.interfaces = { eth0 = { }; lo1 = { type="internal"; }; };
|
|
|
|
vs1.interfaces = [ { name = "eth2"; } { name = "lo2"; type="internal"; } ];
|
2015-09-22 15:49:17 +02:00
|
|
|
};
|
|
|
|
description =
|
|
|
|
''
|
|
|
|
This option allows you to define Open vSwitches that connect
|
2015-10-05 13:23:58 +02:00
|
|
|
physical networks together. The value of this option is an
|
|
|
|
attribute set. Each attribute specifies a vswitch, with the
|
2015-09-22 15:49:17 +02:00
|
|
|
attribute name specifying the name of the vswitch's network
|
|
|
|
interface.
|
|
|
|
'';
|
|
|
|
|
2016-09-11 12:45:24 +02:00
|
|
|
type = with types; attrsOf (submodule {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
interfaces = mkOption {
|
|
|
|
example = [ "eth0" "eth1" ];
|
2018-12-29 11:16:51 +01:00
|
|
|
description = "The physical network interfaces connected by the vSwitch.";
|
|
|
|
type = with types; loaOf (submodule vswitchInterfaceOpts);
|
2016-09-11 12:45:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
controllers = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [ "ptcp:6653:[::1]" ];
|
|
|
|
description = ''
|
|
|
|
Specify the controller targets. For the allowed options see <literal>man 8 ovs-vsctl</literal>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
openFlowRules = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
actions=normal
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
OpenFlow rules to insert into the Open vSwitch. All <literal>openFlowRules</literal> are
|
|
|
|
loaded with <literal>ovs-ofctl</literal> within one atomic operation.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-12-29 11:16:51 +01:00
|
|
|
# TODO: custom "openflow version" type, with list from existing openflow protocols
|
|
|
|
supportedOpenFlowVersions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
example = [ "OpenFlow10" "OpenFlow13" "OpenFlow14" ];
|
|
|
|
default = [ "OpenFlow13" ];
|
|
|
|
description = ''
|
|
|
|
Supported versions to enable on this switch.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
# TODO: use same type as elements from supportedOpenFlowVersions
|
|
|
|
openFlowVersion = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "OpenFlow13";
|
|
|
|
description = ''
|
|
|
|
Version of OpenFlow protocol to use when communicating with the switch internally (e.g. with <literal>openFlowRules</literal>).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-09-11 12:45:24 +02:00
|
|
|
extraOvsctlCmds = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
set-fail-mode <switch_name> secure
|
|
|
|
set Bridge <switch_name> stp_enable=true
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Commands to manipulate the Open vSwitch database. Every line executed with <literal>ovs-vsctl</literal>.
|
|
|
|
All commands are bundled together with the operations for adding the interfaces
|
|
|
|
into one atomic operation.
|
|
|
|
'';
|
|
|
|
};
|
2015-09-22 15:49:17 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-09-11 12:45:24 +02:00
|
|
|
});
|
2015-09-22 15:49:17 +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.
|
|
|
|
'';
|
|
|
|
|
2016-09-11 12:45:24 +02:00
|
|
|
type = with types; attrsOf (submodule {
|
2011-03-15 16:13:48 +01:00
|
|
|
|
2016-09-11 12:45:24 +02:00
|
|
|
options = {
|
2011-03-15 16:13:48 +01:00
|
|
|
|
2016-09-11 12:45:24 +02:00
|
|
|
interfaces = mkOption {
|
|
|
|
example = [ "eth0" "eth1" ];
|
|
|
|
type = types.listOf types.str;
|
|
|
|
description =
|
|
|
|
"The physical network interfaces connected by the bridge.";
|
|
|
|
};
|
|
|
|
|
|
|
|
rstp = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = "Whether the bridge interface should enable rstp.";
|
|
|
|
};
|
2011-03-15 16:13:48 +01:00
|
|
|
|
2015-01-07 23:34:15 +01:00
|
|
|
};
|
|
|
|
|
2016-09-11 12:45:24 +02:00
|
|
|
});
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2011-03-15 16:13:48 +01:00
|
|
|
};
|
|
|
|
|
2017-03-06 13:23:45 +01:00
|
|
|
networking.bonds =
|
|
|
|
let
|
2020-03-29 00:50:26 +01:00
|
|
|
driverOptionsExample = ''
|
|
|
|
{
|
|
|
|
miimon = "100";
|
|
|
|
mode = "active-backup";
|
|
|
|
}
|
|
|
|
'';
|
2017-03-06 13:23:45 +01:00
|
|
|
in mkOption {
|
|
|
|
default = { };
|
2020-03-29 00:50:26 +01:00
|
|
|
example = literalExample ''
|
|
|
|
{
|
|
|
|
bond0 = {
|
|
|
|
interfaces = [ "eth0" "wlan0" ];
|
|
|
|
driverOptions = ${driverOptionsExample};
|
|
|
|
};
|
|
|
|
anotherBond.interfaces = [ "enp4s0f0" "enp4s0f1" "enp5s0f0" "enp5s0f1" ];
|
|
|
|
}
|
|
|
|
'';
|
2017-03-06 13:23:45 +01:00
|
|
|
description = ''
|
|
|
|
This option allows you to define bond devices that aggregate multiple,
|
|
|
|
underlying networking interfaces together. The value of this option is
|
|
|
|
an attribute set. Each attribute specifies a bond, with the attribute
|
|
|
|
name specifying the name of the bond's network interface
|
|
|
|
'';
|
2013-12-30 10:14:41 +01:00
|
|
|
|
2017-03-06 13:23:45 +01:00
|
|
|
type = with types; attrsOf (submodule {
|
2016-09-11 12:45:24 +02:00
|
|
|
|
2017-03-06 13:23:45 +01:00
|
|
|
options = {
|
2016-09-11 12:45:24 +02:00
|
|
|
|
2017-03-06 13:23:45 +01:00
|
|
|
interfaces = mkOption {
|
|
|
|
example = [ "enp4s0f0" "enp4s0f1" "wlan0" ];
|
|
|
|
type = types.listOf types.str;
|
|
|
|
description = "The interfaces to bond together";
|
|
|
|
};
|
|
|
|
|
|
|
|
driverOptions = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = {};
|
|
|
|
example = literalExample driverOptionsExample;
|
|
|
|
description = ''
|
|
|
|
Options for the bonding driver.
|
|
|
|
Documentation can be found in
|
|
|
|
<link xlink:href="https://www.kernel.org/doc/Documentation/networking/bonding.txt" />
|
|
|
|
'';
|
2016-09-11 12:45:24 +02:00
|
|
|
|
2017-02-02 22:21:03 +01:00
|
|
|
};
|
|
|
|
|
2017-03-06 13:23:45 +01:00
|
|
|
lacp_rate = mkOption {
|
|
|
|
default = null;
|
|
|
|
example = "fast";
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
description = ''
|
|
|
|
DEPRECATED, use `driverOptions`.
|
|
|
|
Option specifying the rate in which we'll ask our link partner
|
|
|
|
to transmit LACPDU packets in 802.3ad mode.
|
|
|
|
'';
|
|
|
|
};
|
2017-02-02 22:21:03 +01:00
|
|
|
|
2017-03-06 13:23:45 +01:00
|
|
|
miimon = mkOption {
|
|
|
|
default = null;
|
|
|
|
example = 100;
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
description = ''
|
|
|
|
DEPRECATED, use `driverOptions`.
|
|
|
|
Miimon is the number of millisecond in between each round of polling
|
|
|
|
by the device driver for failed links. By default polling is not
|
|
|
|
enabled and the driver is trusted to properly detect and handle
|
|
|
|
failure scenarios.
|
|
|
|
'';
|
|
|
|
};
|
2016-09-11 12:45:24 +02:00
|
|
|
|
2017-03-06 13:23:45 +01:00
|
|
|
mode = mkOption {
|
|
|
|
default = null;
|
|
|
|
example = "active-backup";
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
description = ''
|
|
|
|
DEPRECATED, use `driverOptions`.
|
|
|
|
The mode which the bond will be running. The default mode for
|
|
|
|
the bonding driver is balance-rr, optimizing for throughput.
|
|
|
|
More information about valid modes can be found at
|
|
|
|
https://www.kernel.org/doc/Documentation/networking/bonding.txt
|
|
|
|
'';
|
|
|
|
};
|
2016-09-11 12:45:24 +02:00
|
|
|
|
2017-03-06 13:23:45 +01:00
|
|
|
xmit_hash_policy = mkOption {
|
|
|
|
default = null;
|
|
|
|
example = "layer2+3";
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
description = ''
|
|
|
|
DEPRECATED, use `driverOptions`.
|
|
|
|
Selects the transmit hash policy to use for slave selection in
|
|
|
|
balance-xor, 802.3ad, and tlb modes.
|
|
|
|
'';
|
|
|
|
};
|
2016-09-11 12:45:24 +02:00
|
|
|
|
|
|
|
};
|
2013-12-30 10:14:41 +01:00
|
|
|
|
2017-03-06 13:23:45 +01:00
|
|
|
});
|
|
|
|
};
|
2013-12-30 10:14:41 +01:00
|
|
|
|
2014-11-27 00:42:32 +01:00
|
|
|
networking.macvlans = mkOption {
|
|
|
|
default = { };
|
2020-03-29 00:50:26 +01:00
|
|
|
example = literalExample ''
|
|
|
|
{
|
|
|
|
wan = {
|
|
|
|
interface = "enp2s0";
|
|
|
|
mode = "vepa";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
2014-11-27 00:42:32 +01:00
|
|
|
description = ''
|
|
|
|
This option allows you to define macvlan interfaces which should
|
|
|
|
be automatically created.
|
|
|
|
'';
|
2016-09-11 12:45:24 +02:00
|
|
|
type = with types; attrsOf (submodule {
|
|
|
|
options = {
|
2014-11-27 00:42:32 +01:00
|
|
|
|
2016-09-11 12:45:24 +02:00
|
|
|
interface = mkOption {
|
|
|
|
example = "enp4s0";
|
|
|
|
type = types.str;
|
|
|
|
description = "The interface the macvlan will transmit packets through.";
|
|
|
|
};
|
|
|
|
|
|
|
|
mode = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
example = "vepa";
|
|
|
|
description = "The mode of the macvlan device.";
|
|
|
|
};
|
2014-11-27 00:42:32 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-09-11 12:45:24 +02:00
|
|
|
});
|
2014-11-27 00:42:32 +01:00
|
|
|
};
|
|
|
|
|
2014-06-26 07:13:21 +02:00
|
|
|
networking.sits = mkOption {
|
|
|
|
default = { };
|
2020-03-29 00:50:26 +01:00
|
|
|
example = literalExample ''
|
|
|
|
{
|
|
|
|
hurricane = {
|
|
|
|
remote = "10.0.0.1";
|
|
|
|
local = "10.0.0.22";
|
|
|
|
ttl = 255;
|
|
|
|
};
|
|
|
|
msipv6 = {
|
|
|
|
remote = "192.168.0.1";
|
|
|
|
dev = "enp3s0";
|
|
|
|
ttl = 127;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
2014-06-26 07:13:21 +02:00
|
|
|
description = ''
|
|
|
|
This option allows you to define 6-to-4 interfaces which should be automatically created.
|
|
|
|
'';
|
2016-09-11 12:45:24 +02:00
|
|
|
type = with types; attrsOf (submodule {
|
|
|
|
options = {
|
|
|
|
|
|
|
|
remote = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "10.0.0.1";
|
|
|
|
description = ''
|
|
|
|
The address of the remote endpoint to forward traffic over.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
local = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "10.0.0.22";
|
|
|
|
description = ''
|
|
|
|
The address of the local endpoint which the remote
|
|
|
|
side should send packets to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
ttl = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
example = 255;
|
|
|
|
description = ''
|
|
|
|
The time-to-live of the connection to the remote tunnel endpoint.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
dev = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "enp4s0f0";
|
|
|
|
description = ''
|
|
|
|
The underlying network device on which the tunnel resides.
|
|
|
|
'';
|
|
|
|
};
|
2014-06-26 07:13:21 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-09-11 12:45:24 +02:00
|
|
|
});
|
2014-06-26 07:13:21 +02:00
|
|
|
};
|
|
|
|
|
2013-12-30 04:52:30 +01:00
|
|
|
networking.vlans = mkOption {
|
|
|
|
default = { };
|
2020-03-29 00:50:26 +01:00
|
|
|
example = literalExample ''
|
|
|
|
{
|
|
|
|
vlan0 = {
|
|
|
|
id = 3;
|
|
|
|
interface = "enp3s0";
|
|
|
|
};
|
|
|
|
vlan1 = {
|
|
|
|
id = 1;
|
|
|
|
interface = "wlan0";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
2013-12-30 04:52:30 +01:00
|
|
|
description =
|
|
|
|
''
|
|
|
|
This option allows you to define vlan devices that tag packets
|
|
|
|
on top of a physical interface. The value of this option is an
|
|
|
|
attribute set. Each attribute specifies a vlan, with the name
|
|
|
|
specifying the name of the vlan interface.
|
|
|
|
'';
|
|
|
|
|
2016-09-11 12:45:24 +02:00
|
|
|
type = with types; attrsOf (submodule {
|
2013-12-30 04:52:30 +01:00
|
|
|
|
2016-09-11 12:45:24 +02:00
|
|
|
options = {
|
2013-12-30 04:52:30 +01:00
|
|
|
|
2016-09-11 12:45:24 +02:00
|
|
|
id = mkOption {
|
|
|
|
example = 1;
|
|
|
|
type = types.int;
|
|
|
|
description = "The vlan identifier";
|
|
|
|
};
|
|
|
|
|
|
|
|
interface = mkOption {
|
|
|
|
example = "enp4s0";
|
|
|
|
type = types.str;
|
|
|
|
description = "The interface the vlan will transmit packets through.";
|
|
|
|
};
|
2013-12-30 04:52:30 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-09-11 12:45:24 +02:00
|
|
|
});
|
|
|
|
|
2013-12-30 04:52:30 +01:00
|
|
|
};
|
|
|
|
|
2015-09-28 18:43:40 +02:00
|
|
|
networking.wlanInterfaces = mkOption {
|
|
|
|
default = { };
|
2020-03-29 00:50:26 +01:00
|
|
|
example = literalExample ''
|
|
|
|
{
|
|
|
|
wlan-station0 = {
|
|
|
|
device = "wlp6s0";
|
|
|
|
};
|
|
|
|
wlan-adhoc0 = {
|
|
|
|
type = "ibss";
|
|
|
|
device = "wlp6s0";
|
|
|
|
mac = "02:00:00:00:00:01";
|
|
|
|
};
|
|
|
|
wlan-p2p0 = {
|
|
|
|
device = "wlp6s0";
|
|
|
|
mac = "02:00:00:00:00:02";
|
|
|
|
};
|
|
|
|
wlan-ap0 = {
|
|
|
|
device = "wlp6s0";
|
|
|
|
mac = "02:00:00:00:00:03";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
2015-09-28 18:43:40 +02:00
|
|
|
description =
|
|
|
|
''
|
|
|
|
Creating multiple WLAN interfaces on top of one physical WLAN device (NIC).
|
|
|
|
|
|
|
|
The name of the WLAN interface corresponds to the name of the attribute.
|
|
|
|
A NIC is referenced by the persistent device name of the WLAN interface that
|
|
|
|
<literal>udev</literal> assigns to a NIC by default.
|
|
|
|
If a NIC supports multiple WLAN interfaces, then the one NIC can be used as
|
|
|
|
<literal>device</literal> for multiple WLAN interfaces.
|
|
|
|
If a NIC is used for creating WLAN interfaces, then the default WLAN interface
|
|
|
|
with a persistent device name form <literal>udev</literal> is not created.
|
|
|
|
A WLAN interface with the persistent name assigned from <literal>udev</literal>
|
|
|
|
would have to be created explicitly.
|
|
|
|
'';
|
|
|
|
|
2016-09-11 12:45:24 +02:00
|
|
|
type = with types; attrsOf (submodule {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
device = mkOption {
|
2019-08-08 22:48:27 +02:00
|
|
|
type = types.str;
|
2016-09-11 12:45:24 +02:00
|
|
|
example = "wlp6s0";
|
|
|
|
description = "The name of the underlying hardware WLAN device as assigned by <literal>udev</literal>.";
|
|
|
|
};
|
|
|
|
|
|
|
|
type = mkOption {
|
2016-11-16 14:37:57 +01:00
|
|
|
type = types.enum [ "managed" "ibss" "monitor" "mesh" "wds" ];
|
2016-09-11 12:45:24 +02:00
|
|
|
default = "managed";
|
|
|
|
example = "ibss";
|
|
|
|
description = ''
|
2016-11-16 14:37:57 +01:00
|
|
|
The type of the WLAN interface.
|
|
|
|
The type has to be supported by the underlying hardware of the device.
|
2016-09-11 12:45:24 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
meshID = mkOption {
|
2019-08-08 22:48:27 +02:00
|
|
|
type = types.nullOr types.str;
|
2016-09-11 12:45:24 +02:00
|
|
|
default = null;
|
|
|
|
description = "MeshID of interface with type <literal>mesh</literal>.";
|
|
|
|
};
|
|
|
|
|
|
|
|
flags = mkOption {
|
2016-11-16 14:37:57 +01:00
|
|
|
type = with types; nullOr (enum [ "none" "fcsfail" "control" "otherbss" "cook" "active" ]);
|
2016-09-11 12:45:24 +02:00
|
|
|
default = null;
|
|
|
|
example = "control";
|
|
|
|
description = ''
|
2016-11-16 14:37:57 +01:00
|
|
|
Flags for interface of type <literal>monitor</literal>.
|
2016-09-11 12:45:24 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
fourAddr = mkOption {
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
default = null;
|
|
|
|
description = "Whether to enable <literal>4-address mode</literal> with type <literal>managed</literal>.";
|
|
|
|
};
|
|
|
|
|
|
|
|
mac = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "02:00:00:00:00:01";
|
|
|
|
description = ''
|
|
|
|
MAC address to use for the device. If <literal>null</literal>, then the MAC of the
|
|
|
|
underlying hardware WLAN device is used.
|
|
|
|
|
|
|
|
INFO: Locally administered MAC addresses are of the form:
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem><para>x2:xx:xx:xx:xx:xx</para></listitem>
|
|
|
|
<listitem><para>x6:xx:xx:xx:xx:xx</para></listitem>
|
|
|
|
<listitem><para>xA:xx:xx:xx:xx:xx</para></listitem>
|
|
|
|
<listitem><para>xE:xx:xx:xx:xx:xx</para></listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
'';
|
|
|
|
};
|
2015-09-28 18:43:40 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-09-11 12:45:24 +02:00
|
|
|
});
|
2015-09-28 18:43:40 +02: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.
|
2019-09-24 09:36:49 +02:00
|
|
|
|
|
|
|
Using this option is highly discouraged and also incompatible with
|
|
|
|
<option>networking.useNetworkd</option>. Please use
|
|
|
|
<option>networking.interfaces.<name>.useDHCP</option> instead
|
|
|
|
and set this to false.
|
2012-02-20 15:29:21 +01:00
|
|
|
'';
|
|
|
|
};
|
2013-02-11 16:01:01 +01:00
|
|
|
|
2014-11-20 11:37:48 +01:00
|
|
|
networking.useNetworkd = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Whether we should use networkd as the network configuration backend or
|
2014-11-25 20:44:14 +01:00
|
|
|
the legacy script based system. Note that this option is experimental,
|
|
|
|
enable at your own risk.
|
2014-11-20 11:37:48 +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
|
|
|
|
2017-12-03 05:13:14 +01:00
|
|
|
warnings = concatMap (i: i.warnings) interfaces;
|
|
|
|
|
2014-08-31 18:46:16 +02:00
|
|
|
assertions =
|
2019-08-05 13:03:38 +02:00
|
|
|
(forEach interfaces (i: {
|
2017-10-05 15:05:30 +02:00
|
|
|
# With the linux kernel, interface name length is limited by IFNAMSIZ
|
|
|
|
# to 16 bytes, including the trailing null byte.
|
|
|
|
# See include/linux/if.h in the kernel sources
|
|
|
|
assertion = stringLength i.name < 16;
|
|
|
|
message = ''
|
|
|
|
The name of networking.interfaces."${i.name}" is too long, it needs to be less than 16 characters.
|
|
|
|
'';
|
2019-08-05 13:03:38 +02:00
|
|
|
})) ++ (forEach slaveIfs (i: {
|
2017-12-03 05:13:14 +01:00
|
|
|
assertion = i.ipv4.addresses == [ ] && i.ipv6.addresses == [ ];
|
2017-11-09 20:27:33 +01:00
|
|
|
message = ''
|
|
|
|
The networking.interfaces."${i.name}" must not have any defined ips when it is a slave.
|
|
|
|
'';
|
2019-08-05 13:03:38 +02:00
|
|
|
})) ++ (forEach interfaces (i: {
|
2020-01-30 11:55:50 +01:00
|
|
|
assertion = i.tempAddress != "disabled" -> cfg.enableIPv6;
|
2018-02-01 12:13:17 +01:00
|
|
|
message = ''
|
|
|
|
Temporary addresses are only needed when IPv6 is enabled.
|
|
|
|
'';
|
nixos: Add system-wide option to set the hostid
The old boot.spl.hostid option was not working correctly due to an
upstream bug.
Instead, now we will create the /etc/hostid file so that all applications
(including the ZFS kernel modules, ZFS user-space applications and other
unrelated programs) pick-up the same system-wide host id. Note that glibc
(and by extension, the `hostid` program) also respect the host id configured in
/etc/hostid, if it exists.
The hostid option is now mandatory when using ZFS because otherwise, ZFS will
require you to force-import your ZFS pools if you want to use them, which is
undesirable because it disables some of the checks that ZFS does to make sure it
is safe to import a ZFS pool.
The /etc/hostid file must also exist when booting the initrd, before the SPL
kernel module is loaded, so that ZFS picks up the hostid correctly.
The complexity in creating the /etc/hostid file is due to having to
write the host ID as a 32-bit binary value, taking into account the
endianness of the machine, while using only shell commands and/or simple
utilities (to avoid exploding the size of the initrd).
2014-10-23 04:59:06 +02:00
|
|
|
})) ++ [
|
|
|
|
{
|
|
|
|
assertion = cfg.hostId == null || (stringLength cfg.hostId == 8 && isHexString cfg.hostId);
|
|
|
|
message = "Invalid value given to the networking.hostId option.";
|
|
|
|
}
|
|
|
|
];
|
2014-08-31 18:46:16 +02:00
|
|
|
|
2013-12-30 10:14:41 +01:00
|
|
|
boot.kernelModules = [ ]
|
|
|
|
++ optional cfg.enableIPv6 "ipv6"
|
|
|
|
++ optional hasVirtuals "tun"
|
2014-06-26 07:13:21 +02:00
|
|
|
++ optional hasSits "sit"
|
2013-12-30 10:14:41 +01:00
|
|
|
++ optional hasBonds "bonding";
|
|
|
|
|
|
|
|
boot.extraModprobeConfig =
|
|
|
|
# This setting is intentional as it prevents default bond devices
|
|
|
|
# from being created.
|
|
|
|
optionalString hasBonds "options bonding max_bonds=0";
|
2011-02-19 18:21:29 +01:00
|
|
|
|
2014-11-20 11:37:48 +01:00
|
|
|
boot.kernel.sysctl = {
|
|
|
|
"net.ipv6.conf.all.disable_ipv6" = mkDefault (!cfg.enableIPv6);
|
|
|
|
"net.ipv6.conf.default.disable_ipv6" = mkDefault (!cfg.enableIPv6);
|
|
|
|
"net.ipv6.conf.all.forwarding" = mkDefault (any (i: i.proxyARP) interfaces);
|
2018-02-01 12:13:17 +01:00
|
|
|
} // listToAttrs (flip concatMap (filter (i: i.proxyARP) interfaces)
|
2019-09-06 23:13:28 +02:00
|
|
|
(i: forEach [ "4" "6" ] (v: nameValuePair "net.ipv${v}.conf.${replaceChars ["."] ["/"] i.name}.proxy_arp" true)))
|
2020-01-30 11:55:50 +01:00
|
|
|
// listToAttrs (forEach interfaces
|
|
|
|
(i: let
|
|
|
|
opt = i.tempAddress;
|
|
|
|
val = { disabled = 0; enabled = 1; default = 2; }.${opt};
|
|
|
|
in nameValuePair "net.ipv6.conf.${replaceChars ["."] ["/"] i.name}.use_tempaddr" val));
|
2010-06-02 23:10:48 +02:00
|
|
|
|
2016-07-01 01:59:18 +02:00
|
|
|
# Capabilities won't work unless we have at-least a 4.3 Linux
|
|
|
|
# kernel because we need the ambient capability
|
2017-01-29 12:39:18 +01:00
|
|
|
security.wrappers = if (versionAtLeast (getVersion config.boot.kernelPackages.kernel) "4.3") then {
|
|
|
|
ping = {
|
|
|
|
source = "${pkgs.iputils.out}/bin/ping";
|
|
|
|
capabilities = "cap_net_raw+p";
|
2017-01-29 05:48:03 +01:00
|
|
|
};
|
2017-01-29 12:39:18 +01:00
|
|
|
} else {
|
|
|
|
ping.source = "${pkgs.iputils.out}/bin/ping";
|
2017-01-29 12:33:56 +01:00
|
|
|
};
|
2011-09-14 20:20:50 +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 =
|
nixos: Add system-wide option to set the hostid
The old boot.spl.hostid option was not working correctly due to an
upstream bug.
Instead, now we will create the /etc/hostid file so that all applications
(including the ZFS kernel modules, ZFS user-space applications and other
unrelated programs) pick-up the same system-wide host id. Note that glibc
(and by extension, the `hostid` program) also respect the host id configured in
/etc/hostid, if it exists.
The hostid option is now mandatory when using ZFS because otherwise, ZFS will
require you to force-import your ZFS pools if you want to use them, which is
undesirable because it disables some of the checks that ZFS does to make sure it
is safe to import a ZFS pool.
The /etc/hostid file must also exist when booting the initrd, before the SPL
kernel module is loaded, so that ZFS picks up the hostid correctly.
The complexity in creating the /etc/hostid file is due to having to
write the host ID as a 32-bit binary value, taking into account the
endianness of the machine, while using only shell commands and/or simple
utilities (to avoid exploding the size of the initrd).
2014-10-23 04:59:06 +02:00
|
|
|
optionalString (cfg.hostName != "") ''
|
|
|
|
hostname "${cfg.hostName}"
|
2010-09-14 13:58:55 +02:00
|
|
|
'';
|
2013-05-22 01:30:24 +02:00
|
|
|
system.activationScripts.domain =
|
2014-11-20 11:37:48 +01:00
|
|
|
optionalString (cfg.domain != null) ''
|
nixos: Add system-wide option to set the hostid
The old boot.spl.hostid option was not working correctly due to an
upstream bug.
Instead, now we will create the /etc/hostid file so that all applications
(including the ZFS kernel modules, ZFS user-space applications and other
unrelated programs) pick-up the same system-wide host id. Note that glibc
(and by extension, the `hostid` program) also respect the host id configured in
/etc/hostid, if it exists.
The hostid option is now mandatory when using ZFS because otherwise, ZFS will
require you to force-import your ZFS pools if you want to use them, which is
undesirable because it disables some of the checks that ZFS does to make sure it
is safe to import a ZFS pool.
The /etc/hostid file must also exist when booting the initrd, before the SPL
kernel module is loaded, so that ZFS picks up the hostid correctly.
The complexity in creating the /etc/hostid file is due to having to
write the host ID as a 32-bit binary value, taking into account the
endianness of the machine, while using only shell commands and/or simple
utilities (to avoid exploding the size of the initrd).
2014-10-23 04:59:06 +02:00
|
|
|
domainname "${cfg.domain}"
|
2013-05-22 01:30:24 +02:00
|
|
|
'';
|
2009-07-16 19:18:54 +02:00
|
|
|
|
2019-08-13 23:52:01 +02:00
|
|
|
environment.etc.hostid = mkIf (cfg.hostId != null)
|
2018-11-08 11:59:03 +01:00
|
|
|
{ source = pkgs.runCommand "gen-hostid" { preferLocalBuild = true; } ''
|
2017-01-01 16:41:34 +01:00
|
|
|
hi="${cfg.hostId}"
|
|
|
|
${if pkgs.stdenv.isBigEndian then ''
|
|
|
|
echo -ne "\x''${hi:0:2}\x''${hi:2:2}\x''${hi:4:2}\x''${hi:6:2}" > $out
|
|
|
|
'' else ''
|
|
|
|
echo -ne "\x''${hi:6:2}\x''${hi:4:2}\x''${hi:2:2}\x''${hi:0:2}" > $out
|
|
|
|
''}
|
|
|
|
'';
|
|
|
|
};
|
nixos: Add system-wide option to set the hostid
The old boot.spl.hostid option was not working correctly due to an
upstream bug.
Instead, now we will create the /etc/hostid file so that all applications
(including the ZFS kernel modules, ZFS user-space applications and other
unrelated programs) pick-up the same system-wide host id. Note that glibc
(and by extension, the `hostid` program) also respect the host id configured in
/etc/hostid, if it exists.
The hostid option is now mandatory when using ZFS because otherwise, ZFS will
require you to force-import your ZFS pools if you want to use them, which is
undesirable because it disables some of the checks that ZFS does to make sure it
is safe to import a ZFS pool.
The /etc/hostid file must also exist when booting the initrd, before the SPL
kernel module is loaded, so that ZFS picks up the hostid correctly.
The complexity in creating the /etc/hostid file is due to having to
write the host ID as a 32-bit binary value, taking into account the
endianness of the machine, while using only shell commands and/or simple
utilities (to avoid exploding the size of the initrd).
2014-10-23 04:59:06 +02:00
|
|
|
|
2017-01-01 16:44:32 +01:00
|
|
|
# static hostname configuration needed for hostnamectl and the
|
|
|
|
# org.freedesktop.hostname1 dbus service (both provided by systemd)
|
2019-08-13 23:52:01 +02:00
|
|
|
environment.etc.hostname = mkIf (cfg.hostName != "")
|
2017-01-01 16:44:32 +01:00
|
|
|
{
|
|
|
|
text = cfg.hostName + "\n";
|
|
|
|
};
|
nixos: Add system-wide option to set the hostid
The old boot.spl.hostid option was not working correctly due to an
upstream bug.
Instead, now we will create the /etc/hostid file so that all applications
(including the ZFS kernel modules, ZFS user-space applications and other
unrelated programs) pick-up the same system-wide host id. Note that glibc
(and by extension, the `hostid` program) also respect the host id configured in
/etc/hostid, if it exists.
The hostid option is now mandatory when using ZFS because otherwise, ZFS will
require you to force-import your ZFS pools if you want to use them, which is
undesirable because it disables some of the checks that ZFS does to make sure it
is safe to import a ZFS pool.
The /etc/hostid file must also exist when booting the initrd, before the SPL
kernel module is loaded, so that ZFS picks up the hostid correctly.
The complexity in creating the /etc/hostid file is due to having to
write the host ID as a 32-bit binary value, taking into account the
endianness of the machine, while using only shell commands and/or simple
utilities (to avoid exploding the size of the initrd).
2014-10-23 04:59:06 +02:00
|
|
|
|
2014-11-20 11:37:48 +01:00
|
|
|
environment.systemPackages =
|
|
|
|
[ pkgs.host
|
|
|
|
pkgs.iproute
|
|
|
|
pkgs.iputils
|
|
|
|
pkgs.nettools
|
2015-07-22 12:51:21 +02:00
|
|
|
]
|
2016-02-01 17:51:10 +01:00
|
|
|
++ optionals config.networking.wireless.enable [
|
2015-07-22 12:51:21 +02:00
|
|
|
pkgs.wirelesstools # FIXME: obsolete?
|
2014-11-20 11:37:48 +01:00
|
|
|
pkgs.iw
|
|
|
|
pkgs.rfkill
|
2015-07-22 12:51:21 +02:00
|
|
|
]
|
|
|
|
++ bridgeStp;
|
2012-10-11 23:59:41 +02:00
|
|
|
|
2016-09-13 11:00:08 +02:00
|
|
|
# The network-interfaces target is kept for backwards compatibility.
|
|
|
|
# New modules must NOT use it.
|
2019-08-13 23:52:01 +02:00
|
|
|
systemd.targets.network-interfaces =
|
2016-09-13 11:00:08 +02:00
|
|
|
{ description = "All Network Interfaces (deprecated)";
|
2014-11-30 07:34:50 +01:00
|
|
|
wantedBy = [ "network.target" ];
|
2014-11-30 07:43:54 +01:00
|
|
|
before = [ "network.target" ];
|
2014-12-02 02:19:06 +01:00
|
|
|
after = [ "network-pre.target" ];
|
2014-11-30 07:34:50 +01:00
|
|
|
unitConfig.X-StopOnReconfiguration = true;
|
|
|
|
};
|
|
|
|
|
2014-11-24 21:06:07 +01:00
|
|
|
systemd.services = {
|
|
|
|
network-local-commands = {
|
|
|
|
description = "Extra networking commands.";
|
2014-11-26 20:19:31 +01:00
|
|
|
before = [ "network.target" ];
|
|
|
|
wantedBy = [ "network.target" ];
|
2014-12-02 02:19:06 +01:00
|
|
|
after = [ "network-pre.target" ];
|
2014-11-24 21:06:07 +01:00
|
|
|
unitConfig.ConditionCapability = "CAP_NET_ADMIN";
|
|
|
|
path = [ pkgs.iproute ];
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
serviceConfig.RemainAfterExit = true;
|
|
|
|
script = ''
|
|
|
|
# Run any user-specified commands.
|
|
|
|
${cfg.localCommands}
|
|
|
|
'';
|
|
|
|
};
|
2019-08-05 13:03:38 +02:00
|
|
|
} // (listToAttrs (forEach interfaces (i:
|
2016-09-30 10:45:48 +02:00
|
|
|
let
|
2018-07-06 21:33:05 +02:00
|
|
|
deviceDependency = if (config.boot.isContainer || i.name == "lo")
|
2016-09-30 10:45:48 +02:00
|
|
|
then []
|
|
|
|
else [ (subsystemDevice i.name) ];
|
|
|
|
in
|
2014-11-24 21:06:07 +01:00
|
|
|
nameValuePair "network-link-${i.name}"
|
|
|
|
{ description = "Link configuration of ${i.name}";
|
|
|
|
wantedBy = [ "network-interfaces.target" ];
|
|
|
|
before = [ "network-interfaces.target" ];
|
2016-09-30 10:45:48 +02:00
|
|
|
bindsTo = deviceDependency;
|
|
|
|
after = [ "network-pre.target" ] ++ deviceDependency;
|
2014-11-28 07:53:50 +01:00
|
|
|
path = [ pkgs.iproute ];
|
2014-11-24 21:06:07 +01:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = true;
|
|
|
|
};
|
|
|
|
script =
|
|
|
|
''
|
|
|
|
echo "Configuring link..."
|
|
|
|
'' + optionalString (i.macAddress != null) ''
|
|
|
|
echo "setting MAC address to ${i.macAddress}..."
|
|
|
|
ip link set "${i.name}" address "${i.macAddress}"
|
|
|
|
'' + optionalString (i.mtu != null) ''
|
|
|
|
echo "setting MTU to ${toString i.mtu}..."
|
|
|
|
ip link set "${i.name}" mtu "${toString i.mtu}"
|
2017-07-27 16:23:20 +02:00
|
|
|
'' + ''
|
|
|
|
echo -n "bringing up interface... "
|
|
|
|
ip link set "${i.name}" up && echo "done" || (echo "failed"; exit 1)
|
2014-11-24 21:06:07 +01:00
|
|
|
'';
|
|
|
|
})));
|
2015-01-14 01:10:39 +01:00
|
|
|
|
|
|
|
services.mstpd = mkIf needsMstpd { enable = true; };
|
|
|
|
|
2015-09-22 15:49:17 +02:00
|
|
|
virtualisation.vswitch = mkIf (cfg.vswitches != { }) { enable = true; };
|
|
|
|
|
2019-04-11 19:41:47 +02:00
|
|
|
services.udev.packages = [
|
|
|
|
(pkgs.writeTextFile rec {
|
2019-07-09 08:06:52 +02:00
|
|
|
name = "ipv6-privacy-extensions.rules";
|
|
|
|
destination = "/etc/udev/rules.d/98-${name}";
|
2019-04-11 19:41:47 +02:00
|
|
|
text = ''
|
2019-07-09 08:06:52 +02:00
|
|
|
# enable and prefer IPv6 privacy addresses by default
|
2019-09-28 19:31:31 +02:00
|
|
|
ACTION=="add", SUBSYSTEM=="net", RUN+="${pkgs.bash}/bin/sh -c 'echo 2 > /proc/sys/net/ipv6/conf/%k/use_tempaddr'"
|
2019-04-11 19:41:47 +02:00
|
|
|
'';
|
2019-07-09 08:06:52 +02:00
|
|
|
})
|
|
|
|
(pkgs.writeTextFile rec {
|
|
|
|
name = "ipv6-privacy-extensions.rules";
|
|
|
|
destination = "/etc/udev/rules.d/99-${name}";
|
2020-01-30 11:55:50 +01:00
|
|
|
text = concatMapStrings (i:
|
|
|
|
let
|
|
|
|
opt = i.tempAddress;
|
|
|
|
val = if opt == "disabled" then 0 else 1;
|
|
|
|
msg = if opt == "disabled"
|
|
|
|
then "completely disable IPv6 privacy addresses"
|
|
|
|
else "enable IPv6 privacy addresses but prefer EUI-64 addresses";
|
|
|
|
in
|
|
|
|
''
|
|
|
|
# override to ${msg} for ${i.name}
|
|
|
|
ACTION=="add", SUBSYSTEM=="net", RUN+="${pkgs.procps}/bin/sysctl net.ipv6.conf.${replaceChars ["."] ["/"] i.name}.use_tempaddr=${toString val}"
|
|
|
|
'') (filter (i: i.tempAddress != "default") interfaces);
|
2019-07-09 08:06:52 +02:00
|
|
|
})
|
|
|
|
] ++ lib.optional (cfg.wlanInterfaces != {})
|
2015-09-28 18:43:40 +02:00
|
|
|
(pkgs.writeTextFile {
|
2015-10-06 18:45:50 +02:00
|
|
|
name = "99-zzz-40-wlanInterfaces.rules";
|
|
|
|
destination = "/etc/udev/rules.d/99-zzz-40-wlanInterfaces.rules";
|
2015-10-04 10:57:16 +02:00
|
|
|
text =
|
|
|
|
let
|
|
|
|
# Collect all interfaces that are defined for a device
|
|
|
|
# as device:interface key:value pairs.
|
|
|
|
wlanDeviceInterfaces =
|
|
|
|
let
|
|
|
|
allDevices = unique (mapAttrsToList (_: v: v.device) cfg.wlanInterfaces);
|
|
|
|
interfacesOfDevice = d: filterAttrs (_: v: v.device == d) cfg.wlanInterfaces;
|
|
|
|
in
|
|
|
|
genAttrs allDevices (d: interfacesOfDevice d);
|
|
|
|
|
|
|
|
# Convert device:interface key:value pairs into a list, and if it exists,
|
|
|
|
# place the interface which is named after the device at the beginning.
|
|
|
|
wlanListDeviceFirst = device: interfaces:
|
|
|
|
if hasAttr device interfaces
|
|
|
|
then mapAttrsToList (n: v: v//{_iName=n;}) (filterAttrs (n: _: n==device) interfaces) ++ mapAttrsToList (n: v: v//{_iName=n;}) (filterAttrs (n: _: n!=device) interfaces)
|
|
|
|
else mapAttrsToList (n: v: v // {_iName = n;}) interfaces;
|
|
|
|
|
|
|
|
# Udev script to execute for the default WLAN interface with the persistend udev name.
|
|
|
|
# The script creates the required, new WLAN interfaces interfaces and configures the
|
|
|
|
# existing, default interface.
|
|
|
|
curInterfaceScript = device: current: new: pkgs.writeScript "udev-run-script-wlan-interfaces-${device}.sh" ''
|
2018-03-01 20:38:53 +01:00
|
|
|
#!${pkgs.runtimeShell}
|
2015-10-04 10:57:16 +02:00
|
|
|
# Change the wireless phy device to a predictable name.
|
|
|
|
${pkgs.iw}/bin/iw phy `${pkgs.coreutils}/bin/cat /sys/class/net/$INTERFACE/phy80211/name` set name ${device}
|
|
|
|
|
|
|
|
# Add new WLAN interfaces
|
|
|
|
${flip concatMapStrings new (i: ''
|
|
|
|
${pkgs.iw}/bin/iw phy ${device} interface add ${i._iName} type managed
|
|
|
|
'')}
|
|
|
|
|
|
|
|
# Configure the current interface
|
|
|
|
${pkgs.iw}/bin/iw dev ${device} set type ${current.type}
|
|
|
|
${optionalString (current.type == "mesh" && current.meshID!=null) "${pkgs.iw}/bin/iw dev ${device} set meshid ${current.meshID}"}
|
|
|
|
${optionalString (current.type == "monitor" && current.flags!=null) "${pkgs.iw}/bin/iw dev ${device} set monitor ${current.flags}"}
|
|
|
|
${optionalString (current.type == "managed" && current.fourAddr!=null) "${pkgs.iw}/bin/iw dev ${device} set 4addr ${if current.fourAddr then "on" else "off"}"}
|
|
|
|
${optionalString (current.mac != null) "${pkgs.iproute}/bin/ip link set dev ${device} address ${current.mac}"}
|
|
|
|
'';
|
|
|
|
|
|
|
|
# Udev script to execute for a new WLAN interface. The script configures the new WLAN interface.
|
2017-05-28 08:34:43 +02:00
|
|
|
newInterfaceScript = device: new: pkgs.writeScript "udev-run-script-wlan-interfaces-${new._iName}.sh" ''
|
2018-03-01 20:38:53 +01:00
|
|
|
#!${pkgs.runtimeShell}
|
2015-10-04 10:57:16 +02:00
|
|
|
# Configure the new interface
|
|
|
|
${pkgs.iw}/bin/iw dev ${new._iName} set type ${new.type}
|
|
|
|
${optionalString (new.type == "mesh" && new.meshID!=null) "${pkgs.iw}/bin/iw dev ${device} set meshid ${new.meshID}"}
|
|
|
|
${optionalString (new.type == "monitor" && new.flags!=null) "${pkgs.iw}/bin/iw dev ${device} set monitor ${new.flags}"}
|
|
|
|
${optionalString (new.type == "managed" && new.fourAddr!=null) "${pkgs.iw}/bin/iw dev ${device} set 4addr ${if new.fourAddr then "on" else "off"}"}
|
|
|
|
${optionalString (new.mac != null) "${pkgs.iproute}/bin/ip link set dev ${device} address ${new.mac}"}
|
|
|
|
'';
|
|
|
|
|
|
|
|
# Udev attributes for systemd to name the device and to create a .device target.
|
|
|
|
systemdAttrs = n: ''NAME:="${n}", ENV{INTERFACE}:="${n}", ENV{SYSTEMD_ALIAS}:="/sys/subsystem/net/devices/${n}", TAG+="systemd"'';
|
|
|
|
in
|
|
|
|
flip (concatMapStringsSep "\n") (attrNames wlanDeviceInterfaces) (device:
|
|
|
|
let
|
2019-08-13 23:52:01 +02:00
|
|
|
interfaces = wlanListDeviceFirst device wlanDeviceInterfaces.${device};
|
2015-10-04 10:57:16 +02:00
|
|
|
curInterface = elemAt interfaces 0;
|
|
|
|
newInterfaces = drop 1 interfaces;
|
|
|
|
in ''
|
|
|
|
# It is important to have that rule first as overwriting the NAME attribute also prevents the
|
|
|
|
# next rules from matching.
|
2019-08-13 23:52:01 +02:00
|
|
|
${flip (concatMapStringsSep "\n") (wlanListDeviceFirst device wlanDeviceInterfaces.${device}) (interface:
|
2017-05-28 08:34:43 +02:00
|
|
|
''ACTION=="add", SUBSYSTEM=="net", ENV{DEVTYPE}=="wlan", ENV{INTERFACE}=="${interface._iName}", ${systemdAttrs interface._iName}, RUN+="${newInterfaceScript device interface}"'')}
|
2015-10-04 10:57:16 +02:00
|
|
|
|
|
|
|
# Add the required, new WLAN interfaces to the default WLAN interface with the
|
|
|
|
# persistent, default name as assigned by udev.
|
|
|
|
ACTION=="add", SUBSYSTEM=="net", ENV{DEVTYPE}=="wlan", NAME=="${device}", ${systemdAttrs curInterface._iName}, RUN+="${curInterfaceScript device curInterface newInterfaces}"
|
|
|
|
# Generate the same systemd events for both 'add' and 'move' udev events.
|
|
|
|
ACTION=="move", SUBSYSTEM=="net", ENV{DEVTYPE}=="wlan", NAME=="${device}", ${systemdAttrs curInterface._iName}
|
|
|
|
'');
|
2019-04-11 19:41:47 +02:00
|
|
|
});
|
2009-07-16 19:18:54 +02:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2006-11-20 18:06:44 +01:00
|
|
|
}
|