diff --git a/modules/misc/locate.nix b/modules/misc/locate.nix
index e24fa2d078c..c240dfa3865 100644
--- a/modules/misc/locate.nix
+++ b/modules/misc/locate.nix
@@ -1,60 +1,62 @@
-{pkgs, config, ...}:
+{ config, pkgs, ... }:
+
+with pkgs.lib;
-###### interface
let
- inherit (pkgs.lib) mkOption;
- options = {
- services = {
- locate = {
-
- enable = mkOption {
- default = false;
- example = true;
- description = ''
- If enabled, NixOS will periodically update the database of
- files used by the locate command.
- '';
- };
-
- period = mkOption {
- default = "15 02 * * *";
- description = ''
- This option defines (in the format used by cron) when the
- locate database is updated.
- The default is to update at 02:15 (at night) every day.
- '';
- };
-
- };
-
- };
- };
-in
-
-###### implementation
-let
locatedb = "/var/cache/locatedb";
- updatedbCmd =
- "${config.services.locate.period} root " +
- "mkdir -m 0755 -p $(dirname ${locatedb}) && " +
- "nice -n 19 ${pkgs.utillinux}/bin/ionice -c 3 " +
- "updatedb --localuser=nobody --output=${locatedb} > /var/log/updatedb 2>&1";
in
{
- require = [
- # ../../upstart-jobs/cron.nix # config.services.cron
- options
- ];
- services = {
- cron = {
- systemCronJobs =
- pkgs.lib.optional
- config.services.locate.enable
- updatedbCmd;
+ ###### interface
+
+ options = {
+
+ services.locate = {
+
+ enable = mkOption {
+ default = false;
+ example = true;
+ description = ''
+ If enabled, NixOS will periodically update the database of
+ files used by the locate command.
+ '';
+ };
+
+ period = mkOption {
+ default = "15 02 * * *";
+ description = ''
+ This option defines (in the format used by cron) when the
+ locate database is updated.
+ The default is to update at 02:15 (at night) every day.
+ '';
+ };
+
};
+
};
+
+ ###### implementation
+
+ config = {
+
+ systemd.services.update-locatedb =
+ { description = "Update Locate Database";
+ path = [ pkgs.su ];
+ script =
+ ''
+ mkdir -m 0755 -p $(dirname ${locatedb})
+ exec updatedb --localuser=nobody --output=${locatedb}
+ '';
+ serviceConfig.Nice = 19;
+ serviceConfig.IOSchedulingClass = "idle";
+ };
+
+ services.cron.systemCronJobs = optional config.services.locate.enable
+ "${config.services.locate.period} root ${config.systemd.package}/bin/systemctl start update-locatedb.service";
+
+ };
+
}