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
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
mlocate but still use
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.