2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-08-14 01:58:55 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2008-11-09 16:44:53 +00:00
|
|
|
|
|
|
|
let
|
2014-06-16 07:03:29 +01:00
|
|
|
cfg = config.services.locate;
|
|
|
|
in {
|
2013-08-14 01:58:55 +01:00
|
|
|
|
|
|
|
###### interface
|
2008-11-09 16:44:53 +00:00
|
|
|
|
|
|
|
options = {
|
|
|
|
|
2013-08-14 01:58:55 +01:00
|
|
|
services.locate = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.bool;
|
2013-08-14 01:58:55 +01:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
If enabled, NixOS will periodically update the database of
|
|
|
|
files used by the <command>locate</command> command.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
period = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.str;
|
2013-08-14 01:58:55 +01:00
|
|
|
default = "15 02 * * *";
|
|
|
|
description = ''
|
|
|
|
This option defines (in the format used by cron) when the
|
|
|
|
locate database is updated.
|
2013-10-30 16:37:45 +00:00
|
|
|
The default is to update at 02:15 at night every day.
|
2013-08-14 01:58:55 +01:00
|
|
|
'';
|
2008-11-09 16:44:53 +00:00
|
|
|
};
|
|
|
|
|
2014-06-16 07:03:29 +01:00
|
|
|
extraFlags = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
2015-08-03 12:48:43 +01:00
|
|
|
Extra flags to pass to <command>updatedb</command>.
|
2014-06-16 07:03:29 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
output = mkOption {
|
|
|
|
type = types.path;
|
2014-08-27 10:51:54 +01:00
|
|
|
default = "/var/cache/locatedb";
|
2014-06-16 07:03:29 +01:00
|
|
|
description = ''
|
|
|
|
The database file to build.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
localuser = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "nobody";
|
|
|
|
description = ''
|
|
|
|
The user to search non-network directories as, using
|
|
|
|
<command>su</command>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-05-28 11:18:31 +01:00
|
|
|
includeStore = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2015-08-03 12:48:43 +01:00
|
|
|
Whether to include <filename>/nix/store<filename> in the locate database.
|
2015-05-28 11:18:31 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2008-11-09 16:44:53 +00:00
|
|
|
};
|
2013-08-14 01:58:55 +01:00
|
|
|
|
2008-11-09 16:44:53 +00:00
|
|
|
};
|
|
|
|
|
2013-08-14 01:58:55 +01:00
|
|
|
###### implementation
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2013-08-14 01:58:55 +01:00
|
|
|
config = {
|
|
|
|
systemd.services.update-locatedb =
|
|
|
|
{ description = "Update Locate Database";
|
|
|
|
path = [ pkgs.su ];
|
|
|
|
script =
|
|
|
|
''
|
2014-06-16 07:03:29 +01:00
|
|
|
mkdir -m 0755 -p $(dirname ${toString cfg.output})
|
|
|
|
exec updatedb \
|
2015-08-03 12:48:43 +01:00
|
|
|
--localuser=${cfg.localuser} \
|
|
|
|
${optionalString (!cfg.includeStore) "--prunepaths='/nix/store'"} \
|
|
|
|
--output=${toString cfg.output} ${concatStringsSep " " cfg.extraFlags}
|
2013-08-14 01:58:55 +01:00
|
|
|
'';
|
|
|
|
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";
|
2008-11-09 16:44:53 +00:00
|
|
|
|
|
|
|
};
|
2013-08-14 01:58:55 +01:00
|
|
|
|
2008-11-09 16:44:53 +00:00
|
|
|
}
|