Commit Graph

69 Commits

Author SHA1 Message Date
Rémy Grünblatt
c9e3cc43c7
nixos: fix iproute2 invocations (#263976)
When using iproute2's ip binary, you can omit the dev parameter, e.g. ip link set up eth0 instead of ip link set up dev eth0.

This breaks if for some reason your device is named e.g. he, hel, … because it is interpreted as ip link set up help.

I just encountered this bug using networking.bridges trying to create an interface named he.

I used a grep on nixpkgs to try to find iproute2 invocations using variables without the dev keyword, and found a few, and fixed them by providing the dev keyword.

I merely fixed what I found, but the use of abbreviated commands makes it a bit hard to be sure everything has been found (e.g. ip l set … up instead of ip link set … up).
2023-10-29 18:27:16 +01:00
Maximilian Bosch
083a10949a
Merge pull request #258695 from Majiir/fix-networkd-defaultgateway
nixos/network-interfaces-systemd: support and require defaultGateway.interface
2023-10-15 16:42:01 +02:00
Maximilian Bosch
632cfff257
Merge pull request #259619 from Majiir/fix-networkd-dhcp
nixos/network-interfaces-systemd: fix DHCP setting
2023-10-14 20:47:36 +02:00
Majiir Paktu
c4228b6c8f nixos/network-interfaces-systemd: fix DHCP setting
The networkd backend logic for setting DHCP= on an interface is bugged
and inconsistent with the scripted logic. Consider this simple NixOS
configuration:

    {
      networking.useNetworkd = true;
      networking.interfaces.eth0.wakeOnLan.enable = true;
    }

The default value of networking.useDHCP is true, so we expect our eth0
interface to have DHCP enabled. With the scripted backend, this works.
But the networkd backend generates the following 40-eth0.network file:

    [Match]
    Name=eth0

    [Network]
    DHCP=no
    IPv6PrivacyExtensions=kernel

This is happening because the wakeOnLan configuration creates a key in
networking.interfaces, and the networkd backend erroneously checks that
instead of for explicitly configured IP addresses as in the scripted
backend. The documentation is also inconsistent across various options.

This change aligns the networkd backend and option documentation to the
actual behavior of the scripted backend, and updates a test to account
for this behavior for both backends.
2023-10-14 13:57:32 -04:00
Majiir Paktu
c3e90f5667 nixos/network-interfaces-systemd: require defaultGateway.interface
The logic for configuring a gateway without an interface specified adds
a route with Gateway= to *every interface* configured by NixOS for
networkd. This leads to nonsensical configurations like the following:

    [Network]
    DHCP=no
    Address=192.168.0.1/24

    [Route]
    Gateway=10.0.0.1
    GatewayOnLink=false

We remove this logic and make defaultGateway.interface required to
configure a default gateway when using networkd.

We can ignore the removal of GatewayOnLink because systemd defaults it
to "no" anyway.
2023-10-07 16:09:11 -04:00
Majiir Paktu
c11b788d1a nixos/network-interfaces-systemd: support defaultGateway.interface
When interface and address are both specified, we can set Gateway= on
the named interface. The existing logic assumes interface is not set
(since it's guarded by assertion) so we now disable it when interface
has a value.

As a bonus, we now support the defaultGateway.metric option when
interface is set.
2023-10-07 16:09:11 -04:00
Linus Heckemann
2de1be5b51
Merge pull request #258677 from Majiir/fix-networkd-search-domains
nixos/network-interfaces-systemd: don't set network-level domains
2023-10-07 08:43:49 +02:00
Jade Lovelace
28ab2b278d nixos/networkd: make wait-online not time out
A further bug to our strange multi-user.target depending on
network-online.target issue is that systemd recently changed the
behaviour of systemd-networkd-wait-online to no longer consider the
absence of interfaces with RequiredForOnline to be sufficient to be
online: https://github.com/systemd/systemd/pull/27825

On the advice of the systemd developers
(https://github.com/systemd/systemd/issues/29388), this commit changes
the configuration of systemd-networkd-wait-online to pass --any by
default, and lets the default DHCP interfaces be RequiredForOnline
as they would be by default if the option is omitted.

It is plausible that systemd-networkd-wait-online may still fail if
there are no interfaces at all. However, that probably cannot be
avoided.
2023-10-02 14:47:21 -07:00
Majiir Paktu
0ba49949b0 nixos/network-interfaces-systemd: don't set network-level domains
systemd.network(5) describes Domains= as a "list of domains which should
be resolved using the DNS servers on this link." This setting is read by
systemd-resolved.service, and it's used to configure both search domains
and DNS query routing.

Adding the search domains from `networking.search` is unnecessary
because these are already configured globally in `resolved.conf` through
the default value of `services.resolved.domains`.

Adding the system's `networking.domain` to each network is unexpected
and probably incorrect. A user may not expect that the domain is in
effect automatically added to the search domains even if not specified
in `networking.search`.

Both of these network-level assignments are problematic in cases where
the NixOS networkd module is not managing every interface on the system.
In that scenario, the managed interfaces will have Domains= set while
the others do not. That will cause systemd-resolved to route DNS queries
for the search domains and the system domain to only those managed
interfaces.
2023-10-02 17:36:08 -04:00
Majiir Paktu
1f34babe84 nixos/network-interfaces-systemd: add bridge interfaces in systemd-initrd 2023-08-25 13:11:40 -04:00
Majiir Paktu
2cb4671ebc nixos/network-interfaces-systemd: add VLAN interfaces in systemd-initrd 2023-08-25 10:44:43 -04:00
figsoda
701bcdbead nixos: fix typos 2023-05-19 22:31:04 -04:00
Will Fancher
748f1329fc systemd-initrd: Automatically configure networking.interfaces 2023-04-17 16:41:35 -04:00
Pierre Bourdon
4ae5da5394
nixos/network-interfaces-systemd: do not ignore /0 gateway routes
While it might seem odd, 0.0.0.0/0 or ::/0 gateways are valid and
commonly used on point-to-point links (e.g. a wireguard tunnel) to
indicate that all traffic needs to be sent to a given interface.

systemd-networkd actually documents this as a valid configuration in its
man pages [1].

Tested to do the right thing in one of my NixOS containers using
a Wireguard tunnel as its default route.

[1] https://www.freedesktop.org/software/systemd/man/systemd.network.html#DefaultRouteOnDevice=
2022-08-19 02:25:41 +02:00
Naïm Favier
e1c1fdd8c2
nixos/networkd: add IPv6PrivacyExtensions=kernel for default networks
Maybe this could go in `genericNetwork`, but I don't know if it makes
sense for bridges, bonds etc. and I don't want to break anything.
2022-06-21 17:12:01 +02:00
Naïm Favier
f8a83b4260
nixos/networkd: make default networks RequiredForOnline when possible
When `systemd.network.wait-online.anyInterface` is enabled,
`RequiredForOnline` really means "sufficient for online", so enable it.
2022-06-21 17:12:01 +02:00
pennae
da28b26d64 nixos/networking: fix v4+v6 default gateways with networkd
fixes #178078
2022-06-18 09:33:35 +02:00
Alexandru Scvortov
3a09010b9d nixos/network-interfaces: add networking.interfaces.<name>.ipv[46].routes.type 2022-06-02 19:16:25 +01:00
Maximilian Bosch
aa849e1478
nixos/network-interfaces-systemd: actually set catchall-iface if useDHCP = true;
Previously this wasn't done in the `forEach`-expression for
`cfg.interfaces` and thus `networking.useDHCP` didn't have any effect if
no further interface was statically configured.
2022-04-30 00:30:03 +02:00
Linus Heckemann
d30dbf38b9
nixos/networkd: reimplement useDHCP in a sensible way 2022-04-30 00:30:01 +02:00
jpathy
19bb72c070 networking.greTunnels: Add ttl option 2022-03-23 00:24:44 +05:30
Luflosi
64560de406
nixos/networkd: fix networking.networkd.static test
Commit ca58bd0a50 broke the test networking.networkd.static. This happened because the test sets `networking.defaultGateway`. This is implemented by adding the gateway to the list of `routes` using `mkDefault`. The `routes` are then overridden by an empty list in the newly added code. Replace `mkDefault` with `id` so the two lists are merged and everything (hopefully) works as expected.
See https://github.com/NixOS/nixpkgs/pull/144590 for a more context.
2022-01-21 19:35:17 +01:00
Luflosi
ca58bd0a50
nixos/networkd: Add routes from interfaces to [Route] section of .network file
Closes https://github.com/NixOS/nixpkgs/pull/93635.
2022-01-20 20:14:55 +01:00
Matthew Leach
5ce7061945 nixos/networking: add options for configuring a GRE tunnel
Add `networking.greTunnels` option that allows a GRE tunnel to be
configured in NixOS.
2021-12-07 15:44:00 +00:00
pennae
c1f5155471 nixos/networking: support FOU encapsulation for sits 2021-10-16 20:48:03 -04:00
pennae
f29ea2d15d nixos/networking: add foo-over-udp endpoint support
allows configuration of foo-over-udp decapsulation endpoints. sadly networkd
seems to lack the features necessary to support local and peer address
configuration, so those are only supported when using scripted configuration.
2021-10-16 20:48:03 -04:00
Michele Guerini Rocco
a336bdd209
Merge pull request #103738 from netixx/openvswitch-improved-systemd
openvswitch: fix systemd integration assertion
2021-08-16 11:48:53 +02:00
Sandro Jäckel
9378fdf87e
iproute: deprecate alias 2021-04-04 01:43:46 +02:00
Florian Klink
24bebfa308 Revert "nixos/network-interfaces-systemd: fix IPv6 privacy extensions"
This reverts commit d349582c07.

The workaround initially applied isn't necessary anymore, as 247.3
contains the following commit:

> 242fc1d261 network: fix IPv6PrivacyExtensions=kernel handling

… which fixes https://github.com/systemd/systemd/issues/18003.
2021-02-03 22:21:19 +01:00
Florian Klink
d349582c07 nixos/network-interfaces-systemd: fix IPv6 privacy extensions
networkd seems to be buggy with IPv6PrivacyExtensions=kernel being set,
and the addresses don't appear anymore. In fact, the corresponding
sysctl seems to be set to -1 again.

Fixes https://github.com/NixOS/nixpkgs/issues/106858.
Upstream Issue: https://github.com/systemd/systemd/issues/18003
2020-12-17 07:29:25 +01:00
Netix (Espinet François)
aa3a82886b openvswitch: better integration with systemd
Systemd dependencies for scripted mode
were refactored according to analysis in #34586.

networking.vswitches can now be used with systemd-networkd,
although they are not supported by the daemon, a nixos receipe
creates the switch and attached required interfaces (just like
the scripted version).

Vlans and internal interfaces are implemented following the
  template format i.e. each interface is
described using an attributeSet (vlan and type at the moment).
If vlan is present, then interface is added to the vswitch with
given tag (access mode). Type internal enabled vswitch to create
interfaces (see openvswitch docs).

Added configuration for configuring supported openFlow version on
the vswitch

This commit is a split from the original PR #35127.
2020-11-13 21:08:56 +01:00
Florian Klink
cddc7a28b8 nixos/networking: fix setting .macAddress and .mtu with networkd
This needs to be set in the .linkConfig of a .network
2020-04-13 22:03:35 +02:00
Jörg Thalheim
1ddb140d95
Merge pull request #53033 from netixx/openvswitch-improved-systemd
openvswitch: better integration with systemd
2020-02-21 08:24:49 +00:00
Netix (Espinet François)
cd3597b486
openvswitch: better integration with systemd
Systemd dependencies for scripted mode
were refactored according to analysis in #34586.

networking.vswitches can now be used with systemd-networkd,
although they are not supported by the daemon, a nixos receipe
creates the switch and attached required interfaces (just like
the scripted version).

Vlans and internal interfaces are implemented following the
  template format i.e. each interface is
described using an attributeSet (vlan and type at the moment).
If vlan is present, then interface is added to the vswitch with
given tag (access mode). Type internal enabled vswitch to create
interfaces (see openvswitch docs).

Added configuration for configuring supported openFlow version on
the vswitch

This commit is a split from the original PR #35127.
2019-12-15 21:16:26 +01:00
Maximilian Bosch
ff65638bfc
nixos/networkd: only set gateway if it's explicitly specified in the module system 2019-12-08 03:30:04 +01:00
Elias Probst
8d8c3cadd6 Fix typo in message (vswichtesvswitches) 2019-10-26 13:26:01 +02:00
Florian Klink
c3098d182d nixos/network: remove 99-main.network
Just maching all network interfaces caused many breakages, see #18962
and #71106.

We already don't support the global networking.useDHCP,
networking.defaultGateway(6) options if networking.useNetworkd is
enabled, but direct users to configure the per-device
networking.interfaces.<name?>.… options.
2019-10-23 11:39:27 +02:00
Robin Gloster
68b42a84fd
Merge branch 'master' into networkd-disallow-dhcp 2019-09-25 11:28:20 +02:00
Roman Volosatovs
a0a3675bdf
nixos/network: replace deprecated DHCP=both by DHCP=yes 2019-09-24 11:33:36 +02:00
Robin Gloster
c26c6241ea
networking.useDHCP: disallow for networkd
This setting will be removed with the switch to systemd-networkd. The
use of per interface config is encouraged instead.
2019-09-24 10:20:16 +02:00
Andreas Rammhold
2b605e96c2
nixos/networkd: continue supporting 99-main with wildcard interface match
With systemd version 243 network units with empty match block will
generate warnigs. The reasoning seems to be that the intended behaviour
is hard to infere. Being explicit about really meaning any interface is
the reasonable thing here.

We want to get rid of this mechanism in the long run but as long as we
do not have a replacement we should stick with it and keep it in
reasonable good shape.
2019-09-08 17:14:13 +02:00
Frederik Rietdijk
5061fe0c2c Merge staging-next into staging 2019-08-28 08:26:42 +02:00
volth
35d68ef143 treewide: remove redundant quotes 2019-08-26 21:40:19 +00:00
danbst
0f8596ab3f mass replace "flip map -> forEach"
See `forEach`-introduction commit.
```
rg 'flip map ' --files-with-matches | xargs sed -i 's/flip map /forEach /g'
```
2019-08-05 14:03:38 +03:00
danbst
91bb646e98 Revert "mass replace "flip map -> foreach""
This reverts commit 3b0534310c.
2019-08-05 14:01:45 +03:00
danbst
3b0534310c mass replace "flip map -> foreach"
See `foreach`-introduction commit.
```
rg 'flip map ' --files-with-matches | xargs sed -i 's/flip map /foreach /g'
```
2019-07-14 13:46:10 +03:00
Andreas Rammhold
1b7b1dbe2f
nixos/networkd: rename GatewayOnlink to GatewayOnLink
This follows upstreams renaming of the option [1].

[1] 9cb8c55934
2019-06-03 15:05:17 +02:00
Andreas Rammhold
d600da7045
nixos/networkd: use the route section for default routes
With systemd v242 using the `Gateway` attribute of the `[Network]`
section will lead to "onlink" routes on all the device that are matched
by the default configuration (typically all devices) causing multiple
default routes (even on localhost).

We can only avoid that - while keeping our default route option - when
we mark the route as explicitly not on link. Only gateways that are
within a subnet of one of the assigned interface addresses will be
installed into the routing table.
2019-06-03 15:05:16 +02:00
Andreas Rammhold
a32cd7d84a
nixos/networkd: use no instead of none for DHCP= option
systemd has deprecated the use of `none` and recommends using `no`
instead.
2019-06-03 15:05:15 +02:00
volth
2e979e8ceb [bot] nixos/*: remove unused arguments in lambdas 2018-07-20 20:56:59 +00:00