Jump to content

IfState: Difference between revisions

From NixOS Wiki
Felbinger (talk | contribs)
m ifstate: switch to documentation mac address (see https://ittavern.com/dummy-ip-and-mac-addresses-for-documentation-and-sanitization/), add ipv6 documentation prefix
Felbinger (talk | contribs)
m ifstate: switch to non eui64 ipv6 example address from documentation prefix to improve readability, fix identify by mac address
Line 12: Line 12:
         addresses = [
         addresses = [
           "192.0.2.10/24"
           "192.0.2.10/24"
           "2001:db8:dead:c0de:200:5eff:fe00:5300/64"
           "2001:db8:dead:c0de::10/64"
         ];
         ];
         link = {
         link = {
Line 18: Line 18:
           kind = "physical";
           kind = "physical";
         };
         };
         identify.address = "00:00:5e:00:53:00";
         identify.perm_address = "00:00:5e:00:53:00";
       };
       };
       routing.routes = [
       routing.routes = [

Revision as of 19:38, 12 August 2025

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::10/64"
        ];
        link = {
          state = "up";
          kind = "physical";
        };
        identify.perm_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";
        }
      ];
    };
  };
}