2023-11-30 22:25:10 -05:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}: let
|
2023-12-01 14:12:33 -05:00
|
|
|
cfg = config.services.locate;
|
2023-11-30 22:25:10 -05:00
|
|
|
|
2023-12-01 14:12:33 -05:00
|
|
|
locateGroup = lib.getName cfg.package.name;
|
|
|
|
|
|
|
|
locate = "${cfg.package}/bin/locate";
|
|
|
|
updatedb = "${cfg.package}/bin/updatedb";
|
2023-11-30 22:25:10 -05:00
|
|
|
|
|
|
|
database = "/var/lib/locate/locatedb";
|
2023-12-01 14:12:33 -05:00
|
|
|
pruneFS = builtins.concatStringsSep " " cfg.pruneFS;
|
|
|
|
pruneNames = builtins.concatStringsSep " " cfg.pruneNames;
|
|
|
|
prunePaths = builtins.concatStringsSep " " cfg.prunePaths;
|
2023-11-30 22:25:10 -05:00
|
|
|
|
|
|
|
updatedbBin = ''
|
|
|
|
${updatedb} -o ${database} --prunefs "${pruneFS}" \
|
|
|
|
--prunepaths "${prunePaths}" --prunenames "${pruneNames}"
|
|
|
|
'';
|
|
|
|
in {
|
2023-12-01 14:12:33 -05:00
|
|
|
users.users.${config.vars.user}.extraGroups = [
|
2023-11-30 22:25:10 -05:00
|
|
|
locateGroup
|
|
|
|
];
|
|
|
|
|
2024-01-04 03:39:14 -05:00
|
|
|
# TODO: add timer
|
2023-11-30 22:25:10 -05:00
|
|
|
systemd.services.locate = {
|
|
|
|
wantedBy = ["default.target"];
|
|
|
|
serviceConfig = {
|
2023-12-01 14:12:33 -05:00
|
|
|
User = config.vars.user;
|
2023-11-30 22:25:10 -05:00
|
|
|
Group = locateGroup;
|
|
|
|
StateDirectory = "locate";
|
|
|
|
StateDirectoryMode = "0770";
|
|
|
|
ExecStart = updatedbBin;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-12-01 14:12:33 -05:00
|
|
|
home-manager.users.${config.vars.user}.programs.bash.shellAliases = {
|
|
|
|
locate = "${pkgs.writeShellScriptBin "lct" ''
|
|
|
|
exec ${locate} -d ${database} "$@" 2> >(grep -v "/var/cache/locatedb")
|
|
|
|
''}/bin/lct";
|
2023-11-30 22:25:10 -05:00
|
|
|
|
2023-12-01 14:12:33 -05:00
|
|
|
updatedb = updatedbBin;
|
|
|
|
};
|
2023-11-30 22:25:10 -05:00
|
|
|
|
|
|
|
services.locate = {
|
|
|
|
enable = true;
|
|
|
|
package = pkgs.mlocate;
|
|
|
|
localuser = null;
|
|
|
|
interval = "never";
|
|
|
|
|
|
|
|
prunePaths = [
|
|
|
|
"/var/lib/flatpak"
|
|
|
|
|
|
|
|
# Defaults
|
|
|
|
"/tmp"
|
|
|
|
"/var/tmp"
|
|
|
|
"/var/cache"
|
|
|
|
"/var/lock"
|
|
|
|
"/var/run"
|
|
|
|
"/var/spool"
|
|
|
|
"/nix/var/log/nix"
|
|
|
|
];
|
|
|
|
|
|
|
|
pruneNames = [
|
|
|
|
"node_modules"
|
|
|
|
|
|
|
|
# Defaults
|
|
|
|
".bzr"
|
|
|
|
".cache"
|
|
|
|
".git"
|
|
|
|
".hg"
|
|
|
|
".svn"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|