diff --git a/etc/profile.sh b/etc/profile.sh index 99f7d7c1e8b..e070222e666 100644 --- a/etc/profile.sh +++ b/etc/profile.sh @@ -8,6 +8,7 @@ export FONTCONFIG_FILE=/etc/fonts/fonts.conf export LANG=@defaultLocale@ export EDITOR=nano export INFOPATH=/var/run/current-system/sw/info:/var/run/current-system/sw/share/info +export LOCATE_PATH=/var/cache/locatedb # A nice prompt. diff --git a/system/options.nix b/system/options.nix index 8f482de5ebf..4fee59cc4ea 100644 --- a/system/options.nix +++ b/system/options.nix @@ -546,6 +546,29 @@ }; + 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. + ''; + }; + + }; + + ttyBackgrounds = { enable = mkOption { diff --git a/upstart-jobs/cron.nix b/upstart-jobs/cron.nix index a7145f1d284..847ca2728dc 100644 --- a/upstart-jobs/cron.nix +++ b/upstart-jobs/cron.nix @@ -2,11 +2,24 @@ let - systemCronJobs = config.services.cron.systemCronJobs; + # !!! This should be defined somewhere else. + 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"; + + + # Put all the system cronjobs together. + systemCronJobs = + config.services.cron.systemCronJobs ++ + pkgs.lib.optional config.services.locate.enable updatedbCmd; systemCronJobsFile = pkgs.writeText "system-crontab" '' SHELL=${pkgs.bash}/bin/sh - PATH=${pkgs.coreutils}/bin + PATH=${pkgs.coreutils}/bin:${pkgs.findutils}/bin:${pkgs.gnused}/bin:${pkgs.su}/bin MAILTO= ${pkgs.lib.concatStrings (map (job: job + "\n") systemCronJobs)} '';