about summary refs log tree commit diff
path: root/nixos/modules/misc/locate.nix
diff options
context:
space:
mode:
authorAnthony Cowley <acowley@gmail.com>2018-03-19 15:24:45 -0400
committerAnthony Cowley <acowley@gmail.com>2018-03-27 23:34:11 -0400
commit1f8382547f6d84b8eed9d81b93e8679c2ae4f4b6 (patch)
treef0f60a7712cb8aab72de34275f4fc41f2317378d /nixos/modules/misc/locate.nix
parent56fb68dcef494b7cdb3e09362d67836b8137019c (diff)
locate: fix `update-locatedb` service for `mlocate`
This fixes the `update-locatedb` service when using the `mlocate`
package.

The service as-is does not properly handle flags during update of the
relevant database when configured to use the `mlocate` package.

The man entry for `updatedb` associated with `mlocate` does not say
that it supports environment variables in place of command line flags,
whereas the `findutils` package's updatedb does so.

To support this distinction, we pass the relevant settings as flags to
the `updatedb` program when using the `mlocate` package.

Fixes #29279
Diffstat (limited to 'nixos/modules/misc/locate.nix')
-rw-r--r--nixos/modules/misc/locate.nix17
1 files changed, 15 insertions, 2 deletions
diff --git a/nixos/modules/misc/locate.nix b/nixos/modules/misc/locate.nix
index 51953d1110c43..ce5765cf1978c 100644
--- a/nixos/modules/misc/locate.nix
+++ b/nixos/modules/misc/locate.nix
@@ -97,7 +97,7 @@ in {
         Whether not to index bind mounts
       '';
     };
-    
+
   };
 
   config = mkIf cfg.enable {
@@ -133,13 +133,26 @@ in {
     systemd.services.update-locatedb =
       { description = "Update Locate Database";
         path = mkIf (!isMLocate) [ pkgs.su ];
+
+        # mlocate's updatedb takes flags via a configuration file or
+        # on the command line, but not by environment variable.
         script =
+          if isMLocate
+          then let toFlags = x: optional (cfg.${x} != [])
+                                         "--${lib.toLower x} '${concatStringsSep " " cfg.${x}}'";
+                   args = concatLists (map toFlags ["pruneFS" "pruneNames" "prunePaths"]);
+               in ''
+            exec ${cfg.locate}/bin/updatedb \
+              --output ${toString cfg.output} ${concatStringsSep " " args} \
+              --prune-bind-mounts ${if cfg.pruneBindMounts then "yes" else "no"} \
+              ${concatStringsSep " " cfg.extraFlags}
           ''
+          else ''
             exec ${cfg.locate}/bin/updatedb \
               ${optionalString (cfg.localuser != null && ! isMLocate) ''--localuser=${cfg.localuser}''} \
               --output=${toString cfg.output} ${concatStringsSep " " cfg.extraFlags}
           '';
-        environment = {
+        environment = optionalAttrs (!isMLocate) {
           PRUNEFS = concatStringsSep " " cfg.pruneFS;
           PRUNEPATHS = concatStringsSep " " cfg.prunePaths;
           PRUNENAMES = concatStringsSep " " cfg.pruneNames;