Run enable multiple instaces of the same systemd service

Hello I would like to enable multiple instances of the same systemd service. Like you do with:

systemctl enable queue_worker\@{1..3}.service

or as described here:

Is it possible to declare as part of the a NixOS configuration?

Thanks a lot

systemd.services."queue_worker@" = { ... };

See e.g. https://github.com/NixOS/nixpkgs/blob/1bf1f7a75fc139db5c500550efd51568a32cf9be/nixos/modules/services/networking/kresd.nix#L135

1 Like

Ah sorry, I misread, but the nixpkgs link I gave you also addresses your specific problem (by defining a target with explicit dependency on all the @ units it wants enabled).

Is it possible to declare as part of the a NixOS configuration?

Sure.

{
  systemd.services."foo@" = {
    description = "foo, instance %i";
    serviceConfig = {
      Type = "oneshot";
      ExecStart = "/my/batch/file %i";
    };
  };
}

2 Likes