Commit Graph

262 Commits

Author SHA1 Message Date
Maximilian Bosch
84f8b1f1da nixos/networkd: this isn't experimental
I know a lot of places where this is used in production and this isn't
true anymore, especially since we're considering to drop scripted
networking.
2026-06-23 13:12:10 +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
r-vdp
f7f9148111 nixos/network-interfaces: don't write net.ipv4.conf.all.forwarding=0
This key is an alias for net.ipv4.ip_forward. The kernel default is
already 0, so emitting `=0` from sysctl.d is at best a no-op.

It is actively harmful when systemd-networkd manages forwarding via
`networkd.conf [Network] IPv4Forwarding=yes`: on a cold boot
systemd-sysctl runs before networkd and networkd's write wins, but on
a `nixos-rebuild switch` that restarts both services (any systemd
package change does, since kernel.poweroff_cmd in 60-nixos.conf
follows the systemd store path) the ordering is undefined and sysctl
can run last, silently flipping a router back to ip_forward=0.

Only emit the sysctl when at least one interface has proxyARP=true,
matching every other in-tree setter of this key (nat, docker,
tailscale, netbird, ...) which only ever write `true`. The previous
value was already mkDefault, so nothing could have been relying on it
to force forwarding off anyway.
2026-04-13 20:05:44 +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
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
Sandro
db4d8f689e nixos/network-interfaces: drop unused variable (#475662) 2026-03-11 22:09:53 +00:00
Svenum
40b42e9f70 nixos/network-interfaces: Add iplvan support 2026-02-27 09:17:46 +01:00
nixpkgs-ci[bot]
b74649e38b Merge master into staging-nixos 2026-01-23 00:20:45 +00:00
Dyego Aurélio
28096cc5e3 treewide: apply nixfmt 1.2.0 2026-01-22 18:37:56 -03:00
Michele Guerini Rocco
8d3ad239e7 nixos/networking-interfaces: stop installing wireless packages (#479623) 2026-01-18 08:41:49 +00: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
rnhmjoj
ad69c9b28c nixos/networking-interfaces: stop installing wireless packages
iw and wirelesstools (iwconfig, iwlist, etc.) are not required by
networking.wireless and rarely used manually, so they should not be
installed by default.
2026-01-13 15:03:31 +01:00
Sandro Jäckel
4692f4dfae nixos/network-interfaces: drop unused variable 2025-12-31 17:35:20 +01:00
rnhmjoj
6238a1d00d nixos/networking: fix wlanInterfaces udev rule
For some reason, starting with systemd v258, the INTERFACE property is
now protected but ID_NET_NAME can be set instead.
2025-12-02 17:54:34 +01:00
Wolfgang Walther
91a8fee3aa treewide: remove redundant parentheses
Auto-fixed by nixf-diagnose.
2025-10-05 10:52:03 +02:00
h7x4
3c10ae2f66 nixos/networking: prefer types.ints over addCheck 2025-09-12 02:37:50 +02:00
nikstur
f087e5c94b nixos/network-interfaces: add packages to corePackages
This allows users to override (i.e. exclude) these packages from their
system closure if they don't need them.
2025-08-10 22:48:26 +02:00
nikstur
d5ae87bdeb Revert "nixos: allow more things to be disabled" 2025-08-10 22:22:08 +02:00
Arian van Putten
1bb040fae8 nixos: allow more things to be disabled (#429695) 2025-08-10 19:49:52 +02:00
nikstur
bb954cddf5 nixos/network-interfaces: let networkd handle privacy extensions
This removes bash from the mandatory system closure.
2025-08-09 00:10:13 +02:00
nikstur
f5ffdbfeb0 nixos/network-interfaces: add packages to corePackages
This allows users to override (i.e. exclude) these packages from their
system closure if they don't need them.
2025-07-31 20:42:35 +02:00
Wolfgang Walther
5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
Michele Guerini Rocco
6424dede0c nixos/network-interfaces: improve IPv6 support (#417150) 2025-07-23 16:51:24 +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
Martin Weinelt
8e70f11f88 networking: clarify search and domain option descriptions
There is no canonical way to set a system domain name any longer. The one
we previously used was the NIS/YP one, but that is pointless these days.

The hostname is set up through /etc/hostname, but hostname(5) states that
it should only contain 64 7-bit ASCII characters, so it cannot be used
to cover the domain name.

We still support setting the domain name to complete the `fqdn` option
and as a central option to reference the domain name from. If anyone
wants a NIS/YP domain name set, do it yourself..

We then clarify that the domain option has nothing to do with DNS
resolution anymore and search should be configured instead.

Finally explain the purpose of the ndots option in the context of search
domains, since they decide when we stop considering the search domains
when querying names with more than one dot.
2025-07-06 00:59:37 +02:00
Martin Weinelt
8a4536fdaf networking: stop configuring NIS domain name
The `domainname` utility uses setdomainname (see getdomainname(2)) to
configure the NIS[1] (also known as YP) domain name.

It provided a central directory for various objects that are resolved via
nsswitch in the late 1990s and early 2000s.

It is however not a safe nor common deployment scenario anymore.

[1] https://en.wikipedia.org/wiki/Network_Information_Service
2025-07-06 00:59:36 +02:00
Martin Weinelt
b84f8fdaa0 networking: provide hostname-debian by default
This is first and foremost to provide compat with scripts that call the
hostname executable to retrieve the hostname, an assumptions we probably
should not be breaking.
2025-07-06 00:59:36 +02:00
Martin Weinelt
bf1b4d35fb networking: don't install nettools by default
https://lwn.net/Articles/710533/ has been true in 2017 and still holds
today.
2025-07-06 00:59:36 +02:00
Michael Hoang
6c701a9573 nixos/networking: fix fqdnOrHostName when FQDN explictly set 2025-04-23 00:45:17 +10:00
Michael Hoang
4d537721f7 nixos/networking: allow users to override FQDN
This may be useful for users where `${cfg.hostname}.${cfg.domain}` isn't
actually the fully quantified domain name of the server.
2025-04-15 18:28:40 +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
Peder Bergebakken Sundt
953f72e76e nixos/*: tag manpage references 2025-01-27 02:47:01 +01:00
misuzu
9c54c30f11 tasks/network-interfaces: Disable network-local-commands service if unnecessary (#338622) 2024-12-14 13:17:13 +02:00
Artturin
e0464e4788 treewide: replace stdenv.is with stdenv.hostPlatform.is
In preparation for the deprecation of `stdenv.isX`.

These shorthands are not conducive to cross-compilation because they
hide the platforms.

Darwin might get cross-compilation for which the continued usage of `stdenv.isDarwin` will get in the way

One example of why this is bad and especially affects compiler packages
https://www.github.com/NixOS/nixpkgs/pull/343059

There are too many files to go through manually but a treewide should
get users thinking when they see a `hostPlatform.isX` in a place where it
doesn't make sense.

```
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is"
fd --type f "\.nix" | xargs sd --fixed-strings "buildStdenv.is" "buildStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "originalStdenv.is" "originalStdenv.hostPlatform.is"
```
2024-09-25 00:04:37 +03:00
tu-maurice
a7ef1254e6 tasks/network-interfaces: Disable network-local-commands service if unnecessary
If the localCommands variable is empty this service does nothing, but
runs anyway. We can disable it in these cases.
2024-08-31 15:22:14 +02:00
stuebinm
6afb255d97 nixos: remove all uses of lib.mdDoc
these changes were generated with nixq 0.0.2, by running

  nixq ">> lib.mdDoc[remove] Argument[keep]" --batchmode nixos/**.nix
  nixq ">> mdDoc[remove] Argument[keep]" --batchmode nixos/**.nix
  nixq ">> Inherit >> mdDoc[remove]" --batchmode nixos/**.nix

two mentions of the mdDoc function remain in nixos/, both of which
are inside of comments.

Since lib.mdDoc is already defined as just id, this commit is a no-op as
far as Nix (and the built manual) is concerned.
2024-04-13 10:07:35 -07:00
Niko
9e2cd6f872 nixos/network-interfaces: remove network-interfaces.target
Co-authored-by: Martin Weinelt <mweinelt@users.noreply.github.com>
2024-01-12 17:29:03 +01:00
nikstur
c9569af3e0 Merge pull request #271326 from philiptaron/shutdown.target
treewide: depend on `shutdown.target` if `DefaultDependencies=no` in almost every case
2023-12-27 08:33:26 +01:00
rnhmjoj
cdc24ab409 nixos/networking-interfaces: fix rootless ping
In 759ec111 the ping setuid wrapper was removed in favour of giving
permissions to perform ICMP echo requests to all users.
The problem is that the systemd file that was supposed to change the
`net.ipv4.ping_group_range` sysctl is not always installed, specifically
only if systemd.coredump.enable.
In that case the range is "0 1", which is effectively restricts ping to
only root.

This change explicitely sets the range to "0 2^31-1", as systemd does.
2023-12-11 13:22:26 +01:00
Philip Taron
54064109fb nixos/network-interfaces: ensure correct ordering w.r.t. shutdown.target
Also, mark this service as `oneshot`, since it is.
2023-11-30 15:39:01 -08:00
Gaurav Juvekar
5ab4ce5d33 nixos/network-interfaces: fix typo in networking.fqdn 2023-11-12 08:47:01 -08:00
Joseph Stahl
137a3c1303 systemd domainname service - fix missing domainname binary
needs nettools in path
2023-10-28 22:30:14 -04:00
nikstur
d300940637 nixos/network-interfaces: replace hostname and domain activationScript
The hostname is already set by systemd
https://www.freedesktop.org/software/systemd/man/latest/hostname.html#Hostname%20semantics

Create a separate service that registers the domainname.
2023-10-26 01:51:08 +02:00
Martin Weinelt
d042a29613 Merge pull request #253764 from linj-fork/fix-ping-wrapper
nixos/network-interfaces: stop wrapping ping with cap_net_raw
2023-10-20 00:57:55 +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
Maximilian Bosch
6998695f5d Merge pull request #259658 from Majiir/fix-networkd-wakeonlan
nixos/network-interfaces-systemd: fix WakeOnLan
2023-10-14 14:48:22 +02:00