Skip to content

Commit

Permalink
nixos/locatedb: fix first run when /var/cache doesn't exist
Browse files Browse the repository at this point in the history
by using systemd-tmpfiles. Also document what's happening there.
(cherry picked from commit 70c3f56)
  • Loading branch information
florianjacob authored and Mic92 committed Oct 11, 2017
1 parent 6c6b966 commit 405eb6f
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions nixos/modules/misc/locate.nix
Expand Up @@ -97,7 +97,7 @@ in {
Whether not to index bind mounts
'';
};

};

config = mkIf cfg.enable {
Expand Down Expand Up @@ -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}
Expand All @@ -147,8 +150,13 @@ in {
serviceConfig.PrivateTmp = "yes";
serviceConfig.PrivateNetwork = "yes";
serviceConfig.NoNewPrivileges = "yes";
serviceConfig.ReadOnlyDirectories = "/";
serviceConfig.ReadWriteDirectories = dirOf cfg.output;
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;
};

systemd.timers.update-locatedb =
Expand Down

0 comments on commit 405eb6f

Please sign in to comment.