2016-01-23 21:44:30 +01:00
|
|
|
{ config, options, lib, pkgs, ... }:
|
2013-08-14 02:58:55 +02:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2008-11-09 17:44:53 +01:00
|
|
|
|
|
|
|
let
|
2014-06-16 08:03:29 +02:00
|
|
|
cfg = config.services.locate;
|
|
|
|
in {
|
2016-01-23 21:44:30 +01: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 02:58:55 +02:00
|
|
|
|
2016-10-25 13:58:49 +02:00
|
|
|
locate = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.findutils;
|
2017-01-26 12:56:53 +01:00
|
|
|
defaultText = "pkgs.findutils";
|
2016-10-25 13:58:49 +02:00
|
|
|
example = "pkgs.mlocate";
|
|
|
|
description = ''
|
|
|
|
The locate implementation to use
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-01-23 21:44:30 +01: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 08:03:29 +02:00
|
|
|
|
2016-01-23 21:44:30 +01:00
|
|
|
extraFlags = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
Extra flags to pass to <command>updatedb</command>.
|
|
|
|
'';
|
|
|
|
};
|
2014-06-16 08:03:29 +02:00
|
|
|
|
2016-01-23 21:44:30 +01:00
|
|
|
output = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/cache/locatedb";
|
|
|
|
description = ''
|
|
|
|
The database file to build.
|
|
|
|
'';
|
|
|
|
};
|
2015-05-28 12:18:31 +02:00
|
|
|
|
2016-01-23 21:44:30 +01:00
|
|
|
localuser = mkOption {
|
2017-01-26 12:56:53 +01:00
|
|
|
type = types.nullOr types.str;
|
2016-01-23 21:44:30 +01:00
|
|
|
default = "nobody";
|
|
|
|
description = ''
|
|
|
|
The user to search non-network directories as, using
|
|
|
|
<command>su</command>.
|
|
|
|
'';
|
2008-11-09 17:44:53 +01:00
|
|
|
};
|
2013-08-14 02:58:55 +02:00
|
|
|
|
2016-01-23 21:44:30 +01:00
|
|
|
includeStore = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to include <filename>/nix/store</filename> in the locate database.
|
|
|
|
'';
|
|
|
|
};
|
2008-11-09 17:44:53 +01:00
|
|
|
};
|
|
|
|
|
2013-08-14 02:58:55 +02:00
|
|
|
config = {
|
|
|
|
systemd.services.update-locatedb =
|
|
|
|
{ description = "Update Locate Database";
|
|
|
|
path = [ pkgs.su ];
|
|
|
|
script =
|
|
|
|
''
|
2014-06-16 08:03:29 +02:00
|
|
|
mkdir -m 0755 -p $(dirname ${toString cfg.output})
|
2016-10-25 13:58:49 +02:00
|
|
|
exec ${cfg.locate}/bin/updatedb \
|
2017-01-26 12:56:53 +01:00
|
|
|
${optionalString (cfg.localuser != null) ''--localuser=${cfg.localuser}''} \
|
2015-08-03 13:48:43 +02:00
|
|
|
${optionalString (!cfg.includeStore) "--prunepaths='/nix/store'"} \
|
|
|
|
--output=${toString cfg.output} ${concatStringsSep " " cfg.extraFlags}
|
2013-08-14 02:58:55 +02:00
|
|
|
'';
|
|
|
|
serviceConfig.Nice = 19;
|
|
|
|
serviceConfig.IOSchedulingClass = "idle";
|
2016-01-23 21:44:30 +01:00
|
|
|
serviceConfig.PrivateTmp = "yes";
|
|
|
|
serviceConfig.PrivateNetwork = "yes";
|
|
|
|
serviceConfig.NoNewPrivileges = "yes";
|
|
|
|
serviceConfig.ReadOnlyDirectories = "/";
|
2016-04-14 13:38:47 +02:00
|
|
|
serviceConfig.ReadWriteDirectories = dirOf cfg.output;
|
2013-08-14 02:58:55 +02:00
|
|
|
};
|
|
|
|
|
2016-01-23 21:44:30 +01: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 17:44:53 +01:00
|
|
|
};
|
|
|
|
}
|