feat: make locate module that actually works

This commit is contained in:
matt1432 2023-11-30 22:25:10 -05:00
parent 6028e3679a
commit 3ad512ce78
3 changed files with 81 additions and 25 deletions

View file

@ -20,8 +20,8 @@
home-manager.nixosModules.default
nh.nixosModules.default
./modules/programs.nix
./modules/locale.nix
./modules/locate.nix
];
nixpkgs.config.allowUnfree = true;

80
common/modules/locate.nix Normal file
View file

@ -0,0 +1,80 @@
{
config,
pkgs,
lib,
...
}: let
vars = config.services.device-vars;
locateGroup = lib.getName config.services.locate.package.name;
locate = "${config.services.locate.package}/bin/locate";
updatedb = "${config.services.locate.package}/bin/updatedb";
database = "/var/lib/locate/locatedb";
pruneFS = builtins.concatStringsSep " " config.services.locate.pruneFS;
pruneNames = builtins.concatStringsSep " " config.services.locate.pruneNames;
prunePaths = builtins.concatStringsSep " " config.services.locate.prunePaths;
updatedbBin = ''
${updatedb} -o ${database} --prunefs "${pruneFS}" \
--prunepaths "${prunePaths}" --prunenames "${pruneNames}"
'';
in {
users.users.${vars.username}.extraGroups = [
locateGroup
];
systemd.services.locate = {
wantedBy = ["default.target"];
serviceConfig = {
User = vars.username;
Group = locateGroup;
StateDirectory = "locate";
StateDirectoryMode = "0770";
ExecStart = updatedbBin;
};
};
home-manager.users.${vars.username}.imports = [
{
programs.bash.shellAliases = {
locate = "${pkgs.writeShellScriptBin "lct" ''
exec ${locate} -d ${database} "$@" 2> >(grep -v "/var/cache/locatedb")
''}/bin/lct";
updatedb = updatedbBin;
};
}
];
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"
];
};
}

View file

@ -1,24 +0,0 @@
{pkgs, ...}: {
services = {
fwupd.enable = true;
upower.enable = true;
locate = {
enable = true;
package = pkgs.mlocate;
localuser = null;
interval = "hourly";
prunePaths = [
"/tmp"
"/var/tmp"
"/var/cache"
"/var/lock"
"/var/run"
"/var/spool"
"/nix/var/log/nix"
"/proc"
"/run/user"
];
};
};
}