summary refs log tree commit diff
path: root/nixos/modules/misc/locate.nix
diff options
context:
space:
mode:
authorFlorian Jacob <projects+git@florianjacob.de>2017-10-11 11:18:28 +0200
committerFlorian Jacob <projects+git@florianjacob.de>2017-10-11 14:59:18 +0200
commit70c3f56bdd37b58f6dfd1a61403835233339819b (patch)
tree27e097ec406a366f2b23bcdbae654f5c5e96d9ab /nixos/modules/misc/locate.nix
parent818b161e0acea3a578d2eb06ae1a13d5aaad9c42 (diff)
downloadnixpkgs-70c3f56bdd37b58f6dfd1a61403835233339819b.tar
nixpkgs-70c3f56bdd37b58f6dfd1a61403835233339819b.tar.gz
nixpkgs-70c3f56bdd37b58f6dfd1a61403835233339819b.tar.bz2
nixpkgs-70c3f56bdd37b58f6dfd1a61403835233339819b.tar.lz
nixpkgs-70c3f56bdd37b58f6dfd1a61403835233339819b.tar.xz
nixpkgs-70c3f56bdd37b58f6dfd1a61403835233339819b.tar.zst
nixpkgs-70c3f56bdd37b58f6dfd1a61403835233339819b.zip
nixos/locatedb: fix first run when /var/cache doesn't exist
by using systemd-tmpfiles.
Also document what's happening there.
Diffstat (limited to 'nixos/modules/misc/locate.nix')
-rw-r--r--nixos/modules/misc/locate.nix12
1 files changed, 10 insertions, 2 deletions
diff --git a/nixos/modules/misc/locate.nix b/nixos/modules/misc/locate.nix
index 9b8a54719e4..51953d1110c 100644
--- a/nixos/modules/misc/locate.nix
+++ b/nixos/modules/misc/locate.nix
@@ -125,13 +125,16 @@ in {
     warnings = optional (isMLocate && cfg.localuser != null) "mlocate does not support searching as user other than root"
             ++ optional (isFindutils && cfg.pruneNames != []) "findutils locate does not support pruning by directory component"
             ++ optional (isFindutils && cfg.pruneBindMounts) "findutils locate does not support skipping bind mounts";
-  
+
+    # directory creation needs to be separated from main service
+    # because ReadWritePaths fails when the directory doesn't already exist
+    systemd.tmpfiles.rules = [ "d ${dirOf cfg.output} 0755 root root -" ];
+
     systemd.services.update-locatedb =
       { description = "Update Locate Database";
         path = mkIf (!isMLocate) [ pkgs.su ];
         script =
           ''
-            mkdir -m 0755 -p ${dirOf cfg.output}
             exec ${cfg.locate}/bin/updatedb \
               ${optionalString (cfg.localuser != null && ! isMLocate) ''--localuser=${cfg.localuser}''} \
               --output=${toString cfg.output} ${concatStringsSep " " cfg.extraFlags}
@@ -148,6 +151,11 @@ in {
         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;
       };