2016-01-23 20:44:30 +00:00
|
|
|
|
{ config, options, lib, pkgs, ... }:
|
2013-08-14 00:58:55 +00:00
|
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
|
with lib;
|
2008-11-09 16:44:53 +00:00
|
|
|
|
|
|
|
|
|
let
|
2014-06-16 06:03:29 +00:00
|
|
|
|
cfg = config.services.locate;
|
|
|
|
|
in {
|
2016-01-23 20:44:30 +00:00
|
|
|
|
options.services.locate = {
|
|
|
|
|
enable = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
|
|
|
|
description = ''
|
|
|
|
|
If enabled, NixOS will periodically update the database of
|
|
|
|
|
files used by the <command>locate</command> command.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2013-08-14 00:58:55 +00:00
|
|
|
|
|
2016-10-25 11:58:49 +00:00
|
|
|
|
locate = mkOption {
|
|
|
|
|
type = types.package;
|
|
|
|
|
default = pkgs.findutils;
|
|
|
|
|
example = "pkgs.mlocate";
|
|
|
|
|
description = ''
|
|
|
|
|
The locate implementation to use
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2016-01-23 20:44:30 +00:00
|
|
|
|
interval = mkOption {
|
|
|
|
|
type = types.str;
|
|
|
|
|
default = "02:15";
|
|
|
|
|
example = "hourly";
|
|
|
|
|
description = ''
|
|
|
|
|
Update the locate database at this interval. Updates by
|
|
|
|
|
default at 2:15 AM every day.
|
|
|
|
|
|
|
|
|
|
The format is described in
|
|
|
|
|
<citerefentry><refentrytitle>systemd.time</refentrytitle>
|
|
|
|
|
<manvolnum>7</manvolnum></citerefentry>.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2014-06-16 06:03:29 +00:00
|
|
|
|
|
2016-01-23 20:44:30 +00:00
|
|
|
|
# This is no longer supported, but we keep it to give a better warning below
|
|
|
|
|
period = mkOption { visible = false; };
|
2014-06-16 06:03:29 +00:00
|
|
|
|
|
2016-01-23 20:44:30 +00:00
|
|
|
|
extraFlags = mkOption {
|
|
|
|
|
type = types.listOf types.str;
|
|
|
|
|
default = [ ];
|
|
|
|
|
description = ''
|
|
|
|
|
Extra flags to pass to <command>updatedb</command>.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2014-06-16 06:03:29 +00:00
|
|
|
|
|
2016-01-23 20:44:30 +00:00
|
|
|
|
output = mkOption {
|
|
|
|
|
type = types.path;
|
|
|
|
|
default = "/var/cache/locatedb";
|
|
|
|
|
description = ''
|
|
|
|
|
The database file to build.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2015-05-28 10:18:31 +00:00
|
|
|
|
|
2016-01-23 20:44:30 +00:00
|
|
|
|
localuser = mkOption {
|
|
|
|
|
type = types.str;
|
|
|
|
|
default = "nobody";
|
|
|
|
|
description = ''
|
|
|
|
|
The user to search non-network directories as, using
|
|
|
|
|
<command>su</command>.
|
|
|
|
|
'';
|
2008-11-09 16:44:53 +00:00
|
|
|
|
};
|
2013-08-14 00:58:55 +00:00
|
|
|
|
|
2016-01-23 20:44:30 +00:00
|
|
|
|
includeStore = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
|
|
|
|
description = ''
|
|
|
|
|
Whether to include <filename>/nix/store</filename> in the locate database.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2008-11-09 16:44:53 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-08-14 00:58:55 +00:00
|
|
|
|
config = {
|
2016-02-27 19:47:10 +00:00
|
|
|
|
warnings =
|
|
|
|
|
let opt = options.services.locate.period; in
|
|
|
|
|
optional opt.isDefined "The ‘services.locate.period’ option in ${showFiles opt.files} has been removed; please replace it with ‘services.locate.interval’, using the systemd.time(7) calendar event format.";
|
2016-01-23 20:44:30 +00:00
|
|
|
|
|
2013-08-14 00:58:55 +00:00
|
|
|
|
systemd.services.update-locatedb =
|
|
|
|
|
{ description = "Update Locate Database";
|
|
|
|
|
path = [ pkgs.su ];
|
|
|
|
|
script =
|
|
|
|
|
''
|
2014-06-16 06:03:29 +00:00
|
|
|
|
mkdir -m 0755 -p $(dirname ${toString cfg.output})
|
2016-10-25 11:58:49 +00:00
|
|
|
|
exec ${cfg.locate}/bin/updatedb \
|
2015-08-03 11:48:43 +00:00
|
|
|
|
--localuser=${cfg.localuser} \
|
|
|
|
|
${optionalString (!cfg.includeStore) "--prunepaths='/nix/store'"} \
|
|
|
|
|
--output=${toString cfg.output} ${concatStringsSep " " cfg.extraFlags}
|
2013-08-14 00:58:55 +00:00
|
|
|
|
'';
|
|
|
|
|
serviceConfig.Nice = 19;
|
|
|
|
|
serviceConfig.IOSchedulingClass = "idle";
|
2016-01-23 20:44:30 +00:00
|
|
|
|
serviceConfig.PrivateTmp = "yes";
|
|
|
|
|
serviceConfig.PrivateNetwork = "yes";
|
|
|
|
|
serviceConfig.NoNewPrivileges = "yes";
|
|
|
|
|
serviceConfig.ReadOnlyDirectories = "/";
|
2016-04-14 11:38:47 +00:00
|
|
|
|
serviceConfig.ReadWriteDirectories = dirOf cfg.output;
|
2013-08-14 00:58:55 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-01-23 20:44:30 +00:00
|
|
|
|
systemd.timers.update-locatedb = mkIf cfg.enable
|
|
|
|
|
{ description = "Update timer for locate database";
|
|
|
|
|
partOf = [ "update-locatedb.service" ];
|
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
|
timerConfig.OnCalendar = cfg.interval;
|
|
|
|
|
};
|
2008-11-09 16:44:53 +00:00
|
|
|
|
};
|
|
|
|
|
}
|