NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18k stars 14.01k forks source link

syncthing user service doesn't inherit system options #338480

Open kr-nn opened 1 month ago

kr-nn commented 1 month ago

When I configure services.syncthing it works as intended but I would like to instead of using the system service, enable user services. But if for ex. I set guiAddress = "0.0.0.0:8384" the user service is still set to 127.0.0.1:8384

Steps:

  1. add services.syncthing = { enable = true; guiAddress = "0.0.0.0:8483" };
  2. cat /etc/systemd/user/syncthing.service
  3. cat /etc/systemd/system/syncthing.service
  4. notice the difference in options

The user services should still be configurable in services.syncthing.X

@Denperidge

rnhmjoj commented 1 month ago

In short, you can't: the NixOS module only configures the system-wide service; the user service unit is provided by the upstream project and installed as-is. The latter is meant to be configured imperatively.

If you want you can run the system-wide service under your user and still configure declaratively from NixOS. home-manager has a syncthing module if you want to configure both independently.

eclairevoyant commented 1 month ago

You could probably also inherit the config as needed from config.systemd.services.syncthing.serviceConfig, I haven't tested that out though (and of course you'll have to not inherit settings unsupported by user services).

kr-nn commented 1 month ago

I mean the user service is "System-Wide" its not ~/.config/systemd. Its /etc/systemd

All users can use the /etc/systemd/user/syncthing.service

The nixos module does allow configuring these user services. Right now I'm taking advantage of systemd.user.units.syncthing.text as a workaround.

eclairevoyant commented 1 month ago

Yeah we probably will eventually want a more "portable" services framework but for now we're sticking to configuring system services primarily. Not just for syncthing, but just about any NixOS module really.

kr-nn commented 1 month ago

I think /etc/systemd/user is a system level config. Unprivileged users can't edit it, but they can take advantage of it without declaring it in home manager.

For my use case I'm trying to avoid using the home manager module, because by name home-manager manages /home which I think /etc should be a nixos responsibility.

For ex. If I'm a sysadmin for a corporation and I'm making a bunch of devs use nixos I can enforce the user service for them if needed without adding a second input.

eclairevoyant commented 1 month ago

What I'm saying is, NixOS modules generally configure systemd.services.<whatever> not systemd.user.services.<whatever>. If we want to configure both, or even allow for configuring both, IMO it should be done the same way for all the modules (that it might apply to) rather than ad-hoc kludge added to individual services.