2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.locate;
|
2024-06-20 14:57:18 +00:00
|
|
|
isMLocate = lib.hasPrefix "mlocate" cfg.package.name;
|
|
|
|
isPLocate = lib.hasPrefix "plocate" cfg.package.name;
|
2023-10-09 19:29:22 +00:00
|
|
|
isMorPLocate = isMLocate || isPLocate;
|
2024-06-20 14:57:18 +00:00
|
|
|
isFindutils = lib.hasPrefix "findutils" cfg.package.name;
|
2022-01-25 03:21:06 +00:00
|
|
|
in
|
|
|
|
{
|
2020-04-24 23:36:52 +00:00
|
|
|
imports = [
|
2024-06-20 14:57:18 +00:00
|
|
|
(lib.mkRenamedOptionModule [ "services" "locate" "period" ] [ "services" "locate" "interval" ])
|
|
|
|
(lib.mkRenamedOptionModule [ "services" "locate" "locate" ] [ "services" "locate" "package" ])
|
|
|
|
(lib.mkRemovedOptionModule [ "services" "locate" "includeStore" ] "Use services.locate.prunePaths")
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
options.services.locate = {
|
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
If enabled, NixOS will periodically update the database of
|
2022-08-12 12:06:08 +00:00
|
|
|
files used by the {command}`locate` command.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
package = lib.mkPackageOption pkgs [ "findutils" "locate" ] {
|
2024-01-02 11:29:13 +00:00
|
|
|
example = "mlocate";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
interval = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "02:15";
|
|
|
|
example = "hourly";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Update the locate database at this interval. Updates by
|
|
|
|
default at 2:15 AM every day.
|
|
|
|
|
|
|
|
The format is described in
|
2022-08-21 13:32:41 +00:00
|
|
|
{manpage}`systemd.time(7)`.
|
2021-10-01 09:20:50 +00:00
|
|
|
|
2022-08-21 13:32:41 +00:00
|
|
|
To disable automatic updates, set to `"never"`
|
|
|
|
and run {command}`updatedb` manually.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
extraFlags = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = [ ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
Extra flags to pass to {command}`updatedb`.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
output = lib.mkOption {
|
|
|
|
type = lib.types.path;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "/var/cache/locatedb";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
The database file to build.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
localuser = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "nobody";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
The user to search non-network directories as, using
|
2022-08-12 12:06:08 +00:00
|
|
|
{command}`su`.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
pruneFS = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
2020-12-25 13:55:36 +00:00
|
|
|
default = [
|
|
|
|
"afs"
|
|
|
|
"anon_inodefs"
|
|
|
|
"auto"
|
|
|
|
"autofs"
|
|
|
|
"bdev"
|
|
|
|
"binfmt"
|
|
|
|
"binfmt_misc"
|
2021-12-06 16:07:01 +00:00
|
|
|
"ceph"
|
2020-12-25 13:55:36 +00:00
|
|
|
"cgroup"
|
2021-12-06 16:07:01 +00:00
|
|
|
"cgroup2"
|
2020-12-25 13:55:36 +00:00
|
|
|
"cifs"
|
|
|
|
"coda"
|
|
|
|
"configfs"
|
|
|
|
"cramfs"
|
|
|
|
"cpuset"
|
2021-12-06 16:07:01 +00:00
|
|
|
"curlftpfs"
|
2020-12-25 13:55:36 +00:00
|
|
|
"debugfs"
|
|
|
|
"devfs"
|
|
|
|
"devpts"
|
|
|
|
"devtmpfs"
|
|
|
|
"ecryptfs"
|
|
|
|
"eventpollfs"
|
|
|
|
"exofs"
|
|
|
|
"futexfs"
|
|
|
|
"ftpfs"
|
|
|
|
"fuse"
|
|
|
|
"fusectl"
|
2021-12-06 16:07:01 +00:00
|
|
|
"fusesmb"
|
|
|
|
"fuse.ceph"
|
|
|
|
"fuse.glusterfs"
|
|
|
|
"fuse.gvfsd-fuse"
|
|
|
|
"fuse.mfs"
|
|
|
|
"fuse.rclone"
|
|
|
|
"fuse.rozofs"
|
2020-12-25 13:55:36 +00:00
|
|
|
"fuse.sshfs"
|
|
|
|
"gfs"
|
|
|
|
"gfs2"
|
|
|
|
"hostfs"
|
|
|
|
"hugetlbfs"
|
|
|
|
"inotifyfs"
|
|
|
|
"iso9660"
|
|
|
|
"jffs2"
|
|
|
|
"lustre"
|
2021-12-06 16:07:01 +00:00
|
|
|
"lustre_lite"
|
2020-12-25 13:55:36 +00:00
|
|
|
"misc"
|
2021-12-06 16:07:01 +00:00
|
|
|
"mfs"
|
2020-12-25 13:55:36 +00:00
|
|
|
"mqueue"
|
|
|
|
"ncpfs"
|
2021-12-06 16:07:01 +00:00
|
|
|
"nfs"
|
|
|
|
"NFS"
|
|
|
|
"nfs4"
|
|
|
|
"nfsd"
|
2020-12-25 13:55:36 +00:00
|
|
|
"nnpfs"
|
|
|
|
"ocfs"
|
|
|
|
"ocfs2"
|
|
|
|
"pipefs"
|
|
|
|
"proc"
|
|
|
|
"ramfs"
|
|
|
|
"rpc_pipefs"
|
|
|
|
"securityfs"
|
|
|
|
"selinuxfs"
|
|
|
|
"sfs"
|
|
|
|
"shfs"
|
|
|
|
"smbfs"
|
|
|
|
"sockfs"
|
|
|
|
"spufs"
|
|
|
|
"sshfs"
|
|
|
|
"subfs"
|
|
|
|
"supermount"
|
|
|
|
"sysfs"
|
|
|
|
"tmpfs"
|
2021-12-06 16:07:01 +00:00
|
|
|
"tracefs"
|
2020-12-25 13:55:36 +00:00
|
|
|
"ubifs"
|
2021-12-06 16:07:01 +00:00
|
|
|
"udev"
|
2020-12-25 13:55:36 +00:00
|
|
|
"udf"
|
|
|
|
"usbfs"
|
|
|
|
"vboxsf"
|
|
|
|
"vperfctrfs"
|
|
|
|
];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Which filesystem types to exclude from indexing
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
prunePaths = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.path;
|
2022-01-25 03:21:06 +00:00
|
|
|
default = [
|
|
|
|
"/tmp"
|
|
|
|
"/var/tmp"
|
|
|
|
"/var/cache"
|
|
|
|
"/var/lock"
|
|
|
|
"/var/run"
|
|
|
|
"/var/spool"
|
|
|
|
"/nix/store"
|
|
|
|
"/nix/var/log/nix"
|
|
|
|
];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Which paths to exclude from indexing
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
pruneNames = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
2022-03-30 09:31:56 +00:00
|
|
|
default = lib.optionals (!isFindutils) [ ".bzr" ".cache" ".git" ".hg" ".svn" ];
|
2024-06-20 14:57:18 +00:00
|
|
|
defaultText = lib.literalMD ''
|
2022-09-09 14:08:57 +00:00
|
|
|
`[ ".bzr" ".cache" ".git" ".hg" ".svn" ]`, if
|
2022-03-30 09:31:56 +00:00
|
|
|
supported by the locate implementation (i.e. mlocate or plocate).
|
|
|
|
'';
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Directory components which should exclude paths containing them from indexing
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
pruneBindMounts = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Whether not to index bind mounts
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
users.groups = lib.mkMerge [
|
|
|
|
(lib.mkIf isMLocate { mlocate = { }; })
|
|
|
|
(lib.mkIf isPLocate { plocate = { }; })
|
2022-01-25 03:21:06 +00:00
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-01-25 03:21:06 +00:00
|
|
|
security.wrappers =
|
|
|
|
let
|
|
|
|
common = {
|
|
|
|
owner = "root";
|
|
|
|
permissions = "u+rx,g+x,o+x";
|
|
|
|
setgid = true;
|
|
|
|
setuid = false;
|
|
|
|
};
|
2024-06-20 14:57:18 +00:00
|
|
|
mlocate = lib.mkIf isMLocate {
|
2022-01-25 03:21:06 +00:00
|
|
|
group = "mlocate";
|
2023-10-09 19:29:22 +00:00
|
|
|
source = "${cfg.package}/bin/locate";
|
|
|
|
};
|
2024-06-20 14:57:18 +00:00
|
|
|
plocate = lib.mkIf isPLocate {
|
2022-01-25 03:21:06 +00:00
|
|
|
group = "plocate";
|
2023-10-09 19:29:22 +00:00
|
|
|
source = "${cfg.package}/bin/plocate";
|
|
|
|
};
|
2022-01-25 03:21:06 +00:00
|
|
|
in
|
2024-06-20 14:57:18 +00:00
|
|
|
lib.mkIf isMorPLocate {
|
|
|
|
locate = lib.mkMerge [ common mlocate plocate ];
|
|
|
|
plocate = lib.mkIf isPLocate (lib.mkMerge [ common plocate ]);
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
environment = {
|
|
|
|
# write /etc/updatedb.conf for manual calls to `updatedb`
|
|
|
|
etc."updatedb.conf".text = ''
|
|
|
|
PRUNEFS="${lib.concatStringsSep " " cfg.pruneFS}"
|
|
|
|
PRUNENAMES="${lib.concatStringsSep " " cfg.pruneNames}"
|
|
|
|
PRUNEPATHS="${lib.concatStringsSep " " cfg.prunePaths}"
|
|
|
|
PRUNE_BIND_MOUNTS="${if cfg.pruneBindMounts then "yes" else "no"}"
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
systemPackages = [ cfg.package ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
variables = lib.mkIf isFindutils {
|
|
|
|
LOCATE_PATH = cfg.output;
|
2021-10-01 09:20:50 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
warnings = lib.optional (isMorPLocate && cfg.localuser != null)
|
2022-05-18 14:49:53 +00:00
|
|
|
"mlocate and plocate do not support the services.locate.localuser option. updatedb will run as root. Silence this warning by setting services.locate.localuser = null."
|
2024-06-20 14:57:18 +00:00
|
|
|
++ lib.optional (isFindutils && cfg.pruneNames != [ ])
|
2022-01-25 03:21:06 +00:00
|
|
|
"findutils locate does not support pruning by directory component"
|
2024-06-20 14:57:18 +00:00
|
|
|
++ lib.optional (isFindutils && cfg.pruneBindMounts)
|
2022-01-25 03:21:06 +00:00
|
|
|
"findutils locate does not support skipping bind mounts";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-01-25 03:21:06 +00:00
|
|
|
systemd.services.update-locatedb = {
|
|
|
|
description = "Update Locate Database";
|
2024-06-20 14:57:18 +00:00
|
|
|
path = lib.mkIf (!isMorPLocate) [ pkgs.su ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-01-25 03:21:06 +00: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:
|
2024-06-20 14:57:18 +00:00
|
|
|
lib.optional (cfg.${x} != [ ])
|
|
|
|
"--${lib.toLower x} '${lib.concatStringsSep " " cfg.${x}}'";
|
|
|
|
args = lib.concatLists (map toFlags [ "pruneFS" "pruneNames" "prunePaths" ]);
|
2022-01-25 03:21:06 +00:00
|
|
|
in
|
|
|
|
''
|
2023-10-09 19:29:22 +00:00
|
|
|
exec ${cfg.package}/bin/updatedb \
|
2024-06-20 14:57:18 +00:00
|
|
|
--output ${toString cfg.output} ${lib.concatStringsSep " " args} \
|
2020-04-24 23:36:52 +00:00
|
|
|
--prune-bind-mounts ${if cfg.pruneBindMounts then "yes" else "no"} \
|
2024-06-20 14:57:18 +00:00
|
|
|
${lib.concatStringsSep " " cfg.extraFlags}
|
2020-04-24 23:36:52 +00:00
|
|
|
''
|
2022-01-25 03:21:06 +00:00
|
|
|
else ''
|
2023-10-09 19:29:22 +00:00
|
|
|
exec ${cfg.package}/bin/updatedb \
|
2024-06-20 14:57:18 +00:00
|
|
|
${lib.optionalString (cfg.localuser != null && !isMorPLocate) "--localuser=${cfg.localuser}"} \
|
|
|
|
--output=${toString cfg.output} ${lib.concatStringsSep " " cfg.extraFlags}
|
2022-01-25 03:21:06 +00:00
|
|
|
'';
|
2024-06-20 14:57:18 +00:00
|
|
|
environment = lib.optionalAttrs (!isMorPLocate) {
|
|
|
|
PRUNEFS = lib.concatStringsSep " " cfg.pruneFS;
|
|
|
|
PRUNEPATHS = lib.concatStringsSep " " cfg.prunePaths;
|
|
|
|
PRUNENAMES = lib.concatStringsSep " " cfg.pruneNames;
|
2022-01-25 03:21:06 +00:00
|
|
|
PRUNE_BIND_MOUNTS = if cfg.pruneBindMounts then "yes" else "no";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2024-06-20 14:57:18 +00:00
|
|
|
serviceConfig = {
|
|
|
|
Nice = 19;
|
|
|
|
IOSchedulingClass = "idle";
|
|
|
|
PrivateTmp = "yes";
|
|
|
|
PrivateNetwork = "yes";
|
|
|
|
NoNewPrivileges = "yes";
|
|
|
|
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
|
|
|
|
ReadWritePaths = dirOf cfg.output;
|
|
|
|
};
|
2022-01-25 03:21:06 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
systemd.timers.update-locatedb = lib.mkIf (cfg.interval != "never") {
|
2022-01-25 03:21:06 +00:00
|
|
|
description = "Update timer for locate database";
|
|
|
|
partOf = [ "update-locatedb.service" ];
|
|
|
|
wantedBy = [ "timers.target" ];
|
2024-07-27 06:49:29 +00:00
|
|
|
timerConfig = {
|
|
|
|
OnCalendar = cfg.interval;
|
|
|
|
Persistent = true;
|
|
|
|
};
|
2022-01-25 03:21:06 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2022-01-25 03:21:06 +00:00
|
|
|
|
|
|
|
meta.maintainers = with lib.maintainers; [ SuperSandro2000 ];
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|