2016-01-23 20:44:30 +00:00
|
|
|
|
{ config, options, 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 {
|
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 01:58:55 +01:00
|
|
|
|
|
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 07:03:29 +01: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 07:03:29 +01: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 07:03:29 +01: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 11:18:31 +01: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 01:58:55 +01: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 01:58:55 +01: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 01:58:55 +01:00
|
|
|
|
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";
|
2016-01-23 20:44:30 +00:00
|
|
|
|
serviceConfig.PrivateTmp = "yes";
|
|
|
|
|
serviceConfig.PrivateNetwork = "yes";
|
|
|
|
|
serviceConfig.NoNewPrivileges = "yes";
|
|
|
|
|
serviceConfig.ReadOnlyDirectories = "/";
|
2016-04-14 12:38:47 +01:00
|
|
|
|
serviceConfig.ReadWriteDirectories = dirOf cfg.output;
|
2013-08-14 01:58:55 +01: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
|
|
|
|
};
|
|
|
|
|
}
|