Change:
if isMorPLocate then let toFlags = x: <del> optional (cfg.${x} != [ ]) "--${lib.toLower x} '${concatStringsSep " " cfg.${x}}'"; args = concatLists (map toFlags [ "pruneFS" "pruneNames" "prunePaths" ]); </del> <ins> lib.optional (cfg.${x} != [ ]) "--${lib.toLower x} '${lib.concatStringsSep " " cfg.${x}}'"; args = lib.concatLists (map toFlags [ "pruneFS" "pruneNames" "prunePaths" ]); </ins> in '' exec ${cfg.package}/bin/updatedb  <del> --output ${toString cfg.output} ${concatStringsSep " " args}  </del> <ins> --output ${toString cfg.output} ${lib.concatStringsSep " " args}  </ins> --prune-bind-mounts ${if cfg.pruneBindMounts then "yes" else "no"}  <del> ${concatStringsSep " " cfg.extraFlags} </del> <ins> ${lib.concatStringsSep " " cfg.extraFlags} </ins> '' else '' exec ${cfg.package}/bin/updatedb  <del> ${optionalString (cfg.localuser != null && !isMorPLocate) "--localuser=${cfg.localuser}"}  --output=${toString cfg.output} ${concatStringsSep " " cfg.extraFlags} </del> <ins> ${lib.optionalString (cfg.localuser != null && !isMorPLocate) "--localuser=${cfg.localuser}"}  --output=${toString cfg.output} ${lib.concatStringsSep " " cfg.extraFlags} </ins> ''; <del> environment = optionalAttrs (!isMorPLocate) { PRUNEFS = concatStringsSep " " cfg.pruneFS; PRUNEPATHS = concatStringsSep " " cfg.prunePaths; PRUNENAMES = concatStringsSep " " cfg.pruneNames; </del> <ins> environment = lib.optionalAttrs (!isMorPLocate) { PRUNEFS = lib.concatStringsSep " " cfg.pruneFS; PRUNEPATHS = lib.concatStringsSep " " cfg.prunePaths; PRUNENAMES = lib.concatStringsSep " " cfg.pruneNames; </ins> PRUNE_BIND_MOUNTS = if cfg.pruneBindMounts then "yes" else "no"; }; <del> serviceConfig.Nice = 19; serviceConfig.IOSchedulingClass = "idle"; serviceConfig.PrivateTmp = "yes"; serviceConfig.PrivateNetwork = "yes"; serviceConfig.NoNewPrivileges = "yes"; serviceConfig.ReadOnlyPaths = "/"; # Use dirOf cfg.output because mlocate creates temporary files next to # the actual database. We could specify and create them as well, # but that would make this quite brittle when they change something. # NOTE: If /var/cache does not exist, this leads to the misleading error message: # update-locatedb.service: Failed at step NAMESPACE spawning …/update-locatedb-start: No such file or directory serviceConfig.ReadWritePaths = dirOf cfg.output; </del> <ins> serviceConfig = { Nice = 19; IOSchedulingClass = "idle"; PrivateTmp = "yes"; PrivateNetwork = "yes"; NoNewPrivileges = "yes"; ReadOnlyPaths = "/"; # Use dirOf cfg.output because mlocate creates temporary files next to # the actual database. We could specify and create them as well, # but that would make this quite brittle when they change something. # NOTE: If /var/cache does not exist, this leads to the misleading error message: # update-locatedb.service: Failed at step NAMESPACE spawning …/update-locatedb-start: No such file or directory ReadWritePaths = dirOf cfg.output; }; </ins> }; <del> systemd.timers.update-locatedb = mkIf (cfg.interval != "never") { </del> <ins> systemd.timers.update-locatedb = lib.mkIf (cfg.interval != "never") { </ins> description = "Update timer for locate database"; partOf = [ "update-locatedb.service" ]; wantedBy = [ "timers.target" ];

Discussion:
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.