2018-07-20 22:56:59 +02:00
|
|
|
{ config, 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;
|
2017-01-05 18:57:45 +01:00
|
|
|
isMLocate = hasPrefix "mlocate" cfg.locate.name;
|
2022-01-24 00:36:51 +01:00
|
|
|
isPLocate = hasPrefix "plocate" cfg.locate.name;
|
|
|
|
isMorPLocate = (isMLocate || isPLocate);
|
2017-01-05 18:57:45 +01:00
|
|
|
isFindutils = hasPrefix "findutils" cfg.locate.name;
|
2022-01-24 00:36:51 +01:00
|
|
|
in
|
|
|
|
{
|
2019-12-10 02:51:19 +01:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "services" "locate" "period" ] [ "services" "locate" "interval" ])
|
2022-01-24 00:36:51 +01:00
|
|
|
(mkRemovedOptionModule [ "services" "locate" "includeStore" ] "Use services.locate.prunePaths")
|
2019-12-10 02:51:19 +01:00
|
|
|
];
|
|
|
|
|
2017-01-05 18:57:45 +01:00
|
|
|
options.services.locate = with types; {
|
2016-01-23 21:44:30 +01:00
|
|
|
enable = mkOption {
|
2017-01-05 18:57:45 +01:00
|
|
|
type = bool;
|
2016-01-23 21:44:30 +01:00
|
|
|
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 {
|
2017-01-05 18:57:45 +01:00
|
|
|
type = package;
|
2016-10-25 13:58:49 +02:00
|
|
|
default = pkgs.findutils;
|
2021-10-03 18:06:03 +02:00
|
|
|
defaultText = literalExpression "pkgs.findutils";
|
|
|
|
example = literalExpression "pkgs.mlocate";
|
2016-10-25 13:58:49 +02:00
|
|
|
description = ''
|
|
|
|
The locate implementation to use
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-01-23 21:44:30 +01:00
|
|
|
interval = mkOption {
|
2017-01-05 18:57:45 +01:00
|
|
|
type = str;
|
2016-01-23 21:44:30 +01:00
|
|
|
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>.
|
2021-03-28 17:20:18 +02:00
|
|
|
|
|
|
|
To disable automatic updates, set to <literal>"never"</literal>
|
|
|
|
and run <command>updatedb</command> manually.
|
2016-01-23 21:44:30 +01:00
|
|
|
'';
|
|
|
|
};
|
2014-06-16 08:03:29 +02:00
|
|
|
|
2016-01-23 21:44:30 +01:00
|
|
|
extraFlags = mkOption {
|
2017-01-05 18:57:45 +01:00
|
|
|
type = listOf str;
|
2016-01-23 21:44:30 +01:00
|
|
|
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 {
|
2017-01-05 18:57:45 +01:00
|
|
|
type = path;
|
2016-01-23 21:44:30 +01:00
|
|
|
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-05 18:57:45 +01:00
|
|
|
type = nullOr 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
|
|
|
|
2017-01-05 18:57:45 +01:00
|
|
|
pruneFS = mkOption {
|
|
|
|
type = listOf str;
|
2020-11-23 06:52:17 +01:00
|
|
|
default = [
|
|
|
|
"afs"
|
|
|
|
"anon_inodefs"
|
|
|
|
"auto"
|
|
|
|
"autofs"
|
|
|
|
"bdev"
|
|
|
|
"binfmt"
|
|
|
|
"binfmt_misc"
|
2021-11-17 02:55:36 +01:00
|
|
|
"ceph"
|
2020-11-23 06:52:17 +01:00
|
|
|
"cgroup"
|
2021-11-17 02:55:36 +01:00
|
|
|
"cgroup2"
|
2020-11-23 06:52:17 +01:00
|
|
|
"cifs"
|
|
|
|
"coda"
|
|
|
|
"configfs"
|
|
|
|
"cramfs"
|
|
|
|
"cpuset"
|
2021-11-17 02:55:36 +01:00
|
|
|
"curlftpfs"
|
2020-11-23 06:52:17 +01:00
|
|
|
"debugfs"
|
|
|
|
"devfs"
|
|
|
|
"devpts"
|
|
|
|
"devtmpfs"
|
|
|
|
"ecryptfs"
|
|
|
|
"eventpollfs"
|
|
|
|
"exofs"
|
|
|
|
"futexfs"
|
|
|
|
"ftpfs"
|
|
|
|
"fuse"
|
|
|
|
"fusectl"
|
2021-11-17 02:55:36 +01:00
|
|
|
"fusesmb"
|
|
|
|
"fuse.ceph"
|
|
|
|
"fuse.glusterfs"
|
|
|
|
"fuse.gvfsd-fuse"
|
|
|
|
"fuse.mfs"
|
|
|
|
"fuse.rclone"
|
|
|
|
"fuse.rozofs"
|
2020-11-23 06:57:00 +01:00
|
|
|
"fuse.sshfs"
|
2020-11-23 06:52:17 +01:00
|
|
|
"gfs"
|
|
|
|
"gfs2"
|
|
|
|
"hostfs"
|
|
|
|
"hugetlbfs"
|
|
|
|
"inotifyfs"
|
|
|
|
"iso9660"
|
|
|
|
"jffs2"
|
|
|
|
"lustre"
|
2021-11-17 02:55:36 +01:00
|
|
|
"lustre_lite"
|
2020-11-23 06:52:17 +01:00
|
|
|
"misc"
|
2021-11-17 02:55:36 +01:00
|
|
|
"mfs"
|
2020-11-23 06:52:17 +01:00
|
|
|
"mqueue"
|
|
|
|
"ncpfs"
|
2021-11-17 02:55:36 +01:00
|
|
|
"nfs"
|
|
|
|
"NFS"
|
|
|
|
"nfs4"
|
|
|
|
"nfsd"
|
2020-11-23 06:52:17 +01:00
|
|
|
"nnpfs"
|
|
|
|
"ocfs"
|
|
|
|
"ocfs2"
|
|
|
|
"pipefs"
|
|
|
|
"proc"
|
|
|
|
"ramfs"
|
|
|
|
"rpc_pipefs"
|
|
|
|
"securityfs"
|
|
|
|
"selinuxfs"
|
|
|
|
"sfs"
|
|
|
|
"shfs"
|
|
|
|
"smbfs"
|
|
|
|
"sockfs"
|
|
|
|
"spufs"
|
|
|
|
"sshfs"
|
|
|
|
"subfs"
|
|
|
|
"supermount"
|
|
|
|
"sysfs"
|
|
|
|
"tmpfs"
|
2021-11-17 02:55:36 +01:00
|
|
|
"tracefs"
|
2020-11-23 06:52:17 +01:00
|
|
|
"ubifs"
|
2021-11-17 02:55:36 +01:00
|
|
|
"udev"
|
2020-11-23 06:52:17 +01:00
|
|
|
"udf"
|
|
|
|
"usbfs"
|
|
|
|
"vboxsf"
|
|
|
|
"vperfctrfs"
|
|
|
|
];
|
2017-01-05 18:57:45 +01:00
|
|
|
description = ''
|
|
|
|
Which filesystem types to exclude from indexing
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
prunePaths = mkOption {
|
|
|
|
type = listOf path;
|
2022-01-24 00:36:51 +01:00
|
|
|
default = [
|
|
|
|
"/tmp"
|
|
|
|
"/var/tmp"
|
|
|
|
"/var/cache"
|
|
|
|
"/var/lock"
|
|
|
|
"/var/run"
|
|
|
|
"/var/spool"
|
|
|
|
"/nix/store"
|
|
|
|
"/nix/var/log/nix"
|
|
|
|
];
|
2017-01-05 18:57:45 +01:00
|
|
|
description = ''
|
|
|
|
Which paths to exclude from indexing
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
pruneNames = mkOption {
|
|
|
|
type = listOf str;
|
2021-11-17 04:19:53 +01:00
|
|
|
default = [ ".bzr" ".cache" ".git" ".hg" ".svn" ];
|
2017-01-05 18:57:45 +01:00
|
|
|
description = ''
|
|
|
|
Directory components which should exclude paths containing them from indexing
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
pruneBindMounts = mkOption {
|
|
|
|
type = bool;
|
2016-01-23 21:44:30 +01:00
|
|
|
default = false;
|
|
|
|
description = ''
|
2017-01-05 18:57:45 +01:00
|
|
|
Whether not to index bind mounts
|
2016-01-23 21:44:30 +01:00
|
|
|
'';
|
|
|
|
};
|
2018-03-19 20:24:45 +01:00
|
|
|
|
2008-11-09 17:44:53 +01:00
|
|
|
};
|
|
|
|
|
2017-01-05 18:57:45 +01:00
|
|
|
config = mkIf cfg.enable {
|
2022-01-24 00:36:51 +01:00
|
|
|
users.groups = mkMerge [
|
|
|
|
(mkIf isMLocate { mlocate = { }; })
|
|
|
|
(mkIf isPLocate { plocate = { }; })
|
|
|
|
];
|
2017-01-05 18:57:45 +01:00
|
|
|
|
2022-01-24 00:36:51 +01:00
|
|
|
security.wrappers =
|
|
|
|
let
|
|
|
|
common = {
|
|
|
|
owner = "root";
|
|
|
|
permissions = "u+rx,g+x,o+x";
|
|
|
|
setgid = true;
|
|
|
|
setuid = false;
|
|
|
|
};
|
|
|
|
mlocate = (mkIf isMLocate {
|
|
|
|
group = "mlocate";
|
|
|
|
source = "${cfg.locate}/bin/locate";
|
|
|
|
});
|
|
|
|
plocate = (mkIf isPLocate {
|
|
|
|
group = "plocate";
|
|
|
|
source = "${cfg.locate}/bin/plocate";
|
|
|
|
});
|
|
|
|
in
|
|
|
|
mkIf isMorPLocate {
|
|
|
|
locate = mkMerge [ common mlocate plocate ];
|
|
|
|
plocate = (mkIf isPLocate (mkMerge [ common plocate ]));
|
2017-01-29 18:27:08 +01:00
|
|
|
};
|
2017-01-05 18:57:45 +01:00
|
|
|
|
2017-01-05 20:16:48 +01:00
|
|
|
nixpkgs.config = { locate.dbfile = cfg.output; };
|
|
|
|
|
2017-01-05 18:57:45 +01:00
|
|
|
environment.systemPackages = [ cfg.locate ];
|
|
|
|
|
2022-01-24 00:36:51 +01:00
|
|
|
environment.variables = mkIf (!isMorPLocate) { LOCATE_PATH = cfg.output; };
|
2017-01-05 20:16:48 +01:00
|
|
|
|
2021-03-28 17:20:18 +02:00
|
|
|
environment.etc = {
|
|
|
|
# write /etc/updatedb.conf for manual calls to `updatedb`
|
|
|
|
"updatedb.conf" = {
|
|
|
|
text = ''
|
|
|
|
PRUNEFS="${lib.concatStringsSep " " cfg.pruneFS}"
|
|
|
|
PRUNENAMES="${lib.concatStringsSep " " cfg.pruneNames}"
|
|
|
|
PRUNEPATHS="${lib.concatStringsSep " " cfg.prunePaths}"
|
2021-11-17 04:26:42 +01:00
|
|
|
PRUNE_BIND_MOUNTS="${if cfg.pruneBindMounts then "yes" else "no"}"
|
2021-03-28 17:20:18 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-01-24 00:36:51 +01:00
|
|
|
warnings = optional (isMorPLocate && cfg.localuser != null)
|
|
|
|
"mlocate does not support the services.locate.localuser option; updatedb will run as root. (Silence with services.locate.localuser = null.)"
|
|
|
|
++ optional (isFindutils && cfg.pruneNames != [ ])
|
|
|
|
"findutils locate does not support pruning by directory component"
|
|
|
|
++ optional (isFindutils && cfg.pruneBindMounts)
|
|
|
|
"findutils locate does not support skipping bind mounts";
|
2017-10-11 11:18:28 +02:00
|
|
|
|
2022-01-24 00:36:51 +01:00
|
|
|
systemd.services.update-locatedb = {
|
|
|
|
description = "Update Locate Database";
|
|
|
|
path = mkIf (!isMorPLocate) [ pkgs.su ];
|
2018-03-19 20:24:45 +01:00
|
|
|
|
2022-01-24 00:36:51 +01:00
|
|
|
# mlocate's updatedb takes flags via a configuration file or
|
|
|
|
# on the command line, but not by environment variable.
|
|
|
|
script =
|
|
|
|
if isMorPLocate then
|
|
|
|
let
|
|
|
|
toFlags = x:
|
|
|
|
optional (cfg.${x} != [ ])
|
|
|
|
"--${lib.toLower x} '${concatStringsSep " " cfg.${x}}'";
|
|
|
|
args = concatLists (map toFlags [ "pruneFS" "pruneNames" "prunePaths" ]);
|
|
|
|
in
|
|
|
|
''
|
2018-03-19 20:24:45 +01:00
|
|
|
exec ${cfg.locate}/bin/updatedb \
|
|
|
|
--output ${toString cfg.output} ${concatStringsSep " " args} \
|
|
|
|
--prune-bind-mounts ${if cfg.pruneBindMounts then "yes" else "no"} \
|
|
|
|
${concatStringsSep " " cfg.extraFlags}
|
2013-08-14 02:58:55 +02:00
|
|
|
''
|
2022-01-24 00:36:51 +01:00
|
|
|
else ''
|
|
|
|
exec ${cfg.locate}/bin/updatedb \
|
|
|
|
${optionalString (cfg.localuser != null && !isMorPLocate) "--localuser=${cfg.localuser}"} \
|
|
|
|
--output=${toString cfg.output} ${concatStringsSep " " cfg.extraFlags}
|
|
|
|
'';
|
|
|
|
environment = optionalAttrs (!isMorPLocate) {
|
|
|
|
PRUNEFS = concatStringsSep " " cfg.pruneFS;
|
|
|
|
PRUNEPATHS = concatStringsSep " " cfg.prunePaths;
|
|
|
|
PRUNENAMES = concatStringsSep " " cfg.pruneNames;
|
|
|
|
PRUNE_BIND_MOUNTS = if cfg.pruneBindMounts then "yes" else "no";
|
2013-08-14 02:58:55 +02:00
|
|
|
};
|
2022-01-24 00:36:51 +01:00
|
|
|
serviceConfig.Nice = 19;
|
|
|
|
serviceConfig.IOSchedulingClass = "idle";
|
|
|
|
serviceConfig.PrivateTmp = "yes";
|
|
|
|
serviceConfig.PrivateNetwork = "yes";
|
|
|
|
serviceConfig.NoNewPrivileges = "yes";
|
|
|
|
serviceConfig.ReadOnlyPaths = "/";
|
|
|
|
# Use dirOf cfg.output because mlocate creates temporary files next to
|
|
|
|
# the actual database. We could specify and create them as well,
|
|
|
|
# but that would make this quite brittle when they change something.
|
|
|
|
# NOTE: If /var/cache does not exist, this leads to the misleading error message:
|
|
|
|
# update-locatedb.service: Failed at step NAMESPACE spawning …/update-locatedb-start: No such file or directory
|
|
|
|
serviceConfig.ReadWritePaths = dirOf cfg.output;
|
|
|
|
};
|
2013-08-14 02:58:55 +02:00
|
|
|
|
2022-01-24 00:36:51 +01:00
|
|
|
systemd.timers.update-locatedb = mkIf (cfg.interval != "never") {
|
|
|
|
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
|
|
|
};
|
2022-01-24 00:36:51 +01:00
|
|
|
|
|
|
|
meta.maintainers = with lib.maintainers; [ SuperSandro2000 ];
|
2008-11-09 17:44:53 +01:00
|
|
|
}
|