2018-07-20 21:56:59 +01:00
|
|
|
{ config, options, lib, pkgs, utils, ... }:
|
2009-03-06 12:27:38 +00:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2014-08-28 23:27:20 +01:00
|
|
|
with utils;
|
2007-02-12 16:00:55 +00:00
|
|
|
|
2009-10-12 18:27:57 +01:00
|
|
|
let
|
2009-05-28 17:03:48 +01:00
|
|
|
|
2009-07-16 18:18:54 +01:00
|
|
|
cfg = config.networking;
|
2021-12-05 20:45:35 +00:00
|
|
|
opt = options.networking;
|
2012-11-02 16:08:11 +00:00
|
|
|
interfaces = attrValues cfg.interfaces;
|
|
|
|
hasVirtuals = any (i: i.virtual) interfaces;
|
2014-06-26 06:13:21 +01:00
|
|
|
hasSits = cfg.sits != { };
|
2021-12-07 15:44:00 +00:00
|
|
|
hasGres = cfg.greTunnels != { };
|
2013-12-30 09:14:41 +00:00
|
|
|
hasBonds = cfg.bonds != { };
|
2021-08-11 11:48:43 +01:00
|
|
|
hasFous = cfg.fooOverUDP != { }
|
|
|
|
|| filterAttrs (_: s: s.encapsulation != null) cfg.sits != { };
|
2012-11-02 16:08:11 +00:00
|
|
|
|
2014-11-30 06:34:50 +00:00
|
|
|
slaves = concatMap (i: i.interfaces) (attrValues cfg.bonds)
|
2015-09-22 14:49:17 +01:00
|
|
|
++ concatMap (i: i.interfaces) (attrValues cfg.bridges)
|
2018-12-29 10:16:51 +00:00
|
|
|
++ concatMap (i: attrNames (filterAttrs (name: config: ! (config.type == "internal" || hasAttr name cfg.interfaces)) i.interfaces)) (attrValues cfg.vswitches);
|
2014-11-30 06:34:50 +00:00
|
|
|
|
2014-11-30 13:16:07 +00:00
|
|
|
slaveIfs = map (i: cfg.interfaces.${i}) (filter (i: cfg.interfaces ? ${i}) slaves);
|
2014-11-30 06:34:50 +00:00
|
|
|
|
2015-01-14 00:10:39 +00: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 19:38:53 +00:00
|
|
|
#!${pkgs.runtimeShell} -e
|
2015-01-14 00:10:39 +00: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 20:06:07 +00:00
|
|
|
# We must escape interfaces due to the systemd interpretation
|
|
|
|
subsystemDevice = interface:
|
|
|
|
"sys-subsystem-net-devices-${escapeSystemdPath interface}.device";
|
|
|
|
|
2014-08-31 17:46:16 +01:00
|
|
|
addrOpts = v:
|
|
|
|
assert v == 4 || v == 6;
|
2016-09-11 11:45:24 +01:00
|
|
|
{ options = {
|
|
|
|
address = mkOption {
|
|
|
|
type = types.str;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2017-07-27 15:23:20 +01:00
|
|
|
IPv${toString v} address of the interface. Leave empty to configure the
|
2016-09-11 11:45:24 +01:00
|
|
|
interface using DHCP.
|
|
|
|
'';
|
|
|
|
};
|
2014-08-31 17:46:16 +01:00
|
|
|
|
2016-09-11 11:45:24 +01:00
|
|
|
prefixLength = mkOption {
|
|
|
|
type = types.addCheck types.int (n: n >= 0 && n <= (if v == 4 then 32 else 128));
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2016-09-11 11:45:24 +01:00
|
|
|
Subnet mask of the interface, specified as the number of
|
2022-07-28 22:19:15 +01:00
|
|
|
bits in the prefix (`${if v == 4 then "24" else "64"}`).
|
2016-09-11 11:45:24 +01:00
|
|
|
'';
|
|
|
|
};
|
2014-08-31 17:46:16 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-07-27 15:23:20 +01:00
|
|
|
routeOpts = v:
|
|
|
|
{ options = {
|
|
|
|
address = mkOption {
|
|
|
|
type = types.str;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "IPv${toString v} address of the network.";
|
2017-07-27 15:23:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
prefixLength = mkOption {
|
|
|
|
type = types.addCheck types.int (n: n >= 0 && n <= (if v == 4 then 32 else 128));
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2017-07-27 15:23:20 +01:00
|
|
|
Subnet mask of the network, specified as the number of
|
2022-07-28 22:19:15 +01:00
|
|
|
bits in the prefix (`${if v == 4 then "24" else "64"}`).
|
2017-07-27 15:23:20 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-06-02 19:16:25 +01:00
|
|
|
type = mkOption {
|
|
|
|
type = types.nullOr (types.enum [
|
|
|
|
"unicast" "local" "broadcast" "multicast"
|
|
|
|
]);
|
|
|
|
default = null;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Type of the route. See the `Route types` section
|
|
|
|
in the `ip-route(8)` manual page for the details.
|
2022-06-02 19:16:25 +01:00
|
|
|
|
2022-07-28 22:19:15 +01:00
|
|
|
Note that `prohibit`, `blackhole`,
|
|
|
|
`unreachable`, and `throw` cannot
|
2022-06-02 19:16:25 +01:00
|
|
|
be configured per device, so they are not available here. Similarly,
|
2022-07-28 22:19:15 +01:00
|
|
|
`nat` hasn't been supported since kernel 2.6.
|
2022-06-02 19:16:25 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-07-28 15:45:58 +01:00
|
|
|
via = mkOption {
|
2017-07-27 15:23:20 +01:00
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "IPv${toString v} address of the next hop.";
|
2017-07-27 15:23:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
options = mkOption {
|
2017-07-28 15:45:58 +01:00
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = { };
|
|
|
|
example = { mtu = "1492"; window = "524288"; };
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Other route options. See the symbol `OPTIONS`
|
|
|
|
in the `ip-route(8)` manual page for the details.
|
|
|
|
You may also specify `metric`,
|
|
|
|
`src`, `protocol`,
|
|
|
|
`scope`, `from`
|
|
|
|
and `table`, which are technically
|
2021-11-03 23:19:54 +00:00
|
|
|
not route options, in the sense used in the manual.
|
2017-07-27 15:23:20 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-01-14 01:14:16 +00:00
|
|
|
gatewayCoerce = address: { inherit address; };
|
|
|
|
|
|
|
|
gatewayOpts = { ... }: {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
address = mkOption {
|
|
|
|
type = types.str;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "The default gateway address.";
|
2017-01-14 01:14:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
interface = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "enp0s3";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "The default gateway interface.";
|
2017-01-14 01:14:16 +00:00
|
|
|
};
|
|
|
|
|
2017-02-09 22:09:07 +00:00
|
|
|
metric = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
example = 42;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "The default gateway metric/preference.";
|
2017-02-09 22:09:07 +00:00
|
|
|
};
|
|
|
|
|
2017-01-14 01:14:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-11-02 16:08:11 +00:00
|
|
|
interfaceOpts = { name, ... }: {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
name = mkOption {
|
|
|
|
example = "eth0";
|
2013-10-30 10:02:04 +00:00
|
|
|
type = types.str;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "Name of the interface.";
|
2012-11-02 16:08:11 +00:00
|
|
|
};
|
|
|
|
|
2020-01-30 10:55:50 +00:00
|
|
|
tempAddress = mkOption {
|
2021-03-30 10:49:13 +01:00
|
|
|
type = types.enum (lib.attrNames tempaddrValues);
|
|
|
|
default = cfg.tempAddresses;
|
2021-10-03 17:06:03 +01:00
|
|
|
defaultText = literalExpression ''config.networking.tempAddresses'';
|
2022-08-20 22:22:50 +01:00
|
|
|
description = lib.mdDoc ''
|
2020-01-30 10:55:50 +00:00
|
|
|
When IPv6 is enabled with SLAAC, this option controls the use of
|
2021-03-30 10:49:13 +01:00
|
|
|
temporary address (aka privacy extensions) on this
|
|
|
|
interface. This is used to reduce tracking.
|
|
|
|
|
|
|
|
See also the global option
|
2022-08-20 22:22:50 +01:00
|
|
|
[](#opt-networking.tempAddresses), which
|
2021-03-30 10:49:13 +01:00
|
|
|
applies to all interfaces where this is not set.
|
|
|
|
|
|
|
|
Possible values are:
|
|
|
|
${tempaddrDoc}
|
2018-02-01 11:13:17 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-11-20 10:37:48 +00:00
|
|
|
useDHCP = mkOption {
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
default = null;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2014-11-20 10:37:48 +00:00
|
|
|
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 04:13:14 +00:00
|
|
|
ipv4.addresses = mkOption {
|
2014-08-31 17:46:16 +01:00
|
|
|
default = [ ];
|
|
|
|
example = [
|
|
|
|
{ address = "10.0.0.1"; prefixLength = 16; }
|
|
|
|
{ address = "192.168.1.1"; prefixLength = 24; }
|
|
|
|
];
|
2016-09-11 11:45:24 +01:00
|
|
|
type = with types; listOf (submodule (addrOpts 4));
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2014-08-31 17:46:16 +01:00
|
|
|
List of IPv4 addresses that will be statically assigned to the interface.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-12-03 04:13:14 +00:00
|
|
|
ipv6.addresses = mkOption {
|
2014-08-31 17:46:16 +01:00
|
|
|
default = [ ];
|
|
|
|
example = [
|
|
|
|
{ address = "fdfd:b3f0:482::1"; prefixLength = 48; }
|
|
|
|
{ address = "2001:1470:fffd:2098::e006"; prefixLength = 64; }
|
|
|
|
];
|
2016-09-11 11:45:24 +01:00
|
|
|
type = with types; listOf (submodule (addrOpts 6));
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2014-08-31 17:46:16 +01:00
|
|
|
List of IPv6 addresses that will be statically assigned to the interface.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-12-03 04:13:14 +00:00
|
|
|
ipv4.routes = mkOption {
|
2017-07-27 15:23:20 +01:00
|
|
|
default = [];
|
|
|
|
example = [
|
|
|
|
{ address = "10.0.0.0"; prefixLength = 16; }
|
2017-07-28 15:45:58 +01:00
|
|
|
{ address = "192.168.2.0"; prefixLength = 24; via = "192.168.1.1"; }
|
2017-07-27 15:23:20 +01:00
|
|
|
];
|
|
|
|
type = with types; listOf (submodule (routeOpts 4));
|
2022-08-20 22:22:50 +01:00
|
|
|
description = lib.mdDoc ''
|
2017-07-27 15:23:20 +01:00
|
|
|
List of extra IPv4 static routes that will be assigned to the interface.
|
2022-08-20 22:22:50 +01:00
|
|
|
|
|
|
|
::: {.warning}
|
|
|
|
If the route type is the default `unicast`, then the scope
|
|
|
|
is set differently depending on the value of {option}`networking.useNetworkd`:
|
|
|
|
the script-based backend sets it to `link`, while networkd sets
|
|
|
|
it to `global`.
|
|
|
|
:::
|
|
|
|
|
2021-11-03 23:19:54 +00:00
|
|
|
If you want consistency between the two implementations,
|
|
|
|
set the scope of the route manually with
|
2022-08-20 22:22:50 +01:00
|
|
|
`networking.interfaces.eth0.ipv4.routes = [{ options.scope = "global"; }]`
|
2021-11-03 23:19:54 +00:00
|
|
|
for example.
|
2017-07-27 15:23:20 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-12-03 04:13:14 +00:00
|
|
|
ipv6.routes = mkOption {
|
2017-07-27 15:23:20 +01:00
|
|
|
default = [];
|
|
|
|
example = [
|
|
|
|
{ address = "fdfd:b3f0::"; prefixLength = 48; }
|
2017-07-28 15:45:58 +01:00
|
|
|
{ address = "2001:1470:fffd:2098::"; prefixLength = 64; via = "fdfd:b3f0::1"; }
|
2017-07-27 15:23:20 +01:00
|
|
|
];
|
|
|
|
type = with types; listOf (submodule (routeOpts 6));
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2017-07-27 15:23:20 +01:00
|
|
|
List of extra IPv6 static routes that will be assigned to the interface.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2012-11-02 16:08:11 +00:00
|
|
|
macAddress = mkOption {
|
|
|
|
default = null;
|
|
|
|
example = "00:11:22:33:44:55";
|
2013-10-30 10:02:04 +00:00
|
|
|
type = types.nullOr (types.str);
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2012-11-02 16:08:11 +00:00
|
|
|
MAC address of the interface. Leave empty to use the default.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-12-30 02:58:59 +00:00
|
|
|
mtu = mkOption {
|
|
|
|
default = null;
|
|
|
|
example = 9000;
|
|
|
|
type = types.nullOr types.int;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2013-12-30 02:58:59 +00:00
|
|
|
MTU size for packets leaving the interface. Leave empty to use the default.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2012-11-02 16:08:11 +00:00
|
|
|
virtual = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2012-11-02 16:08:11 +00:00
|
|
|
Whether this interface is virtual and should be created by tunctl.
|
2016-09-13 07:04:00 +01:00
|
|
|
This is mainly useful for creating bridges between a host and a virtual
|
2012-11-02 16:08:11 +00:00
|
|
|
network such as VPN or a virtual machine.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
virtualOwner = mkOption {
|
|
|
|
default = "root";
|
2013-10-30 10:02:04 +00:00
|
|
|
type = types.str;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2012-11-02 16:08:11 +00:00
|
|
|
In case of a virtual device, the user who owns it.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-08-24 02:38:29 +01:00
|
|
|
virtualType = mkOption {
|
2018-01-31 04:51:09 +00:00
|
|
|
default = if hasPrefix "tun" name then "tun" else "tap";
|
2021-10-03 17:06:03 +01:00
|
|
|
defaultText = literalExpression ''if hasPrefix "tun" name then "tun" else "tap"'';
|
2018-01-31 04:51:09 +00:00
|
|
|
type = with types; enum [ "tun" "tap" ];
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2018-01-31 04:51:09 +00:00
|
|
|
The type of interface to create.
|
|
|
|
The default is TUN for an interface name starting
|
|
|
|
with "tun", otherwise TAP.
|
2014-08-24 02:38:29 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2012-11-02 16:08:11 +00:00
|
|
|
proxyARP = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2020-05-24 20:19:50 +01:00
|
|
|
Turn on proxy_arp for this device.
|
2012-11-02 16:08:11 +00:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-10-02 01:08:39 +01:00
|
|
|
wakeOnLan = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "Whether to enable wol on this interface.";
|
2021-10-02 01:08:39 +01:00
|
|
|
};
|
|
|
|
};
|
2012-11-02 16:08:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
name = mkDefault name;
|
|
|
|
};
|
|
|
|
|
2017-12-03 04:13:14 +00:00
|
|
|
# Renamed or removed options
|
|
|
|
imports =
|
|
|
|
let
|
|
|
|
defined = x: x != "_mkMergedOptionModule";
|
|
|
|
in [
|
2020-01-30 10:55:50 +00:00
|
|
|
(mkChangedOptionModule [ "preferTempAddress" ] [ "tempAddress" ]
|
|
|
|
(config:
|
|
|
|
let bool = getAttrFromPath [ "preferTempAddress" ] config;
|
|
|
|
in if bool then "default" else "enabled"
|
|
|
|
))
|
2017-12-03 04:13:14 +00: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 16:13:29 +01:00
|
|
|
({ options.warnings = options.warnings; options.assertions = options.assertions; })
|
2017-12-03 04:13:14 +00:00
|
|
|
];
|
|
|
|
|
2012-11-02 16:08:11 +00:00
|
|
|
};
|
2009-07-16 18:18:54 +01:00
|
|
|
|
2018-12-29 10:16:51 +00:00
|
|
|
vswitchInterfaceOpts = {name, ...}: {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
name = mkOption {
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "Name of the interface";
|
2018-12-29 10:16:51 +00:00
|
|
|
example = "eth0";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
vlan = mkOption {
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "Vlan tag to apply to interface";
|
2018-12-29 10:16:51 +00:00
|
|
|
example = 10;
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
type = mkOption {
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "Openvswitch type to assign to interface";
|
2018-12-29 10:16:51 +00:00
|
|
|
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 03:59:06 +01:00
|
|
|
hexChars = stringToCharacters "0123456789abcdef";
|
|
|
|
|
|
|
|
isHexString = s: all (c: elem c hexChars) (stringToCharacters (toLower s));
|
|
|
|
|
2021-03-30 10:49:13 +01:00
|
|
|
tempaddrValues = {
|
|
|
|
disabled = {
|
|
|
|
sysctl = "0";
|
|
|
|
description = "completely disable IPv6 temporary addresses";
|
|
|
|
};
|
|
|
|
enabled = {
|
|
|
|
sysctl = "1";
|
|
|
|
description = "generate IPv6 temporary addresses but still use EUI-64 addresses as source addresses";
|
|
|
|
};
|
|
|
|
default = {
|
|
|
|
sysctl = "2";
|
|
|
|
description = "generate IPv6 temporary addresses and use these as source addresses in routing";
|
|
|
|
};
|
|
|
|
};
|
2022-08-20 22:22:50 +01:00
|
|
|
tempaddrDoc = concatStringsSep "\n"
|
|
|
|
(mapAttrsToList
|
|
|
|
(name: { description, ... }: ''- `"${name}"` to ${description};'')
|
|
|
|
tempaddrValues);
|
2021-03-30 10:49:13 +01:00
|
|
|
|
2022-04-16 21:31:58 +01:00
|
|
|
hostidFile = pkgs.runCommand "gen-hostid" { preferLocalBuild = true; } ''
|
|
|
|
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
|
|
|
|
''}
|
|
|
|
'';
|
|
|
|
|
2011-09-14 19:20:50 +01:00
|
|
|
in
|
2009-07-16 18:18:54 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2009-05-28 17:03:48 +01:00
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
networking.hostName = mkOption {
|
2022-12-17 23:00:58 +00:00
|
|
|
default = config.system.nixos.distroId;
|
|
|
|
defaultText = literalExpression "config.system.nixos.distroId";
|
2020-05-25 13:01:26 +01:00
|
|
|
# Only allow hostnames without the domain name part (i.e. no FQDNs, see
|
|
|
|
# e.g. "man 5 hostname") and require valid DNS labels (recommended
|
|
|
|
# syntax). Note: We also allow underscores for compatibility/legacy
|
|
|
|
# reasons (as undocumented feature):
|
|
|
|
type = types.strMatching
|
2020-09-30 22:21:23 +01:00
|
|
|
"^$|^[[:alnum:]]([[:alnum:]_-]{0,61}[[:alnum:]])?$";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2020-05-25 13:01:26 +01:00
|
|
|
The name of the machine. Leave it empty if you want to obtain it from a
|
|
|
|
DHCP server (if using DHCP). The hostname must be a valid DNS label (see
|
2020-09-30 22:21:23 +01:00
|
|
|
RFC 1035 section 2.3.1: "Preferred name syntax", RFC 1123 section 2.1:
|
|
|
|
"Host Names and Numbers") and as such must not contain the domain part.
|
|
|
|
This means that the hostname must start with a letter or digit,
|
|
|
|
end with a letter or digit, and have as interior characters only
|
2020-05-25 13:01:26 +01:00
|
|
|
letters, digits, and hyphen. The maximum length is 63 characters.
|
|
|
|
Additionally it is recommended to only use lower-case characters.
|
2020-10-10 14:27:47 +01:00
|
|
|
If (e.g. for legacy reasons) a FQDN is required as the Linux kernel
|
|
|
|
network node hostname (uname --nodename) the option
|
|
|
|
boot.kernel.sysctl."kernel.hostname" can be used as a workaround (but
|
|
|
|
the 64 character limit still applies).
|
2021-11-19 23:32:55 +00:00
|
|
|
|
|
|
|
WARNING: Do not use underscores (_) or you may run into unexpected issues.
|
2009-07-16 18:18:54 +01:00
|
|
|
'';
|
2021-11-19 23:32:55 +00:00
|
|
|
# warning until the issues in https://github.com/NixOS/nixpkgs/pull/138978
|
|
|
|
# are resolved
|
2009-05-28 17:03:48 +01:00
|
|
|
};
|
|
|
|
|
2020-10-10 12:30:47 +01:00
|
|
|
networking.fqdn = mkOption {
|
|
|
|
readOnly = true;
|
|
|
|
type = types.str;
|
|
|
|
default = if (cfg.hostName != "" && cfg.domain != null)
|
|
|
|
then "${cfg.hostName}.${cfg.domain}"
|
|
|
|
else throw ''
|
|
|
|
The FQDN is required but cannot be determined. Please make sure that
|
|
|
|
both networking.hostName and networking.domain are set properly.
|
|
|
|
'';
|
2021-10-03 17:06:03 +01:00
|
|
|
defaultText = literalExpression ''"''${networking.hostName}.''${networking.domain}"'';
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2020-10-10 12:30:47 +01:00
|
|
|
The fully qualified domain name (FQDN) of this host. It is the result
|
2022-10-15 10:56:42 +01:00
|
|
|
of combining `networking.hostName` and `networking.domain.` Using this
|
2020-10-10 12:30:47 +01:00
|
|
|
option will result in an evaluation error if the hostname is empty or
|
|
|
|
no domain is specified.
|
2022-10-15 10:56:42 +01:00
|
|
|
|
|
|
|
Modules that accept a mere `networing.hostName` but prefer a fully qualified
|
|
|
|
domain name may use `networking.fqdnOrHostName` instead.
|
2020-10-10 12:30:47 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-10-06 15:21:09 +01:00
|
|
|
networking.fqdnOrHostName = mkOption {
|
|
|
|
readOnly = true;
|
|
|
|
type = types.str;
|
|
|
|
default = if cfg.domain == null then cfg.hostName else cfg.fqdn;
|
|
|
|
defaultText = literalExpression ''
|
|
|
|
if cfg.domain == null then cfg.hostName else cfg.fqdn
|
|
|
|
'';
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Either the fully qualified domain name (FQDN), or just the host name if
|
|
|
|
it does not exists.
|
|
|
|
|
|
|
|
This is a convenience option for modules to read instead of `fqdn` when
|
2022-10-15 10:56:42 +01:00
|
|
|
a mere `hostName` is also an acceptable value; this option does not
|
|
|
|
throw an error when `domain` is unset.
|
2020-10-10 12:30:47 +01: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 03:59:06 +01:00
|
|
|
networking.hostId = mkOption {
|
|
|
|
default = null;
|
|
|
|
example = "4e98920d";
|
|
|
|
type = types.nullOr types.str;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
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 03:59:06 +01:00
|
|
|
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 21:52:29 +00: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 03:59:06 +01:00
|
|
|
|
2022-07-28 22:19:15 +01:00
|
|
|
`head -c 8 /etc/machine-id`
|
2016-09-30 09:45:48 +01:00
|
|
|
|
2014-12-18 21:52:29 +00:00
|
|
|
(this derives it from the machine-id that systemd generates) or
|
2016-09-30 09:45:48 +01:00
|
|
|
|
2022-07-28 22:19:15 +01:00
|
|
|
`head -c4 /dev/urandom | od -A none -t x4`
|
2020-08-08 20:30:50 +01:00
|
|
|
|
|
|
|
The primary use case is to ensure when using ZFS that a pool isn't imported
|
|
|
|
accidentally on a wrong machine.
|
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 03:59:06 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2011-02-19 17:21:29 +00:00
|
|
|
networking.enableIPv6 = mkOption {
|
|
|
|
default = true;
|
2014-11-20 10:37:48 +00:00
|
|
|
type = types.bool;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2011-02-19 17:21:29 +00:00
|
|
|
Whether to enable support for IPv6.
|
2009-07-16 18:18:54 +01:00
|
|
|
'';
|
2009-05-28 17:03:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
networking.defaultGateway = mkOption {
|
2014-11-20 10:37:48 +00:00
|
|
|
default = null;
|
2017-01-14 01:14:16 +00:00
|
|
|
example = {
|
|
|
|
address = "131.211.84.1";
|
2017-02-21 14:41:37 +00:00
|
|
|
interface = "enp3s0";
|
2017-01-14 01:14:16 +00:00
|
|
|
};
|
|
|
|
type = types.nullOr (types.coercedTo types.str gatewayCoerce (types.submodule gatewayOpts));
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2017-01-14 01:14:16 +00: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 18:18:54 +01:00
|
|
|
'';
|
2009-05-28 17:03:48 +01:00
|
|
|
};
|
|
|
|
|
2014-12-18 01:54:06 +00:00
|
|
|
networking.defaultGateway6 = mkOption {
|
|
|
|
default = null;
|
2017-01-14 01:14:16 +00:00
|
|
|
example = {
|
|
|
|
address = "2001:4d0:1e04:895::1";
|
2017-02-21 14:41:37 +00:00
|
|
|
interface = "enp3s0";
|
2017-01-14 01:14:16 +00:00
|
|
|
};
|
|
|
|
type = types.nullOr (types.coercedTo types.str gatewayCoerce (types.submodule gatewayOpts));
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2017-01-14 01:14:16 +00: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 01:54:06 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-01-06 21:31:13 +00:00
|
|
|
networking.defaultGatewayWindowSize = mkOption {
|
2013-01-06 22:20:48 +00:00
|
|
|
default = null;
|
|
|
|
example = 524288;
|
|
|
|
type = types.nullOr types.int;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2013-01-06 21:31:13 +00:00
|
|
|
The window size of the default gateway. It limits maximal data bursts that TCP peers
|
|
|
|
are allowed to send to us.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-05-28 17:03:48 +01:00
|
|
|
networking.nameservers = mkOption {
|
2016-01-17 18:34:55 +00:00
|
|
|
type = types.listOf types.str;
|
2009-05-28 17:03:48 +01:00
|
|
|
default = [];
|
|
|
|
example = ["130.161.158.4" "130.161.33.17"];
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2009-05-28 17:03:48 +01:00
|
|
|
The list of nameservers. It can be left empty if it is auto-detected through DHCP.
|
2009-07-16 18:18:54 +01:00
|
|
|
'';
|
2009-05-28 17:03:48 +01:00
|
|
|
};
|
|
|
|
|
2014-04-24 23:46:12 +01:00
|
|
|
networking.search = mkOption {
|
|
|
|
default = [];
|
2020-10-10 13:10:52 +01:00
|
|
|
example = [ "example.com" "home.arpa" ];
|
2014-04-24 23:46:12 +01:00
|
|
|
type = types.listOf types.str;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2014-04-24 23:46:12 +01:00
|
|
|
The list of search paths used when resolving domain names.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-05-28 17:03:48 +01:00
|
|
|
networking.domain = mkOption {
|
2014-11-20 10:37:48 +00:00
|
|
|
default = null;
|
2020-10-10 13:10:52 +01:00
|
|
|
example = "home.arpa";
|
2014-11-20 10:37:48 +00:00
|
|
|
type = types.nullOr types.str;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2009-05-28 17:03:48 +01:00
|
|
|
The domain. It can be left empty if it is auto-detected through DHCP.
|
2009-07-16 18:18:54 +01:00
|
|
|
'';
|
2009-05-28 17:03:48 +01:00
|
|
|
};
|
|
|
|
|
2014-04-18 15:40:27 +01:00
|
|
|
networking.useHostResolvConf = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2014-04-18 15:40:27 +01:00
|
|
|
In containers, whether to use the
|
2022-07-28 22:19:15 +01:00
|
|
|
{file}`resolv.conf` supplied by the host.
|
2014-04-18 15:40:27 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-05-28 17:03:48 +01:00
|
|
|
networking.localCommands = mkOption {
|
2016-09-20 12:29:40 +01:00
|
|
|
type = types.lines;
|
2009-05-28 17:03:48 +01:00
|
|
|
default = "";
|
|
|
|
example = "text=anything; echo You can put $text here.";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2009-05-28 17:03:48 +01:00
|
|
|
Shell commands to be executed at the end of the
|
2022-07-28 22:19:15 +01:00
|
|
|
`network-setup` systemd service. Note that if
|
2009-05-28 17:03:48 +01:00
|
|
|
you are using DHCP to obtain the network configuration,
|
|
|
|
interfaces may not be fully configured yet.
|
2009-07-16 18:18:54 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.interfaces = mkOption {
|
2012-11-02 16:08:11 +00:00
|
|
|
default = {};
|
|
|
|
example =
|
2018-03-16 16:06:20 +00:00
|
|
|
{ eth0.ipv4.addresses = [ {
|
2014-08-31 17:46:16 +01:00
|
|
|
address = "131.211.84.78";
|
|
|
|
prefixLength = 25;
|
|
|
|
} ];
|
2012-11-02 16:08:11 +00:00
|
|
|
};
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2009-07-16 18:18:54 +01:00
|
|
|
The configuration for each network interface. If
|
2022-07-28 22:19:15 +01:00
|
|
|
{option}`networking.useDHCP` is true, then every
|
2009-07-16 18:18:54 +01:00
|
|
|
interface not listed here will be configured using DHCP.
|
2022-09-15 17:07:24 +01:00
|
|
|
|
|
|
|
Please note that {option}`systemd.network.netdevs` has more features
|
|
|
|
and is better maintained. When building new things, it is advised to
|
|
|
|
use that instead.
|
2009-07-16 18:18:54 +01:00
|
|
|
'';
|
2020-08-23 00:28:45 +01:00
|
|
|
type = with types; attrsOf (submodule interfaceOpts);
|
2010-05-21 15:12:03 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2015-09-22 14:49:17 +01:00
|
|
|
networking.vswitches = mkOption {
|
|
|
|
default = { };
|
|
|
|
example =
|
2018-12-29 10:16:51 +00:00
|
|
|
{ vs0.interfaces = { eth0 = { }; lo1 = { type="internal"; }; };
|
|
|
|
vs1.interfaces = [ { name = "eth2"; } { name = "lo2"; type="internal"; } ];
|
2015-09-22 14:49:17 +01:00
|
|
|
};
|
|
|
|
description =
|
2022-07-28 22:19:15 +01:00
|
|
|
lib.mdDoc ''
|
2015-09-22 14:49:17 +01:00
|
|
|
This option allows you to define Open vSwitches that connect
|
2015-10-05 12:23:58 +01:00
|
|
|
physical networks together. The value of this option is an
|
|
|
|
attribute set. Each attribute specifies a vswitch, with the
|
2015-09-22 14:49:17 +01:00
|
|
|
attribute name specifying the name of the vswitch's network
|
|
|
|
interface.
|
|
|
|
'';
|
|
|
|
|
2016-09-11 11:45:24 +01:00
|
|
|
type = with types; attrsOf (submodule {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
interfaces = mkOption {
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "The physical network interfaces connected by the vSwitch.";
|
2020-08-23 00:28:45 +01:00
|
|
|
type = with types; attrsOf (submodule vswitchInterfaceOpts);
|
2016-09-11 11:45:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
controllers = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [ "ptcp:6653:[::1]" ];
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Specify the controller targets. For the allowed options see `man 8 ovs-vsctl`.
|
2016-09-11 11:45:24 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
openFlowRules = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
actions=normal
|
|
|
|
'';
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
OpenFlow rules to insert into the Open vSwitch. All `openFlowRules` are
|
|
|
|
loaded with `ovs-ofctl` within one atomic operation.
|
2016-09-11 11:45:24 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-12-29 10:16:51 +00: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" ];
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2018-12-29 10:16:51 +00:00
|
|
|
Supported versions to enable on this switch.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
# TODO: use same type as elements from supportedOpenFlowVersions
|
|
|
|
openFlowVersion = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "OpenFlow13";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Version of OpenFlow protocol to use when communicating with the switch internally (e.g. with `openFlowRules`).
|
2018-12-29 10:16:51 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-09-11 11:45:24 +01:00
|
|
|
extraOvsctlCmds = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
set-fail-mode <switch_name> secure
|
|
|
|
set Bridge <switch_name> stp_enable=true
|
|
|
|
'';
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Commands to manipulate the Open vSwitch database. Every line executed with `ovs-vsctl`.
|
2016-09-11 11:45:24 +01:00
|
|
|
All commands are bundled together with the operations for adding the interfaces
|
|
|
|
into one atomic operation.
|
|
|
|
'';
|
|
|
|
};
|
2015-09-22 14:49:17 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-09-11 11:45:24 +01:00
|
|
|
});
|
2015-09-22 14:49:17 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-03-15 15:13:48 +00:00
|
|
|
networking.bridges = mkOption {
|
|
|
|
default = { };
|
|
|
|
example =
|
|
|
|
{ br0.interfaces = [ "eth0" "eth1" ];
|
|
|
|
br1.interfaces = [ "eth2" "wlan0" ];
|
|
|
|
};
|
|
|
|
description =
|
2022-07-28 22:19:15 +01:00
|
|
|
lib.mdDoc ''
|
2011-03-15 15:13:48 +00:00
|
|
|
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 11:45:24 +01:00
|
|
|
type = with types; attrsOf (submodule {
|
2011-03-15 15:13:48 +00:00
|
|
|
|
2016-09-11 11:45:24 +01:00
|
|
|
options = {
|
2011-03-15 15:13:48 +00:00
|
|
|
|
2016-09-11 11:45:24 +01:00
|
|
|
interfaces = mkOption {
|
|
|
|
example = [ "eth0" "eth1" ];
|
|
|
|
type = types.listOf types.str;
|
|
|
|
description =
|
2022-07-28 22:19:15 +01:00
|
|
|
lib.mdDoc "The physical network interfaces connected by the bridge.";
|
2016-09-11 11:45:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
rstp = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "Whether the bridge interface should enable rstp.";
|
2016-09-11 11:45:24 +01:00
|
|
|
};
|
2011-03-15 15:13:48 +00:00
|
|
|
|
2015-01-07 22:34:15 +00:00
|
|
|
};
|
|
|
|
|
2016-09-11 11:45:24 +01:00
|
|
|
});
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2011-03-15 15:13:48 +00:00
|
|
|
};
|
|
|
|
|
2017-03-06 12:23:45 +00:00
|
|
|
networking.bonds =
|
|
|
|
let
|
2020-03-28 23:50:26 +00:00
|
|
|
driverOptionsExample = ''
|
|
|
|
{
|
|
|
|
miimon = "100";
|
|
|
|
mode = "active-backup";
|
|
|
|
}
|
|
|
|
'';
|
2017-03-06 12:23:45 +00:00
|
|
|
in mkOption {
|
|
|
|
default = { };
|
2021-10-03 17:06:03 +01:00
|
|
|
example = literalExpression ''
|
2020-03-28 23:50:26 +00:00
|
|
|
{
|
|
|
|
bond0 = {
|
|
|
|
interfaces = [ "eth0" "wlan0" ];
|
|
|
|
driverOptions = ${driverOptionsExample};
|
|
|
|
};
|
|
|
|
anotherBond.interfaces = [ "enp4s0f0" "enp4s0f1" "enp5s0f0" "enp5s0f1" ];
|
|
|
|
}
|
|
|
|
'';
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2017-03-06 12:23:45 +00:00
|
|
|
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 09:14:41 +00:00
|
|
|
|
2017-03-06 12:23:45 +00:00
|
|
|
type = with types; attrsOf (submodule {
|
2016-09-11 11:45:24 +01:00
|
|
|
|
2017-03-06 12:23:45 +00:00
|
|
|
options = {
|
2016-09-11 11:45:24 +01:00
|
|
|
|
2017-03-06 12:23:45 +00:00
|
|
|
interfaces = mkOption {
|
|
|
|
example = [ "enp4s0f0" "enp4s0f1" "wlan0" ];
|
|
|
|
type = types.listOf types.str;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "The interfaces to bond together";
|
2017-03-06 12:23:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
driverOptions = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = {};
|
2021-10-03 17:06:03 +01:00
|
|
|
example = literalExpression driverOptionsExample;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2017-03-06 12:23:45 +00:00
|
|
|
Options for the bonding driver.
|
|
|
|
Documentation can be found in
|
2022-07-28 22:19:15 +01:00
|
|
|
<https://www.kernel.org/doc/Documentation/networking/bonding.txt>
|
2017-03-06 12:23:45 +00:00
|
|
|
'';
|
2016-09-11 11:45:24 +01:00
|
|
|
|
2017-02-02 21:21:03 +00:00
|
|
|
};
|
|
|
|
|
2017-03-06 12:23:45 +00:00
|
|
|
lacp_rate = mkOption {
|
|
|
|
default = null;
|
|
|
|
example = "fast";
|
|
|
|
type = types.nullOr types.str;
|
2022-08-14 08:03:30 +01:00
|
|
|
description = lib.mdDoc ''
|
2017-03-06 12:23:45 +00:00
|
|
|
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 21:21:03 +00:00
|
|
|
|
2017-03-06 12:23:45 +00:00
|
|
|
miimon = mkOption {
|
|
|
|
default = null;
|
|
|
|
example = 100;
|
|
|
|
type = types.nullOr types.int;
|
2022-08-14 08:03:30 +01:00
|
|
|
description = lib.mdDoc ''
|
2017-03-06 12:23:45 +00:00
|
|
|
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 11:45:24 +01:00
|
|
|
|
2017-03-06 12:23:45 +00:00
|
|
|
mode = mkOption {
|
|
|
|
default = null;
|
|
|
|
example = "active-backup";
|
|
|
|
type = types.nullOr types.str;
|
2022-08-14 08:03:30 +01:00
|
|
|
description = lib.mdDoc ''
|
2017-03-06 12:23:45 +00:00
|
|
|
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 11:45:24 +01:00
|
|
|
|
2017-03-06 12:23:45 +00:00
|
|
|
xmit_hash_policy = mkOption {
|
|
|
|
default = null;
|
|
|
|
example = "layer2+3";
|
|
|
|
type = types.nullOr types.str;
|
2022-08-14 08:03:30 +01:00
|
|
|
description = lib.mdDoc ''
|
2017-03-06 12:23:45 +00:00
|
|
|
DEPRECATED, use `driverOptions`.
|
|
|
|
Selects the transmit hash policy to use for slave selection in
|
|
|
|
balance-xor, 802.3ad, and tlb modes.
|
|
|
|
'';
|
|
|
|
};
|
2016-09-11 11:45:24 +01:00
|
|
|
|
|
|
|
};
|
2013-12-30 09:14:41 +00:00
|
|
|
|
2017-03-06 12:23:45 +00:00
|
|
|
});
|
|
|
|
};
|
2013-12-30 09:14:41 +00:00
|
|
|
|
2014-11-26 23:42:32 +00:00
|
|
|
networking.macvlans = mkOption {
|
|
|
|
default = { };
|
2021-10-03 17:06:03 +01:00
|
|
|
example = literalExpression ''
|
2020-03-28 23:50:26 +00:00
|
|
|
{
|
|
|
|
wan = {
|
|
|
|
interface = "enp2s0";
|
|
|
|
mode = "vepa";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2014-11-26 23:42:32 +00:00
|
|
|
This option allows you to define macvlan interfaces which should
|
|
|
|
be automatically created.
|
|
|
|
'';
|
2016-09-11 11:45:24 +01:00
|
|
|
type = with types; attrsOf (submodule {
|
|
|
|
options = {
|
2014-11-26 23:42:32 +00:00
|
|
|
|
2016-09-11 11:45:24 +01:00
|
|
|
interface = mkOption {
|
|
|
|
example = "enp4s0";
|
|
|
|
type = types.str;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "The interface the macvlan will transmit packets through.";
|
2016-09-11 11:45:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
mode = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
example = "vepa";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "The mode of the macvlan device.";
|
2016-09-11 11:45:24 +01:00
|
|
|
};
|
2014-11-26 23:42:32 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-09-11 11:45:24 +01:00
|
|
|
});
|
2014-11-26 23:42:32 +00:00
|
|
|
};
|
|
|
|
|
2021-08-11 10:02:47 +01:00
|
|
|
networking.fooOverUDP = mkOption {
|
|
|
|
default = { };
|
|
|
|
example =
|
|
|
|
{
|
|
|
|
primary = { port = 9001; local = { address = "192.0.2.1"; dev = "eth0"; }; };
|
|
|
|
backup = { port = 9002; };
|
|
|
|
};
|
2022-08-05 18:39:00 +01:00
|
|
|
description = lib.mdDoc ''
|
2021-08-11 10:02:47 +01:00
|
|
|
This option allows you to configure Foo Over UDP and Generic UDP Encapsulation
|
2022-08-05 18:39:00 +01:00
|
|
|
endpoints. See {manpage}`ip-fou(8)` for details.
|
2021-08-11 10:02:47 +01:00
|
|
|
'';
|
|
|
|
type = with types; attrsOf (submodule {
|
|
|
|
options = {
|
|
|
|
port = mkOption {
|
|
|
|
type = port;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2021-08-11 10:02:47 +01:00
|
|
|
Local port of the encapsulation UDP socket.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
protocol = mkOption {
|
|
|
|
type = nullOr (ints.between 1 255);
|
|
|
|
default = null;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Protocol number of the encapsulated packets. Specifying `null`
|
2021-08-11 10:02:47 +01:00
|
|
|
(the default) creates a GUE endpoint, specifying a protocol number will create
|
|
|
|
a FOU endpoint.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
local = mkOption {
|
|
|
|
type = nullOr (submodule {
|
|
|
|
options = {
|
|
|
|
address = mkOption {
|
|
|
|
type = types.str;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2021-08-11 10:02:47 +01:00
|
|
|
Local address to bind to. The address must be available when the FOU
|
|
|
|
endpoint is created, using the scripted network setup this can be achieved
|
2022-07-28 22:19:15 +01:00
|
|
|
either by setting `dev` or adding dependency information to
|
|
|
|
`systemd.services.<name>-fou-encap`; it isn't supported
|
2021-08-11 10:02:47 +01:00
|
|
|
when using networkd.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
dev = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
|
|
|
example = "eth0";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2021-08-11 10:02:47 +01:00
|
|
|
Network device to bind to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
default = null;
|
|
|
|
example = { address = "203.0.113.22"; };
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2021-08-11 10:02:47 +01:00
|
|
|
Local address (and optionally device) to bind to using the given port.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-06-26 06:13:21 +01:00
|
|
|
networking.sits = mkOption {
|
|
|
|
default = { };
|
2021-10-03 17:06:03 +01:00
|
|
|
example = literalExpression ''
|
2020-03-28 23:50:26 +00:00
|
|
|
{
|
|
|
|
hurricane = {
|
|
|
|
remote = "10.0.0.1";
|
|
|
|
local = "10.0.0.22";
|
|
|
|
ttl = 255;
|
|
|
|
};
|
|
|
|
msipv6 = {
|
|
|
|
remote = "192.168.0.1";
|
|
|
|
dev = "enp3s0";
|
|
|
|
ttl = 127;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2014-06-26 06:13:21 +01:00
|
|
|
This option allows you to define 6-to-4 interfaces which should be automatically created.
|
|
|
|
'';
|
2016-09-11 11:45:24 +01:00
|
|
|
type = with types; attrsOf (submodule {
|
|
|
|
options = {
|
|
|
|
|
|
|
|
remote = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "10.0.0.1";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2016-09-11 11:45:24 +01:00
|
|
|
The address of the remote endpoint to forward traffic over.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
local = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "10.0.0.22";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2016-09-11 11:45:24 +01:00
|
|
|
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;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2016-09-11 11:45:24 +01:00
|
|
|
The time-to-live of the connection to the remote tunnel endpoint.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
dev = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "enp4s0f0";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2016-09-11 11:45:24 +01:00
|
|
|
The underlying network device on which the tunnel resides.
|
|
|
|
'';
|
|
|
|
};
|
2014-06-26 06:13:21 +01:00
|
|
|
|
2021-08-11 11:48:43 +01:00
|
|
|
encapsulation = with types; mkOption {
|
|
|
|
type = nullOr (submodule {
|
|
|
|
options = {
|
|
|
|
type = mkOption {
|
|
|
|
type = enum [ "fou" "gue" ];
|
2022-08-05 18:39:00 +01:00
|
|
|
description = lib.mdDoc ''
|
2021-08-11 11:48:43 +01:00
|
|
|
Selects encapsulation type. See
|
2022-08-05 18:39:00 +01:00
|
|
|
{manpage}`ip-link(8)` for details.
|
2021-08-11 11:48:43 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = port;
|
|
|
|
example = 9001;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2021-08-11 11:48:43 +01:00
|
|
|
Destination port for encapsulated packets.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
sourcePort = mkOption {
|
|
|
|
type = nullOr types.port;
|
|
|
|
default = null;
|
|
|
|
example = 9002;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2021-08-11 11:48:43 +01:00
|
|
|
Source port for encapsulated packets. Will be chosen automatically by
|
|
|
|
the kernel if unset.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
default = null;
|
|
|
|
example = { type = "fou"; port = 9001; };
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2021-08-11 11:48:43 +01:00
|
|
|
Configures encapsulation in UDP packets.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-06-26 06:13:21 +01:00
|
|
|
};
|
|
|
|
|
2016-09-11 11:45:24 +01:00
|
|
|
});
|
2014-06-26 06:13:21 +01:00
|
|
|
};
|
|
|
|
|
2021-12-07 15:44:00 +00:00
|
|
|
networking.greTunnels = mkOption {
|
|
|
|
default = { };
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
greBridge = {
|
|
|
|
remote = "10.0.0.1";
|
|
|
|
local = "10.0.0.22";
|
|
|
|
dev = "enp4s0f0";
|
|
|
|
type = "tap";
|
2022-03-22 14:54:25 +00:00
|
|
|
ttl = 255;
|
2021-12-07 15:44:00 +00:00
|
|
|
};
|
2022-03-16 05:48:15 +00:00
|
|
|
gre6Tunnel = {
|
|
|
|
remote = "fd7a:5634::1";
|
|
|
|
local = "fd7a:5634::2";
|
|
|
|
dev = "enp4s0f0";
|
|
|
|
type = "tun6";
|
2022-03-22 14:54:25 +00:00
|
|
|
ttl = 255;
|
2022-03-16 05:48:15 +00:00
|
|
|
};
|
2021-12-07 15:44:00 +00:00
|
|
|
}
|
|
|
|
'';
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2021-12-07 15:44:00 +00:00
|
|
|
This option allows you to define Generic Routing Encapsulation (GRE) tunnels.
|
|
|
|
'';
|
|
|
|
type = with types; attrsOf (submodule {
|
|
|
|
options = {
|
|
|
|
|
|
|
|
remote = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "10.0.0.1";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2021-12-07 15:44:00 +00:00
|
|
|
The address of the remote endpoint to forward traffic over.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
local = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "10.0.0.22";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2021-12-07 15:44:00 +00:00
|
|
|
The address of the local endpoint which the remote
|
|
|
|
side should send packets to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
dev = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "enp4s0f0";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2021-12-07 15:44:00 +00:00
|
|
|
The underlying network device on which the tunnel resides.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-03-22 14:54:25 +00:00
|
|
|
ttl = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
example = 255;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2022-03-22 14:54:25 +00:00
|
|
|
The time-to-live/hoplimit of the connection to the remote tunnel endpoint.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-12-07 15:44:00 +00:00
|
|
|
type = mkOption {
|
2022-03-16 05:48:15 +00:00
|
|
|
type = with types; enum [ "tun" "tap" "tun6" "tap6" ];
|
2021-12-07 15:44:00 +00:00
|
|
|
default = "tap";
|
|
|
|
example = "tap";
|
2022-03-16 05:48:15 +00:00
|
|
|
apply = v: {
|
|
|
|
tun = "gre";
|
|
|
|
tap = "gretap";
|
|
|
|
tun6 = "ip6gre";
|
|
|
|
tap6 = "ip6gretap";
|
|
|
|
}.${v};
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2021-12-07 15:44:00 +00:00
|
|
|
Whether the tunnel routes layer 2 (tap) or layer 3 (tun) traffic.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-12-30 03:52:30 +00:00
|
|
|
networking.vlans = mkOption {
|
|
|
|
default = { };
|
2021-10-03 17:06:03 +01:00
|
|
|
example = literalExpression ''
|
2020-03-28 23:50:26 +00:00
|
|
|
{
|
|
|
|
vlan0 = {
|
|
|
|
id = 3;
|
|
|
|
interface = "enp3s0";
|
|
|
|
};
|
|
|
|
vlan1 = {
|
|
|
|
id = 1;
|
|
|
|
interface = "wlan0";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
2013-12-30 03:52:30 +00:00
|
|
|
description =
|
2022-07-28 22:19:15 +01:00
|
|
|
lib.mdDoc ''
|
2013-12-30 03:52:30 +00:00
|
|
|
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 11:45:24 +01:00
|
|
|
type = with types; attrsOf (submodule {
|
2013-12-30 03:52:30 +00:00
|
|
|
|
2016-09-11 11:45:24 +01:00
|
|
|
options = {
|
2013-12-30 03:52:30 +00:00
|
|
|
|
2016-09-11 11:45:24 +01:00
|
|
|
id = mkOption {
|
|
|
|
example = 1;
|
|
|
|
type = types.int;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "The vlan identifier";
|
2016-09-11 11:45:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
interface = mkOption {
|
|
|
|
example = "enp4s0";
|
|
|
|
type = types.str;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "The interface the vlan will transmit packets through.";
|
2016-09-11 11:45:24 +01:00
|
|
|
};
|
2013-12-30 03:52:30 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-09-11 11:45:24 +01:00
|
|
|
});
|
|
|
|
|
2013-12-30 03:52:30 +00:00
|
|
|
};
|
|
|
|
|
2015-09-28 17:43:40 +01:00
|
|
|
networking.wlanInterfaces = mkOption {
|
|
|
|
default = { };
|
2021-10-03 17:06:03 +01:00
|
|
|
example = literalExpression ''
|
2020-03-28 23:50:26 +00:00
|
|
|
{
|
|
|
|
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 17:43:40 +01:00
|
|
|
description =
|
2022-07-28 22:19:15 +01:00
|
|
|
lib.mdDoc ''
|
2015-09-28 17:43:40 +01:00
|
|
|
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
|
2022-07-28 22:19:15 +01:00
|
|
|
`udev` assigns to a NIC by default.
|
2015-09-28 17:43:40 +01:00
|
|
|
If a NIC supports multiple WLAN interfaces, then the one NIC can be used as
|
2022-07-28 22:19:15 +01:00
|
|
|
`device` for multiple WLAN interfaces.
|
2015-09-28 17:43:40 +01:00
|
|
|
If a NIC is used for creating WLAN interfaces, then the default WLAN interface
|
2022-07-28 22:19:15 +01:00
|
|
|
with a persistent device name form `udev` is not created.
|
|
|
|
A WLAN interface with the persistent name assigned from `udev`
|
2015-09-28 17:43:40 +01:00
|
|
|
would have to be created explicitly.
|
|
|
|
'';
|
|
|
|
|
2016-09-11 11:45:24 +01:00
|
|
|
type = with types; attrsOf (submodule {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
device = mkOption {
|
2019-08-08 21:48:27 +01:00
|
|
|
type = types.str;
|
2016-09-11 11:45:24 +01:00
|
|
|
example = "wlp6s0";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "The name of the underlying hardware WLAN device as assigned by `udev`.";
|
2016-09-11 11:45:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
type = mkOption {
|
2016-11-16 13:37:57 +00:00
|
|
|
type = types.enum [ "managed" "ibss" "monitor" "mesh" "wds" ];
|
2016-09-11 11:45:24 +01:00
|
|
|
default = "managed";
|
|
|
|
example = "ibss";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2016-11-16 13:37:57 +00:00
|
|
|
The type of the WLAN interface.
|
|
|
|
The type has to be supported by the underlying hardware of the device.
|
2016-09-11 11:45:24 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
meshID = mkOption {
|
2019-08-08 21:48:27 +01:00
|
|
|
type = types.nullOr types.str;
|
2016-09-11 11:45:24 +01:00
|
|
|
default = null;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "MeshID of interface with type `mesh`.";
|
2016-09-11 11:45:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
flags = mkOption {
|
2016-11-16 13:37:57 +00:00
|
|
|
type = with types; nullOr (enum [ "none" "fcsfail" "control" "otherbss" "cook" "active" ]);
|
2016-09-11 11:45:24 +01:00
|
|
|
default = null;
|
|
|
|
example = "control";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Flags for interface of type `monitor`.
|
2016-09-11 11:45:24 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
fourAddr = mkOption {
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
default = null;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "Whether to enable `4-address mode` with type `managed`.";
|
2016-09-11 11:45:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
mac = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "02:00:00:00:00:01";
|
2022-08-20 22:22:50 +01:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
MAC address to use for the device. If `null`, then the MAC of the
|
2016-09-11 11:45:24 +01:00
|
|
|
underlying hardware WLAN device is used.
|
|
|
|
|
|
|
|
INFO: Locally administered MAC addresses are of the form:
|
2022-08-20 22:22:50 +01:00
|
|
|
- x2:xx:xx:xx:xx:xx
|
|
|
|
- x6:xx:xx:xx:xx:xx
|
|
|
|
- xA:xx:xx:xx:xx:xx
|
|
|
|
- xE:xx:xx:xx:xx:xx
|
2016-09-11 11:45:24 +01:00
|
|
|
'';
|
|
|
|
};
|
2015-09-28 17:43:40 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-09-11 11:45:24 +01:00
|
|
|
});
|
2015-09-28 17:43:40 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-02-20 14:29:21 +00:00
|
|
|
networking.useDHCP = mkOption {
|
2013-10-28 15:14:15 +00:00
|
|
|
type = types.bool;
|
2012-02-20 14:29:21 +00:00
|
|
|
default = true;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2013-08-10 22:07:13 +01:00
|
|
|
Whether to use DHCP to obtain an IP address and other
|
2012-02-20 14:29:21 +00:00
|
|
|
configuration for all network interfaces that are not manually
|
|
|
|
configured.
|
|
|
|
'';
|
|
|
|
};
|
2013-02-11 15:01:01 +00:00
|
|
|
|
2014-11-20 10:37:48 +00:00
|
|
|
networking.useNetworkd = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2014-11-20 10:37:48 +00:00
|
|
|
Whether we should use networkd as the network configuration backend or
|
2014-11-25 19:44:14 +00:00
|
|
|
the legacy script based system. Note that this option is experimental,
|
|
|
|
enable at your own risk.
|
2014-11-20 10:37:48 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-03-30 10:49:13 +01:00
|
|
|
networking.tempAddresses = mkOption {
|
|
|
|
default = if cfg.enableIPv6 then "default" else "disabled";
|
2021-12-05 20:45:35 +00:00
|
|
|
defaultText = literalExpression ''
|
|
|
|
if ''${config.${opt.enableIPv6}} then "default" else "disabled"
|
|
|
|
'';
|
2021-03-30 10:49:13 +01:00
|
|
|
type = types.enum (lib.attrNames tempaddrValues);
|
2022-08-20 22:22:50 +01:00
|
|
|
description = lib.mdDoc ''
|
2021-03-30 10:49:13 +01:00
|
|
|
Whether to enable IPv6 Privacy Extensions for interfaces not
|
|
|
|
configured explicitly in
|
2022-08-20 22:22:50 +01:00
|
|
|
[](#opt-networking.interfaces._name_.tempAddress).
|
2021-03-30 10:49:13 +01:00
|
|
|
|
|
|
|
This sets the ipv6.conf.*.use_tempaddr sysctl for all
|
|
|
|
interfaces. Possible values are:
|
|
|
|
|
|
|
|
${tempaddrDoc}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-05-28 17:03:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-16 18:18:54 +01:00
|
|
|
###### implementation
|
2009-05-28 17:03:48 +01:00
|
|
|
|
2009-07-16 18:18:54 +01:00
|
|
|
config = {
|
2009-03-06 12:27:38 +00:00
|
|
|
|
2017-12-03 04:13:14 +00:00
|
|
|
warnings = concatMap (i: i.warnings) interfaces;
|
|
|
|
|
2014-08-31 17:46:16 +01:00
|
|
|
assertions =
|
2019-08-05 12:03:38 +01:00
|
|
|
(forEach interfaces (i: {
|
2017-10-05 14:05:30 +01: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 12:03:38 +01:00
|
|
|
})) ++ (forEach slaveIfs (i: {
|
2017-12-03 04:13:14 +00:00
|
|
|
assertion = i.ipv4.addresses == [ ] && i.ipv6.addresses == [ ];
|
2017-11-09 19:27:33 +00:00
|
|
|
message = ''
|
|
|
|
The networking.interfaces."${i.name}" must not have any defined ips when it is a slave.
|
|
|
|
'';
|
2019-08-05 12:03:38 +01:00
|
|
|
})) ++ (forEach interfaces (i: {
|
2020-01-30 10:55:50 +00:00
|
|
|
assertion = i.tempAddress != "disabled" -> cfg.enableIPv6;
|
2018-02-01 11:13:17 +00:00
|
|
|
message = ''
|
|
|
|
Temporary addresses are only needed when IPv6 is enabled.
|
|
|
|
'';
|
2020-04-13 14:20:29 +01:00
|
|
|
})) ++ (forEach interfaces (i: {
|
|
|
|
assertion = (i.virtual && i.virtualType == "tun") -> i.macAddress == null;
|
|
|
|
message = ''
|
|
|
|
Setting a MAC Address for tun device ${i.name} isn't supported.
|
|
|
|
'';
|
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 03:59:06 +01:00
|
|
|
})) ++ [
|
|
|
|
{
|
|
|
|
assertion = cfg.hostId == null || (stringLength cfg.hostId == 8 && isHexString cfg.hostId);
|
|
|
|
message = "Invalid value given to the networking.hostId option.";
|
|
|
|
}
|
|
|
|
];
|
2014-08-31 17:46:16 +01:00
|
|
|
|
2013-12-30 09:14:41 +00:00
|
|
|
boot.kernelModules = [ ]
|
|
|
|
++ optional hasVirtuals "tun"
|
2014-06-26 06:13:21 +01:00
|
|
|
++ optional hasSits "sit"
|
2021-12-07 15:44:00 +00:00
|
|
|
++ optional hasGres "gre"
|
2021-08-11 10:02:47 +01:00
|
|
|
++ optional hasBonds "bonding"
|
|
|
|
++ optional hasFous "fou";
|
2013-12-30 09:14:41 +00:00
|
|
|
|
|
|
|
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 17:21:29 +00:00
|
|
|
|
2014-11-20 10:37:48 +00:00
|
|
|
boot.kernel.sysctl = {
|
2020-05-24 20:19:50 +01:00
|
|
|
"net.ipv4.conf.all.forwarding" = mkDefault (any (i: i.proxyARP) interfaces);
|
2014-11-20 10:37:48 +00:00
|
|
|
"net.ipv6.conf.all.disable_ipv6" = mkDefault (!cfg.enableIPv6);
|
|
|
|
"net.ipv6.conf.default.disable_ipv6" = mkDefault (!cfg.enableIPv6);
|
2021-09-24 18:16:18 +01:00
|
|
|
# networkmanager falls back to "/proc/sys/net/ipv6/conf/default/use_tempaddr"
|
|
|
|
"net.ipv6.conf.default.use_tempaddr" = tempaddrValues.${cfg.tempAddresses}.sysctl;
|
2022-10-06 15:44:51 +01:00
|
|
|
} // listToAttrs (forEach interfaces
|
2022-12-12 01:36:03 +00:00
|
|
|
(i: nameValuePair "net.ipv4.conf.${replaceStrings ["."] ["/"] i.name}.proxy_arp" i.proxyARP))
|
2020-01-30 10:55:50 +00:00
|
|
|
// listToAttrs (forEach interfaces
|
|
|
|
(i: let
|
|
|
|
opt = i.tempAddress;
|
2021-03-30 10:49:13 +01:00
|
|
|
val = tempaddrValues.${opt}.sysctl;
|
2022-12-12 01:36:03 +00:00
|
|
|
in nameValuePair "net.ipv6.conf.${replaceStrings ["."] ["/"] i.name}.use_tempaddr" val));
|
2010-06-02 22:10:48 +01:00
|
|
|
|
2022-01-21 11:40:28 +00:00
|
|
|
security.wrappers = {
|
2017-01-29 11:39:18 +00:00
|
|
|
ping = {
|
2021-09-12 17:53:48 +01:00
|
|
|
owner = "root";
|
|
|
|
group = "root";
|
2017-01-29 11:39:18 +00:00
|
|
|
capabilities = "cap_net_raw+p";
|
2021-09-12 17:53:48 +01:00
|
|
|
source = "${pkgs.iputils.out}/bin/ping";
|
2017-01-29 04:48:03 +00:00
|
|
|
};
|
2017-01-29 11:33:56 +00:00
|
|
|
};
|
2020-10-18 14:36:24 +01:00
|
|
|
security.apparmor.policies."bin.ping".profile = lib.mkIf config.security.apparmor.policies."bin.ping".enable (lib.mkAfter ''
|
|
|
|
/run/wrappers/bin/ping {
|
|
|
|
include <abstractions/base>
|
|
|
|
include <nixos/security.wrappers>
|
|
|
|
rpx /run/wrappers/wrappers.*/ping,
|
|
|
|
}
|
|
|
|
/run/wrappers/wrappers.*/ping {
|
|
|
|
include <abstractions/base>
|
|
|
|
include <nixos/security.wrappers>
|
|
|
|
r /run/wrappers/wrappers.*/ping.real,
|
|
|
|
mrpx ${config.security.wrappers.ping.source},
|
|
|
|
capability net_raw,
|
|
|
|
capability setpcap,
|
|
|
|
}
|
|
|
|
'');
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2013-05-22 00:30:24 +01: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 16:34:43 +00:00
|
|
|
# since it may have been set by dhcpcd in the meantime.
|
2021-03-23 15:40:54 +00:00
|
|
|
system.activationScripts.hostname = let
|
|
|
|
effectiveHostname = config.boot.kernel.sysctl."kernel.hostname" or cfg.hostName;
|
|
|
|
in optionalString (effectiveHostname != "") ''
|
|
|
|
hostname "${effectiveHostname}"
|
2010-09-14 12:58:55 +01:00
|
|
|
'';
|
2013-05-22 00:30:24 +01:00
|
|
|
system.activationScripts.domain =
|
2014-11-20 10:37:48 +00: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 03:59:06 +01:00
|
|
|
domainname "${cfg.domain}"
|
2013-05-22 00:30:24 +01:00
|
|
|
'';
|
2009-07-16 18:18:54 +01:00
|
|
|
|
2022-04-16 21:31:58 +01:00
|
|
|
environment.etc.hostid = mkIf (cfg.hostId != null) { source = hostidFile; };
|
|
|
|
boot.initrd.systemd.contents."/etc/hostid" = mkIf (cfg.hostId != null) { source = hostidFile; };
|
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 03:59:06 +01:00
|
|
|
|
2017-01-01 15:44:32 +00:00
|
|
|
# static hostname configuration needed for hostnamectl and the
|
|
|
|
# org.freedesktop.hostname1 dbus service (both provided by systemd)
|
2019-08-13 22:52:01 +01:00
|
|
|
environment.etc.hostname = mkIf (cfg.hostName != "")
|
2017-01-01 15:44:32 +00: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 03:59:06 +01:00
|
|
|
|
2014-11-20 10:37:48 +00:00
|
|
|
environment.systemPackages =
|
|
|
|
[ pkgs.host
|
2021-04-08 12:33:09 +01:00
|
|
|
pkgs.iproute2
|
2014-11-20 10:37:48 +00:00
|
|
|
pkgs.iputils
|
|
|
|
pkgs.nettools
|
2015-07-22 11:51:21 +01:00
|
|
|
]
|
2016-02-01 16:51:10 +00:00
|
|
|
++ optionals config.networking.wireless.enable [
|
2015-07-22 11:51:21 +01:00
|
|
|
pkgs.wirelesstools # FIXME: obsolete?
|
2014-11-20 10:37:48 +00:00
|
|
|
pkgs.iw
|
2015-07-22 11:51:21 +01:00
|
|
|
]
|
|
|
|
++ bridgeStp;
|
2012-10-11 22:59:41 +01:00
|
|
|
|
2016-09-13 10:00:08 +01:00
|
|
|
# The network-interfaces target is kept for backwards compatibility.
|
|
|
|
# New modules must NOT use it.
|
2019-08-13 22:52:01 +01:00
|
|
|
systemd.targets.network-interfaces =
|
2016-09-13 10:00:08 +01:00
|
|
|
{ description = "All Network Interfaces (deprecated)";
|
2014-11-30 06:34:50 +00:00
|
|
|
wantedBy = [ "network.target" ];
|
2014-11-30 06:43:54 +00:00
|
|
|
before = [ "network.target" ];
|
2014-12-02 01:19:06 +00:00
|
|
|
after = [ "network-pre.target" ];
|
2014-11-30 06:34:50 +00:00
|
|
|
unitConfig.X-StopOnReconfiguration = true;
|
|
|
|
};
|
|
|
|
|
2014-11-24 20:06:07 +00:00
|
|
|
systemd.services = {
|
|
|
|
network-local-commands = {
|
|
|
|
description = "Extra networking commands.";
|
2014-11-26 19:19:31 +00:00
|
|
|
before = [ "network.target" ];
|
|
|
|
wantedBy = [ "network.target" ];
|
2014-12-02 01:19:06 +00:00
|
|
|
after = [ "network-pre.target" ];
|
2014-11-24 20:06:07 +00:00
|
|
|
unitConfig.ConditionCapability = "CAP_NET_ADMIN";
|
2021-03-14 16:05:16 +00:00
|
|
|
path = [ pkgs.iproute2 ];
|
2014-11-24 20:06:07 +00:00
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
serviceConfig.RemainAfterExit = true;
|
|
|
|
script = ''
|
|
|
|
# Run any user-specified commands.
|
|
|
|
${cfg.localCommands}
|
|
|
|
'';
|
|
|
|
};
|
2020-04-13 14:22:22 +01:00
|
|
|
};
|
2015-01-14 00:10:39 +00:00
|
|
|
services.mstpd = mkIf needsMstpd { enable = true; };
|
|
|
|
|
2015-09-22 14:49:17 +01:00
|
|
|
virtualisation.vswitch = mkIf (cfg.vswitches != { }) { enable = true; };
|
|
|
|
|
2019-04-11 18:41:47 +01:00
|
|
|
services.udev.packages = [
|
|
|
|
(pkgs.writeTextFile rec {
|
2019-07-09 07:06:52 +01:00
|
|
|
name = "ipv6-privacy-extensions.rules";
|
|
|
|
destination = "/etc/udev/rules.d/98-${name}";
|
2021-03-30 10:49:13 +01:00
|
|
|
text = let
|
|
|
|
sysctl-value = tempaddrValues.${cfg.tempAddresses}.sysctl;
|
|
|
|
in ''
|
2019-07-09 07:06:52 +01:00
|
|
|
# enable and prefer IPv6 privacy addresses by default
|
2022-02-04 22:39:25 +00:00
|
|
|
ACTION=="add", SUBSYSTEM=="net", RUN+="${pkgs.bash}/bin/sh -c 'echo ${sysctl-value} > /proc/sys/net/ipv6/conf/$name/use_tempaddr'"
|
2019-04-11 18:41:47 +01:00
|
|
|
'';
|
2019-07-09 07:06:52 +01:00
|
|
|
})
|
|
|
|
(pkgs.writeTextFile rec {
|
|
|
|
name = "ipv6-privacy-extensions.rules";
|
|
|
|
destination = "/etc/udev/rules.d/99-${name}";
|
2020-01-30 10:55:50 +00:00
|
|
|
text = concatMapStrings (i:
|
|
|
|
let
|
|
|
|
opt = i.tempAddress;
|
2021-03-30 10:49:13 +01:00
|
|
|
val = tempaddrValues.${opt}.sysctl;
|
|
|
|
msg = tempaddrValues.${opt}.description;
|
2020-01-30 10:55:50 +00:00
|
|
|
in
|
|
|
|
''
|
|
|
|
# override to ${msg} for ${i.name}
|
2022-12-12 01:36:03 +00:00
|
|
|
ACTION=="add", SUBSYSTEM=="net", RUN+="${pkgs.procps}/bin/sysctl net.ipv6.conf.${replaceStrings ["."] ["/"] i.name}.use_tempaddr=${val}"
|
2021-03-30 10:49:13 +01:00
|
|
|
'') (filter (i: i.tempAddress != cfg.tempAddresses) interfaces);
|
2019-07-09 07:06:52 +01:00
|
|
|
})
|
|
|
|
] ++ lib.optional (cfg.wlanInterfaces != {})
|
2015-09-28 17:43:40 +01:00
|
|
|
(pkgs.writeTextFile {
|
2015-10-06 17:45:50 +01:00
|
|
|
name = "99-zzz-40-wlanInterfaces.rules";
|
|
|
|
destination = "/etc/udev/rules.d/99-zzz-40-wlanInterfaces.rules";
|
2015-10-04 09:57:16 +01: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 19:38:53 +00:00
|
|
|
#!${pkgs.runtimeShell}
|
2015-10-04 09:57:16 +01: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"}"}
|
2021-03-14 16:05:16 +00:00
|
|
|
${optionalString (current.mac != null) "${pkgs.iproute2}/bin/ip link set dev ${device} address ${current.mac}"}
|
2015-10-04 09:57:16 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
# Udev script to execute for a new WLAN interface. The script configures the new WLAN interface.
|
2021-09-02 02:46:26 +01:00
|
|
|
newInterfaceScript = new: pkgs.writeScript "udev-run-script-wlan-interfaces-${new._iName}.sh" ''
|
2018-03-01 19:38:53 +00:00
|
|
|
#!${pkgs.runtimeShell}
|
2015-10-04 09:57:16 +01:00
|
|
|
# Configure the new interface
|
|
|
|
${pkgs.iw}/bin/iw dev ${new._iName} set type ${new.type}
|
2021-09-02 02:46:26 +01:00
|
|
|
${optionalString (new.type == "mesh" && new.meshID!=null) "${pkgs.iw}/bin/iw dev ${new._iName} set meshid ${new.meshID}"}
|
|
|
|
${optionalString (new.type == "monitor" && new.flags!=null) "${pkgs.iw}/bin/iw dev ${new._iName} set monitor ${new.flags}"}
|
|
|
|
${optionalString (new.type == "managed" && new.fourAddr!=null) "${pkgs.iw}/bin/iw dev ${new._iName} set 4addr ${if new.fourAddr then "on" else "off"}"}
|
|
|
|
${optionalString (new.mac != null) "${pkgs.iproute2}/bin/ip link set dev ${new._iName} address ${new.mac}"}
|
2015-10-04 09:57:16 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
# Udev attributes for systemd to name the device and to create a .device target.
|
2020-11-24 03:21:44 +00:00
|
|
|
systemdAttrs = n: ''NAME:="${n}", ENV{INTERFACE}="${n}", ENV{SYSTEMD_ALIAS}="/sys/subsystem/net/devices/${n}", TAG+="systemd"'';
|
2015-10-04 09:57:16 +01:00
|
|
|
in
|
|
|
|
flip (concatMapStringsSep "\n") (attrNames wlanDeviceInterfaces) (device:
|
|
|
|
let
|
2019-08-13 22:52:01 +01:00
|
|
|
interfaces = wlanListDeviceFirst device wlanDeviceInterfaces.${device};
|
2015-10-04 09:57:16 +01: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 22:52:01 +01:00
|
|
|
${flip (concatMapStringsSep "\n") (wlanListDeviceFirst device wlanDeviceInterfaces.${device}) (interface:
|
2021-09-02 02:46:26 +01:00
|
|
|
''ACTION=="add", SUBSYSTEM=="net", ENV{DEVTYPE}=="wlan", ENV{INTERFACE}=="${interface._iName}", ${systemdAttrs interface._iName}, RUN+="${newInterfaceScript interface}"'')}
|
2015-10-04 09:57:16 +01: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 18:41:47 +01:00
|
|
|
});
|
2009-07-16 18:18:54 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2006-11-20 17:06:44 +00:00
|
|
|
}
|