A question about Home Manager's services

Home manager has service modules, and programs. In the manual one can read that:

The option names of a program module typically start with programs.<package name>.

Similarly, for a service module, the names start with services.<package name>. Note in some cases a package has both programs and service options – Emacs is such an example.

Let’s take services.nextcloud-client as an example. Initially, I thought that services.nextcloud-client.enable = true would make sure nextcloud-client package would be installed. But, I was wrong about that. You need to install the package as well: home.packages = with pkgs; [ playerctl ];. What is the reason for using services.nextcloud-client.enable? Will that command add the program to systemd? Is the reason for using this simply to have the program to start as a service?

Yep. When in doubt, don’t hesitate to read the code linked from the docs, most stuff you’d find a .enable on is quite simple: home-manager/modules/services/nextcloud-client.nix at ff1c3646541316258b1ca64e9b25d4c9cca8e587 · nix-community/home-manager · GitHub

The term “installed” is ambiguous in the nix world. Using the service option will “install” the package, as in download it to the nix store, and create a systemd unit that will auto start it when your graphical session starts (assuming your window manager/DE is configured correctly).

It will apparently not add the binary directory of the package to $PATH (which is not necessary for systemd to execute it since the absolute path is known), or its share/applications with the .desktop file to your $XDG_DATA_DIRS. Adding the package to home.packages on the other hand will do that.

I’m not sure why the service module doesn’t just do both, but on the other hand if the service is intended to be started via systemd you probably don’t want to expose a way for users to mess with that.

There’s probably an argument to be had about user expectation, and whether systemd should be used in the first place, or if this should be managed with dbus & autostarts instead. I know too little about nextcloud-client and home-manager’s design philosophies to chime in, so I’ll leave that to upstream.

1 Like

Nicely explained, @TLATER. Thanks a lot. To me, as a new NixOS user, I found this a bit confusing. It would have been nice to at least have had an option for also making service modules available to run manually. This so you do not have to double “install/download” the same packages. But, there might be a good reason for not doing that.

Don’t worry, the package resolves to the same store path in both instances, so nothing is downloaded twice :slight_smile:

Nix just stores everything in /nix/store, and then other things reference the paths there. No matter how often you reference a specific package in code, it will always only be “installed” once.

1 Like

Nice! NixOS for the win. :heart_eyes: