NixOS ethtool --set-ring on startup

This is a post to hopefully help other searching, because I couldn’t find anything quickly when I tired.

This is also captured in the issue: ethtool can't set options for coalesce or ring sizes · Issue #255759 · NixOS/nixpkgs · GitHub

If you want to configure your NIC with ethtool on boot you can do the following. Remember to change the NIC name, and you need to make one of these per NIC.

{ pkgs, ... }:
{
    systemd.services.ethtool-enp3s0f0 = {
    description = "ethtool-enp3s0f0";
    serviceConfig = {
        Type = "oneshot";
        User = "root";
        ExecStart = "${pkgs.ethtool}/bin/ethtool --set-ring enp3s0f0 rx 4096 tx 4096";
    };
    wantedBy = [ "multi-user.target" ];
    };
}

Actually, this is a little better, because usually these ethtool commands bounce the interface, so you want to run ethtool before the NIC really comes up.

{ pkgs, ... }:
{
    systemd.services.ethtool-enp3s0f1 = {
    description = "ethtool-enp3s0f1";
    serviceConfig = {
        Type = "oneshot";
        User = "root";
        ExecStart = "${pkgs.ethtool}/bin/ethtool --set-ring enp3s0f1 rx 4096 tx 4096";
    };
    # wantedBy = [ "multi-user.target" ];
    # https://systemd.io/NETWORK_ONLINE/
    wantedBy = [ "network-pre.target" ];
    };
}