Commit Graph

118 Commits

Author SHA1 Message Date
Ryan Omasta
585e53ec3a nixos/network-interfaces-scripted: fix shellcheck for bridge reload 2026-06-04 05:01:17 -06:00
rnhmjoj
ff3a0a4565 nixos/networking-interfaces-scripted: add fix for systemd initrd
When systemd is used in stage 1 (boot.initrd.systemd.enable), the device
units are activated before the stage 2 units are loaded, so the
network-addresses-*.service are never started.

To avoid this, in addition to the wantedBy dependency, we use udev rules
with SYSTEMD_WANTS to trigger the services directly.
2026-05-01 22:56:35 +02:00
rnhmjoj
13f0bd5f92 Revert "Revert #481473 "nixos/network-interfaces: remove network-setup""
This reverts commit 85a509502d.
2026-05-01 22:56:25 +02:00
Will Fancher
85a509502d Revert #481473 "nixos/network-interfaces: remove network-setup"
Reverts #481473, fixes #509254

Turns out this breaks scripted networking with systemd stage 1. Even
if we assumed that systemd stage 1 wasn't now the default, I still
think that makes this worthy of a revert, in the absence of a fix. But
now that systemd stage 1 is the default, this is also a channel
blocker.

The problem is that wantedBy = [ "foo.device" ]; doesn't work as
hoped. If the device appears in stage 1, then the systemd device unit
becomes active in stage 1 without pulling in any dependency for
configuring it (because that only exists in stage 2). When we
transition to stage 2, systemd maintains its information about unit
state between stages and remembers that the device units were already
active. They do not become reactivated, and consequently their new
stage 2 dependencies do not get pulled in.

The fix is probably to do this with SYSTEMD_WANTS= in udev rules,
rather than with wantedBy. The udev rules will re-fire during stage 2,
though I'm not 100% clear on exactly which events that includes
(e.g. if we'll get new add events or if we need to look for a
different ACTION or anything like that). This is going to require some
experimentation and testing that I don't have time for today.

Given that this is addressing a channel blocker, I think this revert
should be merged if a fix can't be merged instead before the next
unstable-small eval. In either case, staging-nixos should be merged to
master right after.
2026-04-12 17:03:36 -04:00
rnhmjoj
65c1c008f2 nixos/networking-interfaces: add networking-scripted.target
This adds a target that groups together all the services of the
scripted backend. It has no role during the boot, but provides
a quick way to reset the network configuration.

For example, if addresses/routes are added/removed or an interface has
been stopped manually, running

  systemctl restart networking-scripted.target

will undo all the changes.
2026-03-14 18:11:31 +01:00
rnhmjoj
355908755a nixos/network-interfaces: remove network-setup
This change solves some big design flaws in the scripted networking
backend.

1. When the module was reworked in 072c1dcc4a to use the new systemd
  targets, network-setup.service was used to:

  a. order the services and link network.target to the boot sequence

  b. perform some perform final network configuration, specifically
     setting the default gateways and nameservers (/etc/resolv.conf).

  Later (ec00b4bb11) however, network-setup.service was made
  optional: if resolvconf is not used and a default gateway is not set,
  the service is not be defined (because it would result in an empty
  script). Doing so, however, has the unintended effect of unlinking
  network.target from multi-uset.target, meaning no network
  configuration at all is performed.

  Note: this can be easily seen by adding `networking.resolvconf.enable
  = false` to the nixosTests.networking.scripted.static test.

