nixos-configs/modules/base/locate/default.nix

83 lines
1.7 KiB
Nix
Raw Permalink Normal View History

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