Jump to content

IfState

From NixOS Wiki
Revision as of 19:36, 12 August 2025 by Felbinger (talk | contribs) (ifstate: switch to documentation mac address (see https://ittavern.com/dummy-ip-and-mac-addresses-for-documentation-and-sanitization/), add ipv6 documentation prefix)

IfState is a python 3 utility designed for declarative management of Linux network interfaces. It acts as a frontend to the kernel's Netlink interface, using the pyroute2 library to configure network settings such as IP addresses, bridges, traffic control, and WireGuard in an idempotent manner—much like an iproute2/ethtool/tc/wg wrapper.

It will be probably be available with NixOS 25.11 (see https://github.com/NixOS/nixpkgs/pull/431047).

Examples

You can find several examples on the IfState website. Due to the fact that these are yaml examples, I decided to provide some nix examples here too:

{
  networking.ifstate = {
    enable = true;
    settings = {
      interfaces.enp3s0 = {
        addresses = [
          "192.0.2.10/24"
          "2001:db8:dead:c0de:200:5eff:fe00:5300/64"
        ];
        link = {
          state = "up";
          kind = "physical";
        };
        identify.address = "00:00:5e:00:53:00";
      };
      routing.routes = [
        {
          to = "0.0.0.0/0";
          dev = "enp3s0";
          via = "192.0.2.1";
        }
        {
          to = "::/0";
          dev = "enp3s0";
          via = "fe80::1";
        }
      ];
    };
  };
}