Skip to content

Installation

Alpine Linux

IfState is available in the community repository since Alpine Linux 3.13.

To enable eXpress Data Path (XDP) support you need to install libbpf.

You need to install py3-pygments to enable syntax highlighting in ifstate's interactive python shell.

Debian GNU/Linux

IfState is not available in the Debian repository, yet. Packages are provided for Debian trixie and bookworm in the RouterKit package registry hosted at Codeberg:

  • put the following repository key at /etc/apt/keyrings/routerkit.asc:
    -----BEGIN PGP PUBLIC KEY BLOCK-----
    
    xsBNBGmFFB8BCADuSd7ES80FKtV7vIgzqTOmAAz1ucXeNzhFTlQix0+Bt9IgYakK
    ZHx79seWc46cSd5dn+DEA0FuO4PK6YAq7HDvjARH8GcY83ieUxMO9ceVt3Gx2FDx
    46xdZphsgKU7xTO8OMGG6e2Sl4dVJ9Z+pQcw6KVjGl16076SsUF0fOCD5Bkd5VeU
    O19JFZSjzX0iaASHUQ355kCskQkhdHz+ylHAntrdM5weFwrZQ7HceHq8pTBGHyOn
    YHrVA6zXKBQLCnYlsCTV1UOnjcVsZqYeDvY0kevLvrqAAkJ3aImV1r5DTyquu4i4
    eDg2+ZyRYRUQewwZPYRImysNPxgriC5EoZt9ABEBAAHNEShEZWJpYW4gUmVnaXN0
    cnkpwsC7BBMBCABvBYJphRQfAgsHCRDmAbXVofAalTUUAAAAAAAcABBzYWx0QG5v
    dGF0aW9ucy5vcGVucGdwanMub3Jn75GgOk9atcEq5FBfcvawWQIVCAIWAAIZAQKb
    AwIeARYhBPlrHqOybuydwx6FUuYBtdWh8BqVAADxWggAno/kzmmZOqSK7S7I+gr1
    RRZTyNOfKWnY65Pd3Bvb13fxYWxRRLmB3qCR6x9JNNhrr8/ZZUd01JEwVLtVVk9j
    F8ZdmvB4oAh2N8wOs1i26oE/EODtmcvGFOo53oBBTp9UDXJS/Vg11940+Jmso/Qo
    LmAzZ8GJtcb2abZo9DGxGf7zW5SgkvE+m7q0aNc0pW2nTgSziMazHkFnHol9dIb3
    QGxZYpPSgdAQFKwLahjxQVX1OvA7Upp8tBxWwu5DtHNK1aAdHObamLHKOSFt65D9
    9rZPDNH2qX2AZFXk803lKMWQ3jhkYhBCle+xlnKbUqU2Adzs5jsUmblC0Whtuckj
    D87ATQRphRQfAQgAtHGdL242SxAwR8Q0WjMKzQn4zkiXrqL+dCLqZudTwcD1odwl
    3+0NVXieKi1+c/9Zvx0d1OuFkUf5wciEKQNl85+dQHR8FxFD+xJzfEeU3Z3Kxfps
    d8YzV2ZFWEXuJ/HIftEKIy9QzE5KV+DjsopGUG12ovYtwiZPT2lfZwJD1kW9kve8
    LBoGcKLi0pXkY6K6+txIngCj8bBhf4q1LBROyPt1aujrvOZCf8dpxYDHAn6yb781
    THh4+3ILB0EbPaxMQBZxZ+U7/0ecAf1IDqwIbtS/D68kEkYdK5DjRQhEwxYByfYS
    Ke9xUwNHXbAIAooJrsd0+3msqUyy7Ihk7ae2xQARAQABwsCsBBgBCABgBYJphRQf
    CRDmAbXVofAalTUUAAAAAAAcABBzYWx0QG5vdGF0aW9ucy5vcGVucGdwanMub3Jn
    C2I/RdH71BgbgqFwoTT/BQKbDBYhBPlrHqOybuydwx6FUuYBtdWh8BqVAAAlIQf9
    H1EuGB19W58P2+iHXIs+o15nWqKKeCGCvCHBrpbG75hnBSyJQsJFGWOgGIaD8IGb
    Kyjbtg0wNafJzl4jA68wCCMrLudVEkNnxa7sPreiDSFhwttdaMSpcvWK/tmBW5fE
    rkZyqjiyxAwnDxTJ7OkGRia84ehKJanNESTB9z8Bfl7usrbl1w35w+8vTUEMmiRR
    T+7I+nx4nI+a9Deogp/4Ap36gzFw51aWvv85SJI3z5E+kkVHCeHTLA+HO9TdVMe/
    VtP0mQfy7MnE4PFpXsTN+EDapUyq4Xh5TXSBQqJdAqI2QJRFVp8JOlXbxaV86dhv
    1GHdLVCb+57I+cVQKRfpaA==
    =nIWn
    -----END PGP PUBLIC KEY BLOCK-----
    
  • add a new repository source file /etc/apt/sources.list.d/routerkit.list with the following content:
