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