How to override nixpkg services ExecStart

There are no extra settings to change the intervals using.

services.vnstat.enable = true;

So I copied the source from nixos/modules/services/monitoring/vnstat.nix inside my nixos config.

Instead is there a way to only override the

        ExecStart = "${pkgs.vnstat}/bin/vnstatd -n";

TO

        ExecStart = "${pkgs.vnstat}/bin/vnstatd -n --config ${pkgs.writeText "vnstat.conf" ''
          DatabaseDir ${cfg.databaseDir}
          UpdateInterval ${toString cfg.updateInterval}
          PollInterval ${toString cfg.pollInterval}
          SaveInterval ${toString cfg.saveInterval}
          OfflineSaveInterval ${toString cfg.offlineSaveInterval}
        ''}";

while still using services.vnstat.enable = true; ?

systemd.services.vnstat.serviceConfig.ExecStart

Well, you already have the solution in your question :slight_smile:

{ config, lib, pkgs, ... }:
{
  services.vnstat.enable = true;
  systemd.services.vnstat.serviceConfig.ExecStart = let
    cfg = config.services.vnstat;
  in lib.mkForce "${pkgs.vnstat}/bin/vnstatd -n --config ${pkgs.writeText "vnstat.conf" ''
    DatabaseDir ${cfg.databaseDir}
    UpdateInterval ${toString cfg.updateInterval}
    PollInterval ${toString cfg.pollInterval}
    SaveInterval ${toString cfg.saveInterval}
    OfflineSaveInterval ${toString cfg.offlineSaveInterval}
  ''}";
}
2 Likes

ty
I didn’t need the let, I have one at the top.
I was missing the mkForce :blush: