Update the locate database using a systemd service
This makes it easier to update the database manually ("systemctl start update-locatedb"). Also, use modern module syntax.
This commit is contained in:
parent
fc2fc63f4c
commit
ce866184c6
@ -1,12 +1,20 @@
|
|||||||
{pkgs, config, ...}:
|
{ config, pkgs, ... }:
|
||||||
|
|
||||||
|
with pkgs.lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
|
||||||
|
locatedb = "/var/cache/locatedb";
|
||||||
|
|
||||||
|
in
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
###### interface
|
###### interface
|
||||||
let
|
|
||||||
inherit (pkgs.lib) mkOption;
|
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
services = {
|
|
||||||
locate = {
|
services.locate = {
|
||||||
|
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
default = false;
|
default = false;
|
||||||
@ -29,32 +37,26 @@ let
|
|||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
|
||||||
in
|
|
||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
let
|
|
||||||
locatedb = "/var/cache/locatedb";
|
|
||||||
|
|
||||||
updatedbCmd =
|
config = {
|
||||||
"${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
|
|
||||||
|
|
||||||
{
|
systemd.services.update-locatedb =
|
||||||
require = [
|
{ description = "Update Locate Database";
|
||||||
# ../../upstart-jobs/cron.nix # config.services.cron
|
path = [ pkgs.su ];
|
||||||
options
|
script =
|
||||||
];
|
''
|
||||||
|
mkdir -m 0755 -p $(dirname ${locatedb})
|
||||||
services = {
|
exec updatedb --localuser=nobody --output=${locatedb}
|
||||||
cron = {
|
'';
|
||||||
systemCronJobs =
|
serviceConfig.Nice = 19;
|
||||||
pkgs.lib.optional
|
serviceConfig.IOSchedulingClass = "idle";
|
||||||
config.services.locate.enable
|
|
||||||
updatedbCmd;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
services.cron.systemCronJobs = optional config.services.locate.enable
|
||||||
|
"${config.services.locate.period} root ${config.systemd.package}/bin/systemctl start update-locatedb.service";
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user