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" ];
};
}
2 Likes
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" ];
};
}
3 Likes
Actually, I found on a different machine the tweak didn’t always work. Had to add to add some “after”, to make sure the device was available before adjusting it.
[das@l:~/nixos/hp/hp1]$ cat systemd.services.ethtool-enp1s0f0.nix
{ pkgs, ... }:
{
systemd.services.ethtool-enp1s0f0 = {
description = "ethtool-enp1s0f0";
# Wait for the network interface to be available
after = [ "network-pre.target" "network.target" "sys-subsystem-net-devices-enp1s0f0.device" ];
wants = [ "sys-subsystem-net-devices-enp1s0f0.device" ];
serviceConfig = {
Type = "oneshot";
User = "root";
# Wait for interface to exist before running ethtool
ExecStartPre = "${pkgs.coreutils}/bin/timeout 30 ${pkgs.bash}/bin/bash -c 'until ${pkgs.iproute2}/bin/ip link show enp1s0f0 >/dev/null 2>&1; do sleep 0.5; done'";
# Intel Corporation 82571EB/82571GB Gigabit Ethernet Controller D0/D1 (copper applications) (rev 06)
ExecStart = "${pkgs.ethtool}/bin/ethtool --set-ring enp1s0f0 rx 8192 tx 8192";
# Restart if the interface comes back up
Restart = "on-failure";
RestartSec = "5s";
};
# Start when system reaches multi-user target (after network is configured)
wantedBy = [ "multi-user.target" ];
};
}