Code change:
Using more-or-less the default configuration for (with ), the list of results is printed twice whenever running . For example: Steps to reproduce the behavior: the module like so: the job with some file name that exists on the system Matching files should each be printed once. The issue is fixed if I unset the environment variable. plocate deliberately reads from both and the hard coded default path, even if they are the same: The comment claims that this is also the behavior of mlocate, but I do not have an mlocate database installed and haven't wanted to change my running system to use mlocate. It looks like recently started being set in NixOS in . Please run and paste the result.
Sounds to me like an upstream issue. Can you write a mail to the upstream maintainer? ;a=blob;f=README;h=;hb=HEAD#l40
Sure, I have done so. I'll follow up when I get a response.
The plocate maintainer says they do not consider this to be a bug in plocate, and is intentional behavior. Rather than setting the environment variable, could we just make a wrapper script for that uses the NixOS-configured dbpath, if we don't want to re-build itself when the path is changed?
I would be personally fine to just drop support for a custom place for the db. If people really want to have it somewhere else they could symlink it. Then we don't need a wrapper or to worry about the env.
I can confirm the behaviour with .
Could we just take out the variable setting? It isn't needed for or , and just causes this annoying behaviour. If it's needed for , maybe the setting could be made conditional. It would be nice to get something done about it sooner rather than later. This issue has been open for 4 months now.
Please take a look at
I've reviewed the PR and it LGTM. Thanks for doing this! It will be great to have this fixed.

Related discussion:
text: setgid = true; setuid = false; }; <del> mlocate = mkIf isMLocate { </del> <ins> mlocate = lib.mkIf isMLocate { </ins> group = "mlocate"; source = "${cfg.package}/bin/locate"; }; <del> plocate = mkIf isPLocate { </del> <ins> plocate = lib.mkIf isPLocate { </ins> group = "plocate"; source = "${cfg.package}/bin/plocate"; }; in <del> mkIf isMorPLocate { locate = mkMerge [ common mlocate plocate ]; plocate = mkIf isPLocate (mkMerge [ common plocate ]); </del> <ins> lib.mkIf isMorPLocate { locate = lib.mkMerge [ common mlocate plocate ]; plocate = lib.mkIf isPLocate (lib.mkMerge [ common plocate ]); </ins> }; <del> environment.systemPackages = [ cfg.package ]; </del> <ins> environment = { # write /etc/updatedb.conf for manual calls to `updatedb` etc."updatedb.conf".text = '' PRUNEFS="${lib.concatStringsSep " " cfg.pruneFS}" PRUNENAMES="${lib.concatStringsSep " " cfg.pruneNames}" PRUNEPATHS="${lib.concatStringsSep " " cfg.prunePaths}" PRUNE_BIND_MOUNTS="${if cfg.pruneBindMounts then "yes" else "no"}" ''; </ins> <del> environment.variables.LOCATE_PATH = cfg.output; </del> <ins> systemPackages = [ cfg.package ]; </ins> <del> environment.etc = { # write /etc/updatedb.conf for manual calls to `updatedb` "updatedb.conf" = { text = '' PRUNEFS="${lib.concatStringsSep " " cfg.pruneFS}" PRUNENAMES="${lib.concatStringsSep " " cfg.pruneNames}" PRUNEPATHS="${lib.concatStringsSep " " cfg.prunePaths}" PRUNE_BIND_MOUNTS="${if cfg.pruneBindMounts then "yes" else "no"}" ''; </del> <ins> variables = lib.mkIf isFindutils { LOCATE_PATH = cfg.output; </ins> }; }; <del> warnings = optional (isMorPLocate && cfg.localuser != null) </del> <ins> warnings = lib.optional (isMorPLocate && cfg.localuser != null) </ins> "mlocate and plocate do not support the services.locate.localuser option. updatedb will run as root. Silence this warning by setting services.locate.localuser = null." <del> ++ optional (isFindutils && cfg.pruneNames != [ ]) </del> <ins> ++ lib.optional (isFindutils && cfg.pruneNames != [ ]) </ins> "findutils locate does not support pruning by directory component" <del> ++ optional (isFindutils && cfg.pruneBindMounts) </del> <ins> ++ lib.optional (isFindutils && cfg.pruneBindMounts) </ins> "findutils locate does not support skipping bind mounts"; systemd.services.update-locatedb = { description = "Update Locate Database"; <del> path = mkIf (!isMorPLocate) [ pkgs.su ]; </del> <ins> path = lib.mkIf (!isMorPLocate) [ pkgs.su ]; </ins> # mlocate's updatedb takes flags via a configuration file or # on the command line, but not by environment variable.