Using nixOS: In my configuration.nix, I have a custom generic service systemd.service."my-service@".
I am currently having to manage instances of that service manually (sudo systemctl start my-service@foo). How can I declare some fixed instances of that (e.g. my-service@foo, my-service@bar) in configuration.nix? I don’t want to redefine a service definition, I’d prefer to use the same machinery that systemd does for services with @.
Thank you for linking those issues! (They describe exactly this problem). Now that I know the keyword is “template”, my searches turn up more useful information, too.
Not sure if this is useful to your case, but I’ve had a situation where I needed to create a fixed number of template instances before and used a target to do so.
I’ve just revisited this problem and come up with the following workaround. You need to put a symlink to the template unit in the systemd unit directory which you can do by using systemd.packages. Then you only have to add the new symlink to a target, which is done using systemd.services."<name>".wantedBy.