2. The network-addresses-*.service are linked to network.target, which,
   in turn, is linked to multi-uset.target. This means that if a
   hardware interface is not found, the boot will hang until this
   service times out (issue #154737).

To solve issue 1. this change removes network-target entirely while

  - moving the default gateway setup into the relative
    network-addresses-*.service unit;

  - moving the nameservers setup into networking.localCommands;
    (incidentally, this also fixes issue #445496)

  - directly linking network.target to multi-user.target.

To solve issue 2. this removes the Wants=network.target dependency of
network-addresses-*.service and solely relies on the underlying
interface unit (*-netdev.service for virtual, *.device for physical) to
start the service.

Note: for NixOS containers, the dependency is kept, because the .device
unit are not available in this case.

Finally, if an interface is the default gateway, network-online.target
is added as an extra dependency, so the target is not reached until the
interface has been plugged in and configured.
2026-03-14 18:11:31 +01:00
Svenum
40b42e9f70 nixos/network-interfaces: Add iplvan support 2026-02-27 09:17:46 +01:00
Lin Jian
17256403d0 nixos/network-interfaces: allow setting virtualOwner to null
null will not set owner, allowing any user to access the virtual
device.  Previously, this behavior can be achieved by using
systemd.network.netdevs.* options direcly and leaving
systemd.network.netdevs.<name>.tapConfig.User unset.  With this patch,
this behavior can be achieved using the generic
networking.interfaces.* options by setting
networking.interfaces.<name>.virtualOwner to null.

If needed, we can change the default value from "root" to null in the
future to be consistent with systemd-networkd's default behavior.
2026-01-15 20:55:30 +08:00
clerie
076f59fd54 nixos/networking: network.target depends on netdev service directly
So we don't depend on addresses configured for an interface or
network-setup.service existing anymore.

Fixes #349882
2025-08-27 18:42:09 +02:00
Wolfgang Walther
5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
rnhmjoj
602006b0b6 nixos/networking-interfaces: add rnhmjoj as maintainer 2025-07-11 09:44:49 +02:00
rnhmjoj
4e5205a68a nixos/networking-interfaces: add IPIP tunnels 2025-07-11 09:44:49 +02:00
rnhmjoj
716634530e nixos/networking-interfaces: clean up networking.sits
This change rework a bit the documentation on networking.sits to explain
what they actually are. In fact, there are three different protocols
being collectively called "SIT", which itself is a nonstandard term.
2025-07-11 09:44:48 +02:00
rnhmjoj
1a8c90128b nixos/network-interfaces: add option to set source address 2025-07-11 09:44:48 +02:00
rnhmjoj
a1a86470e3 nixos/network-interfaces-scripted: disable DAD
Duplicate address detection (DAD) causes newly added IPv6 addresses to
be effectively unusable for an unpredictable amount of time, introducing
race conditions in the network setup.
For example, a "tentative" addresses is not considered a valid source
address, so installing routes can fail unpredictably.

This change disables DAD for static IPv6 addresses, with the assumption
that the user already made sure they are unique when configuring the
network.
2025-07-11 09:44:47 +02:00
Silvan Mosberger
374e6bcc40 treewide: Format all Nix files
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](8616af08d9/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
2025-04-01 20:10:43 +02:00
Egor Savkin
201f27715e network: make network-setup service do not depend on udevd directly; fix typo with GRE tunnels
Otherwise, when doing nixos switch to major changes (typically when stdenv changes), udevd service gets loaded after addresses, which causes addresses service to wait indefinitely for the device and fail.

Signed-off-by: Egor Savkin <es@m-labs.hk>
2025-01-24 17:40:34 +08:00
Sefa Eyeoglu
f571531078 nixos/networking: fix shellcheck findings with enableStrictShellChecks enabled (#349573) 2025-01-13 09:00:59 +01:00
Tomodachi94
2e98ec0e0e nixos/networking-interfaces-scripted: use read -r
...instead of plain read, which can cause issues.

See SC2162:
https://www.shellcheck.net/wiki/SC2162
2024-12-09 08:06:29 +01:00
Egor Savkin
9354d385e2 network: Fix cycle dependency causing race of netdev and address configuration
This changes the following chain after `nixos-rebuild switch` with modified tunnel interfaces:
stop network-setup -> stop TUN-netdev -> stop network-addresses-TUN -> start network-addresses-TUN (fails since it depends on TUN-netdev which is off).

Chain after this change:
stop TUN-netdev -> stop network-setup -> stop network-addresses-TUN -> start TUN-netdev -> start network-addresses-TUN -> start network-setup

Signed-off-by: Egor Savkin <es@m-labs.hk>
2024-12-02 10:54:47 +08:00
Sefa Eyeoglu
8e6cc2f3f6 nixos/networking: fix shellcheck findings with enableStrictShellChecks enabled
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
2024-10-18 18:23:05 +02:00
Bjørn Forsman
20a3012813 nixos/networking: improve vlan service description
VLAN is an abbreviation, so let's not write Vlan.
2024-10-04 22:09:01 +02:00
Bjørn Forsman
e8da2c8981 nixos/networking: fix macvlan service description
Fix copy pasta from the vlan service: Vlan -> MACVLAN
2024-10-04 22:08:40 +02:00
Tomáš Kuča
71ce6b582b nixos/network-interfaces: prevent failure when a network address already exists
The original code tests output of `ip addr add` command to detect if an
adress already exists. The error message was changed in the past and the
test no longer works.

The patch replaces `ip addr add` with `ip addr replace`. The new command
replaces an existing address or creates a new one if there isn't any.

fixes 306841
2024-05-17 01:02:29 +02:00
sinanmohd
8314af158f nixos/network-interfaces: fix implicit dependency on underlying device
the bug causes a hard dependency on an underlying device which might not be
valid for all interfaces, also broke the example for networking.sits. this is
due to calling hasAttr first and checking for null afterwards, the bug was
made more apparent in commit 76a3c30
2024-01-02 12:03:29 +05:30
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
Majiir Paktu
f5f1751b1f refactor: combine scripted and networkd WakeOnLan config 2023-10-07 21:02:46 -04:00
ign0tus
27d0a8a0cd network.interfaces: Add option to configure WakeOnLan policy
Adds an option to configure a custom WakeOnLan policy instead of the
hard-coded "magic" policy. To ensure compatibility with current
behavior, "magic" is kept as default.
2023-09-28 20:14:02 +02:00
rnhmjoj
6732106210 network-interfaces-scripted: fix interface cleanup
There is apparently a bug in the parser of iproute2 where the command
`ip link show <devname>` will not show the device but list all
interfaces (equivalent to `ip link show`) if devname is equal to one of
the flags of `ip-address(8)`. For example, `home`, or `optimistic`.

This bug causes a false positive in the clean up command of the
<devname>-netdev.service, the service fails and the interface is never
configured.

To avoid the bug we can simply use `ip link show dev <devname>`.
2023-05-27 15:09:22 +02:00
figsoda
701bcdbead nixos: fix typos 2023-05-19 22:31:04 -04:00
Michael Livshin
cd13a2074b nixos/network-interfaces-scripted: don't bindTo absent network-setup.service 2022-06-26 11:03:57 +03:00
Sandro
8effa309cc Merge pull request #176379 from SuperSandro2000/network-setup
nixos/network-interfaces-scripted: remove network-setup unit if unused
2022-06-17 22:36:45 +02:00
Sandro Jäckel
ec00b4bb11 nixos/network-interfaces-scripted: remove network-setup unit if unused 2022-06-05 13:35:55 +02:00
Alexandru Scvortov
3a09010b9d nixos/network-interfaces: add networking.interfaces.<name>.ipv[46].routes.type 2022-06-02 19:16:25 +01:00
jpathy
19bb72c070 networking.greTunnels: Add ttl option 2022-03-23 00:24:44 +05:30
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
legendofmiracles
bb3ea37eee nixos/networking: add the wakeonlan option 2021-10-07 14:15:17 -06:00
Sandro Jäckel
9378fdf87e iproute: deprecate alias 2021-04-04 01:43:46 +02:00
volth
7503f280c8 nixos/systemd: fix TUN networking in LXC containers (#81481)
in LXC container /dev/net/tun is pre-available, "dev-net-tun.device" always fails
2020-08-05 21:12:57 -05:00
datafoo
8f16f66b27 nixos/networking: check interface state files exist before acting on them
Fix #89158
2020-05-29 12:20:06 +02:00
Florian Klink
822918df4c nixos/scripted-networking: use udev to configure link MACAddress and MTUBytes
The `network-link-${i.name}` units raced with other things trying to
configure the interface, or ran before the interface was available.

Instead of running our own set of shell scripts on boot, and hoping
they're executed at the right time, we can make use of udev to configure
the interface *while they appear*, by providing `.link` files in
/etc/systemd/network/*.link to set MACAddress and MTUBytes.

This doesn't require networkd to be enabled, and is populated properly
on non-networkd systems since
https://github.com/NixOS/nixpkgs/pull/82941.

This continues clean-up work done in
https://github.com/NixOS/nixpkgs/pull/85170 for the scripted networking
stack.

The only leftover part of the `network-link-${i.name}` unit (bringing
the interface up) is moved to the beginning of the
`network-addresses-${i.name}` unit.

Fixes: https://github.com/NixOS/nixpkgs/issues/74471
Closes: https://github.com/NixOS/nixpkgs/pull/87116
2020-05-22 10:58:00 +02:00
Florian Klink
ad26d7c044 nixos/network-interfaces-scripted: always run systemctl of the currently running systemd 2020-05-21 10:33:51 +02:00
Florian Klink
532528190b nixos/networking: move network-link-${i.name} to scripted networking
The unit sets MTU and MAC Address even with networkd enabled, which
isn't necessary anymore, as networkd handles this by itself.
2020-04-13 22:03:35 +02:00
volth
687aa06c70 nixos/scripted-networking: fix bridge setup when libvirtd uses socket activation 2020-03-15 11:29:14 +07: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
volth
35d68ef143 treewide: remove redundant quotes 2019-08-26 21:40:19 +00:00
Nikolay Amiantov
01b90dce78 resolvconf service: init
This is a refactor of how resolvconf is managed on NixOS. We split it
into a separate service which is enabled internally depending on whether
we want /etc/resolv.conf to be managed by it. Various services now take
advantage of those configuration options.

We also now use systemd instead of activation scripts to update
resolv.conf.

NetworkManager now uses the right option for rc-manager DNS
automatically, so the configuration option shouldn't be exposed.
2019-07-15 20:25:39 +03:00
volth
c730f29e7f network-scripting: do not run resolvconf if /etc/resolv.conf is managed manually (#56682)
The second invocation of resolvconf, missed in https://github.com/NixOS/nixpkgs/pull/32308
2019-03-09 13:42:14 +02:00