I must be doing something wrong

I went to install mlocate and found it wasn’t working because the mlocate group didn’t exist. I found a forum post that explains that the locate service will set up this group. My first issue here is that I had to find out about the locate service from a forum post. If you search mlocate on search.nixos.org you will get nothing back. There has to be something I’m missing here right?

My second issue comes from actually installing the service. The search results don’t mention a REQUIRED setting for the locate service. You have to set services.locate.locate to a locate packge. Either mlocate or plocate. How am I expected to find this information without this forum post?

Lastly, the locate service “helpfully” installs mlocate for you when you specify it in services.locate.locate. This means that there’s no point in having mlocate in my array of system packages. When I go back in the future to see if mlocate is installed it won’t be where I expect it to be. This makes my config feel unorganized. Is there some other way of doing this? Feels like I’m going against the grain here.

No, unfortunately. This is confusing, and has been discussed in the past: Installation suggestion of service packages is completely wrong · Issue #506 · NixOS/nixos-search · GitHub

It applies to a bunch of other packages too, the one most commonly misused is probably steam, likely because less advanced users try that package out a lot.

For the moment, until we eventually find a satisfying solution to this, just learn to search under NixOS Search first and under packages second.

While it’s confusing for new users, at least after you run into it once you will never have this issue again.

services.locate is particularly unfortunate, because none of the option help entries happen to continue the mlocate string, so searching for mlocate under options doesn’t help you - I’d suggest we change that, either by making search.nixos.org also search the examples, or by simply adding mlocate to the description of services.locate.locate.

Not really, but there are plenty of packages that are “helpfully” installed via options rather than your big list of packages (and you should double check if any of them are already duplicated).

So firstly, let me address why this happens. If things like this happen, the NixOS module in question needs to know what package it’s supposed to use. In this case, mlocate needs to get a security wrapper to grant it setuid permissions: https://github.com/NixOS/nixpkgs/blob/0c5678df521e1407884205fe3ce3cf1d7df297db/nixos/modules/misc/locate.nix#L221

If you install mlocate by adding it to environment.systemPackages, not only will it be lacking the locate service, but it also won’t have setuid permissions, so it won’t work if you don’t set services.locate.locate to mlocate but still use mlocate.

I’d recommend splitting up the system configuration into multiple files that do logically coherent things, rather than having a single big environment.systemPackages, personally. You can have multiple environment.systemPackages split across multiple files - they’ll be merged into one list during evaluation, this gives you a nice way to do configuration that belongs together conceptually in the same place, rather than throwing everything in one big, albeit perhaps internally organized file.

If you’re really concerned about looking at your environment.systemPackages to check if a package is installed, you can still leave a comment about mlocate right there, though I appreciate the added maintenance burden caused by comments like that. That said, I’ve personally never felt the need to do that over several years of using NixOS in multiple contexts - in the worst case, grep is your friend.