NixOS: systemd.network.networks does not create .network files

Hi there,

I’m trying to setup a router using nixos.
I want to use systemd-networkd to configure the network interfaces.

As I move from an arch linux I’m familiar with the networkd config but how is the ‘nixos way’ to create the config files for systemd?

These are used to configure the interface on a working setup (not nixos).

First, set a name for the interface

cat /etc/systemd/network/10-wan0.link
[Match]
Path=pci-0000:02:00.0
[Link]
Name=wan0

Second, config the interface

cat /etc/systemd/network/20-wan0.network
[Match]
Name=wan0

[Network]
ConfigureWithoutCarrier=yes
Address=<ip of this interface>

[Route]
Gateway=<ip of gateway>

This is the part to configure my device in configuration.nix.
It only generates the .link file. The .network file for systemd-networkd is missing.

  systemd.network.links = {
    "10-wan0" = {
       matchConfig.Path="pci-000:02:00.0";
       linkConfig.Name="wan0";
    };
  };

  systemd.network = {
    networks.wan0 = {
       enable = true;
       name = "wan0";
       networkConfig = {
         ConfigureWithoutCarrier="yes";
       };
       address = [ "<ip of this interface>/<netmask>" ];
       gateway = [ "<IP of gateway" ];
    };
  };

What am I missing here to configure the network device properly using systemd-networkd?

I believe you need to prefix the wan0 in systemd.network.networks.wan0 with 10- like you did with systemd.network.links."10-wan".

i.e.

  systemd.network = {
    networks."10-wan0" = {
       enable = true;
       ...
    };
  };

Thanks for reaching out @kraftnix

I have tried that without success. As far as I understand it, the number prefix is required to order the files for systemd and make sure that the link is setup before the network.

Solved: Found the missing parameter…

systemd.network.enable = true;

nixos options documentation

The default is false. So systemd.network.networks are ignored.

I don’t quite understand why the links can be configured but this parameter resolved my problem.

2 Likes