Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable networkd by default #202488

Closed
wants to merge 11 commits into from
13 changes: 0 additions & 13 deletions nixos/doc/manual/configuration/ad-hoc-network-config.section.md

This file was deleted.

1 change: 0 additions & 1 deletion nixos/doc/manual/configuration/networking.chapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on your NixOS machine.
<xi:include href="ipv6-config.section.xml" />
<xi:include href="firewall.section.xml" />
<xi:include href="wireless.section.xml" />
<xi:include href="ad-hoc-network-config.section.xml" />
<xi:include href="renaming-interfaces.section.xml" />
```
<!-- TODO: OpenVPN, NAT -->
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
<xi:include href="ipv6-config.section.xml" />
<xi:include href="firewall.section.xml" />
<xi:include href="wireless.section.xml" />
<xi:include href="ad-hoc-network-config.section.xml" />
<xi:include href="renaming-interfaces.section.xml" />
</chapter>
12 changes: 11 additions & 1 deletion nixos/doc/manual/from_md/release-notes/rl-2305.section.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@
<itemizedlist spacing="compact">
<listitem>
<para>
Create the first release note entry in this section!
NixOS now uses
<link linkend="opt-systemd.network.enable">systemd-networkd</link>
as its default networking backend. With networkd, many network
configurations which previously required use of
<xref linkend="opt-networking.localCommands" /> can be
expressed declaratively. Networkd’s connection management is
also significantly more reliable than the scripted networking
implementation previously in use by default. If you wish to
continue using scripted networking, set
<xref linkend="opt-networking.useNetworkd" /> to
<literal>false</literal>.
</para>
</listitem>
</itemizedlist>
Expand Down
2 changes: 1 addition & 1 deletion nixos/doc/manual/release-notes/rl-2305.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ In addition to numerous new and upgraded packages, this release has the followin

<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->

- Create the first release note entry in this section!
- NixOS now uses [systemd-networkd](#opt-systemd.network.enable) as its default networking backend. With networkd, many network configurations which previously required use of [](#opt-networking.localCommands) can be expressed declaratively. Networkd's connection management is also significantly more reliable than the scripted networking implementation previously in use by default. If you wish to continue using scripted networking, set [](#opt-networking.useNetworkd) to `false`.

## New Services {#sec-release-23.05-new-services}

Expand Down
14 changes: 1 addition & 13 deletions nixos/modules/installer/tools/nixos-generate-config.pl
Original file line number Diff line number Diff line change
Expand Up @@ -596,22 +596,10 @@ sub multiLineList {
EOF

sub generateNetworkingDhcpConfig {
# FIXME disable networking.useDHCP by default when switching to networkd.
my $config = <<EOF;
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking
# (the default) this is the recommended approach. When using systemd-networkd it's
# still possible to use this option, but it's recommended to use it in conjunction
# with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
# Enables DHCP on all ethernet and wireless LAN interfaces.
networking.useDHCP = lib.mkDefault true;
EOF

foreach my $path (glob "/sys/class/net/*") {
my $dev = basename($path);
if ($dev ne "lo") {
$config .= " # networking.interfaces.$dev.useDHCP = lib.mkDefault true;\n";
}
}

return $config;
}

Expand Down
3 changes: 2 additions & 1 deletion nixos/modules/services/system/cloud-init.nix
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ in

environment.etc."cloud/cloud.cfg".text = cfg.config;

systemd.network.enable = cfg.network.enable;
# Enable networkd if we're supposed to configure the network, but don't disable it otherwise
systemd.network.enable = mkIf cfg.network.enable true;

systemd.services.cloud-init-local =
{ description = "Initial cloud-init job (pre-networking)";
Expand Down
1 change: 1 addition & 0 deletions nixos/modules/tasks/network-interfaces-systemd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ in
enable = true;
}
(mkIf cfg.useDHCP {
wait-online.anyInterface = lib.mkDefault true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I frequently see problems with wait-online timing out already because it tracks to many interfaces. Wouldn't this make this worse?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this does the exact opposite. Its just waits for any of the interfaces to come online.

networks."99-ethernet-default-dhcp" = lib.mkIf cfg.useDHCP {
# We want to match physical ethernet interfaces as commonly
# found on laptops, desktops and servers, to provide an
Expand Down
10 changes: 6 additions & 4 deletions nixos/modules/tasks/network-interfaces.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1291,12 +1291,14 @@ in
};

networking.useNetworkd = mkOption {
default = false;
default = true;
type = types.bool;
description = lib.mdDoc ''
Whether we should use networkd as the network configuration backend or
the legacy script based system. Note that this option is experimental,
enable at your own risk.
Whether to use systemd-networkd to manage network interface
configuration. networkd provides more declarative, versatile
and reliable network configuration than the legacy scripted
networking setup, but may require config changes when
upgrading.
'';
};

Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/virtualisation/container-config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ with lib;
powerManagement.enable = mkDefault false;
documentation.nixos.enable = mkDefault false;

networking.useHostResolvConf = mkDefault true;
networking.useHostResolvConf = mkDefault (!config.systemd.network.enable);

# Containers should be light-weight, so start sshd on demand.
services.openssh.startWhenNeeded = mkDefault true;
Expand Down
4 changes: 2 additions & 2 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ in {
atd = handleTest ./atd.nix {};
atop = handleTest ./atop.nix {};
auth-mysql = handleTest ./auth-mysql.nix {};
avahi = handleTest ./avahi.nix {};
avahi-with-resolved = handleTest ./avahi.nix { networkd = true; };
avahi = handleTest ./avahi.nix { networkd = true; };
avahi-with-scripted-networking = handleTest ./avahi.nix { networkd = false; };
babeld = handleTest ./babeld.nix {};
bazarr = handleTest ./bazarr.nix {};
bcachefs = handleTestOn ["x86_64-linux" "aarch64-linux"] ./bcachefs.nix {};
Expand Down
6 changes: 1 addition & 5 deletions nixos/tests/avahi.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ import ./make-test-python.nix {
publish.workstation = true;
extraServiceFiles.ssh = "${pkgs.avahi}/etc/avahi/services/ssh.service";
};
} // pkgs.lib.optionalAttrs (networkd) {
networking = {
useNetworkd = true;
useDHCP = false;
};
networking.useNetworkd = networkd;
};
in {
one = cfg;
Expand Down
1 change: 0 additions & 1 deletion nixos/tests/bird.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ let
environment.systemPackages = with pkgs; [ jq ];

networking = {
useNetworkd = true;
useDHCP = false;
firewall.enable = false;
};
Expand Down
3 changes: 3 additions & 0 deletions nixos/tests/cjdns.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ let
{ ... }:
{ services.cjdns.enable = true;

# Occupies port 53 otherwise
services.resolved.enable = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CJDNS is actually unrelated to DNS (at least in a direct sense), this shouldn't be necesarry


# Turning off DHCP isn't very realistic but makes
# the sequence of address assignment less stochastic.
networking.useDHCP = false;
Expand Down
5 changes: 1 addition & 4 deletions nixos/tests/dnscrypt-proxy2.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ in {
refresh_delay = 72;
};
};

services.dnsmasq.enable = true;
services.dnsmasq.servers = [ "127.0.0.1#${toString localProxyPort}" ];
};
};

testScript = ''
client.wait_for_unit("dnsmasq")
client.wait_for_unit("systemd-resolved")
client.wait_for_unit("dnscrypt-proxy2")
client.wait_until_succeeds("ss --numeric --udp --listening | grep -q ${toString localProxyPort}")
'';
Expand Down
3 changes: 3 additions & 0 deletions nixos/tests/dnsdist.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import ./make-test-python.nix (
};

environment.systemPackages = with pkgs; [ dig ];

# Occupies port 53 otherwise
services.resolved.enable = false;
};

testScript = ''
Expand Down
4 changes: 0 additions & 4 deletions nixos/tests/ferm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import ./make-test-python.nix ({ pkgs, ...} : {
with pkgs.lib;
{
networking = {
dhcpcd.enable = false;
interfaces.eth1.ipv6.addresses = mkOverride 0 [ { address = "fd00::2"; prefixLength = 64; } ];
interfaces.eth1.ipv4.addresses = mkOverride 0 [ { address = "192.168.1.2"; prefixLength = 24; } ];
};
Expand All @@ -21,9 +20,6 @@ import ./make-test-python.nix ({ pkgs, ...} : {
with pkgs.lib;
{
networking = {
dhcpcd.enable = false;
useNetworkd = true;
useDHCP = false;
interfaces.eth1.ipv6.addresses = mkOverride 0 [ { address = "fd00::1"; prefixLength = 64; } ];
interfaces.eth1.ipv4.addresses = mkOverride 0 [ { address = "192.168.1.1"; prefixLength = 24; } ];
};
Expand Down
4 changes: 0 additions & 4 deletions nixos/tests/kea.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import ./make-test-python.nix ({ pkgs, lib, ...}: {
virtualisation.vlans = [ 1 ];

networking = {
useNetworkd = true;
useDHCP = false;
firewall.allowedUDPPorts = [ 67 ];
};
Expand Down Expand Up @@ -58,10 +57,7 @@ import ./make-test-python.nix ({ pkgs, lib, ...}: {
virtualisation.vlans = [ 1 ];
systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug";
networking = {
useNetworkd = true;
useDHCP = false;
firewall.enable = false;
interfaces.eth1.useDHCP = true;
};
};
};
Expand Down
4 changes: 4 additions & 0 deletions nixos/tests/knot.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ in {
{ address = "fd00::1"; prefixLength = 64; }
];
};

# Occupies port 53 otherwise
services.resolved.enable = false;

services.knot.enable = true;
services.knot.extraArgs = [ "-v" ];
services.knot.keyFiles = [ tsigFile ];
Expand Down
3 changes: 3 additions & 0 deletions nixos/tests/ncdns.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ in
identity.address = "1.0.0.1";
};

# Occupies port 53 otherwise
services.resolved.enable = false;

services.pdns-recursor.enable = true;
services.pdns-recursor.resolveNamecoin = true;

Expand Down
4 changes: 0 additions & 4 deletions nixos/tests/owncast.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ import ./make-test-python.nix ({ pkgs, ... }: {
nodes = {
client = { pkgs, ... }: with pkgs.lib; {
networking = {
dhcpcd.enable = false;
interfaces.eth1.ipv6.addresses = mkOverride 0 [ { address = "fd00::2"; prefixLength = 64; } ];
interfaces.eth1.ipv4.addresses = mkOverride 0 [ { address = "192.168.1.2"; prefixLength = 24; } ];
};
};
server = { pkgs, ... }: with pkgs.lib; {
networking = {
dhcpcd.enable = false;
useNetworkd = true;
useDHCP = false;
interfaces.eth1.ipv6.addresses = mkOverride 0 [ { address = "fd00::1"; prefixLength = 64; } ];
interfaces.eth1.ipv4.addresses = mkOverride 0 [ { address = "192.168.1.1"; prefixLength = 24; } ];

Expand Down
3 changes: 3 additions & 0 deletions nixos/tests/pdns-recursor.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import ./make-test-python.nix ({ pkgs, ... }: {
services.pdns-recursor.enable = true;
services.pdns-recursor.exportHosts= true;
networking.hosts."192.0.2.1" = [ "example.com" ];

# Occupies port 53 otherwise
services.resolved.enable = false;
};

testScript = ''
Expand Down
2 changes: 2 additions & 0 deletions nixos/tests/powerdns-admin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ let
secretKeyFile = "/etc/powerdns-admin/secret";
saltFile = "/etc/powerdns-admin/salt";
};
# Occupies port 53 otherwise
services.resolved.enable = false;
# It's insecure to have secrets in the world-readable nix store, but this is just a test
environment.etc."powerdns-admin/secret".text = "secret key";
environment.etc."powerdns-admin/salt".text = "salt";
Expand Down
3 changes: 3 additions & 0 deletions nixos/tests/powerdns.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: {
zone-cache-refresh-interval=0
'';

# Occupies port 53 otherwise
services.resolved.enable = false;

services.mysql = {
enable = true;
package = pkgs.mariadb;
Expand Down
2 changes: 0 additions & 2 deletions nixos/tests/systemd-bpf.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import ./make-test-python.nix ({ lib, ... }: {
node1 = {
virtualisation.vlans = [ 1 ];
networking = {
useNetworkd = true;
useDHCP = false;
firewall.enable = false;
interfaces.eth1.ipv4.addresses = [
Expand All @@ -19,7 +18,6 @@ import ./make-test-python.nix ({ lib, ... }: {
node2 = {
virtualisation.vlans = [ 1 ];
networking = {
useNetworkd = true;
useDHCP = false;
firewall.enable = false;
interfaces.eth1.ipv4.addresses = [
Expand Down
8 changes: 0 additions & 8 deletions nixos/tests/systemd-machinectl.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import ./make-test-python.nix ({ pkgs, ... }:
# ... and revert unwanted defaults
networking.useHostResolvConf = false;

# use networkd to obtain systemd network setup
networking.useNetworkd = true;
networking.useDHCP = false;

# systemd-nspawn expects /sbin/init
boot.loader.initScript.enable = true;

Expand All @@ -30,10 +26,6 @@ import ./make-test-python.nix ({ pkgs, ... }:
name = "systemd-machinectl";

nodes.machine = { lib, ... }: {
# use networkd to obtain systemd network setup
networking.useNetworkd = true;
networking.useDHCP = false;

# do not try to access cache.nixos.org
nix.settings.substituters = lib.mkForce [ ];

Expand Down
4 changes: 0 additions & 4 deletions nixos/tests/systemd-networkd-dhcpserver-static-leases.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import ./make-test-python.nix ({ lib, ... }: {
virtualisation.vlans = [ 1 ];
systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug";
networking = {
useNetworkd = true;
useDHCP = false;
firewall.enable = false;
};
Expand Down Expand Up @@ -42,11 +41,8 @@ import ./make-test-python.nix ({ lib, ... }: {
virtualisation.vlans = [ 1 ];
systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug";
networking = {
useNetworkd = true;
useDHCP = false;
firewall.enable = false;
interfaces.eth1 = {
useDHCP = true;
macAddress = "02:de:ad:be:ef:01";
};
};
Expand Down
4 changes: 0 additions & 4 deletions nixos/tests/systemd-networkd-dhcpserver.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import ./make-test-python.nix ({pkgs, ...}: {
virtualisation.vlans = [ 1 ];
systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug";
networking = {
useNetworkd = true;
useDHCP = false;
firewall.enable = false;
};
Expand Down Expand Up @@ -41,10 +40,7 @@ import ./make-test-python.nix ({pkgs, ...}: {
virtualisation.vlans = [ 1 ];
systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug";
networking = {
useNetworkd = true;
useDHCP = false;
firewall.enable = false;
interfaces.eth1.useDHCP = true;
};
};
};
Expand Down
5 changes: 0 additions & 5 deletions nixos/tests/systemd-networkd-ipv6-prefix-delegation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: {
};

networking = {
useNetworkd = true;
useDHCP = false;
# Consider enabling this in production and generating firewall rules
# for fowarding/input from the configured interfaces so you do not have
Expand Down Expand Up @@ -274,10 +273,6 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: {
client = {
virtualisation.vlans = [ 2 ];
systemd.services.systemd-networkd.environment.SYSTEMD_LOG_LEVEL = "debug";
networking = {
useNetworkd = true;
useDHCP = false;
};

# make the network-online target a requirement, we wait for it in our test script
systemd.targets.network-online.wantedBy = [ "multi-user.target" ];
Expand Down
Loading