deb [signed-by=/etc/apt/keyrings/routerkit.asc] https://codeberg.org/api/packages/routerkit/debian trixie stable
deb [signed-by=/etc/apt/keyrings/routerkit.asc] https://codeberg.org/api/packages/routerkit/debian bookworm stable
  • install ifstate via apt:
    # apt update
    # apt install ifstate
    

Configuration required

Installing ifstate will remove the ifupdown package (or one of its replacements). If no sensible ifstate configuration is provided the host will not have a working network setup when it is rebooted the next time!

NixOS

Downstream Nixpkgs

IfState is available in Nixpkgs repository since NixOS 25.11.

See NixOS Search for all available options.

Additionally this module also supports IfState to be used in the initrd to accomplish features like remote disk decryption using ssh.

Example Configuration

{
  networking.ifstate = {
    enable = true;
    settings = {
      interfaces.eth0 = {
        addresses = [ "2001:0db8::10/64" ];
        link = {
          state = "up";
          kind = "physical";
        };
        identify.perm_address = "2e:28:00:60:c2:1b";
      };
      routing.routes = [
        { to = "::/0"; via = "2001:0db8::1"; }
      ];
    };
  };
}

Example initrd Configuration

{ config, ... }:

{
  boot.initrd = {
    # systemd stage two is required for IfState in initrd
    system.enable = true;

    network = {
      enable = true;

      ifstate = {
        enable = true;
        # copy non-initrd ifstate configuration
        # NOTE: ifstate in initrd disables some features by default
        #       in order to redurce disk usage in /boot
        #       see `boot.initrd.network.ifstate.package` for details.
        settings = config.networking.ifstate.settings;
      };

      # example ssh configuration
      # See https://wiki.nixos.org/wiki/Remote_disk_unlocking for details
      # after connecting to ssh execute `systemctl default`
      ssh = {
        enable = true;
        hostKeys = [ /etc/ssh/ssh_initrd_host_ed25519_key ];
        authorizedKeys = [ "ssh-ed25519 AAAA..." ];  
      };
    };
  };
}

Using IfState as a flake

This repository can also be used as a flake input:

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
    ifstate = {
      url = "git+https://codeberg.org/routerkit/ifstate";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { nixpkgs, ifstate, ... }: {
    nixosConfigurations = {
      hostname = nixpkgs.lib.nixosSystem {
        modules = [
          ifstate.nixosModules.default
        ];
      };
    };
  };
}

The supported options are identical, but may contain new features ahead of schedule.

For a full list of available options see the options reference.

Manually

Prerequisites

IfState depends on Python3 and the following python packages:

  • pyroute2 - Python Netlink library
  • PyYAML - YAML parser and emitter for Python
  • jsonschema - An implementation of JSON Schema validation for Python (recommended)
  • Pygments - Python syntax highlighter (optional)

IfState uses python ctypes to configure XDP. You need to have libbp.so.1 available to configure XDP.

PyPI

IfState is available at Python Package Index. Use pip3 for installation:

pip3 install ifstate

This will also install all dependencies if not already satisfied. The optional dependencies can be installed via pip's extra feature:

pip3 install ifstate[shell]