From 3ad512ce78309726a2c472122213159a91c4f4a1 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Thu, 30 Nov 2023 22:25:10 -0500 Subject: [PATCH] feat: make locate module that actually works --- common/default.nix | 2 +- common/modules/locate.nix | 80 +++++++++++++++++++++++++++++++++++++ common/modules/programs.nix | 24 ----------- 3 files changed, 81 insertions(+), 25 deletions(-) create mode 100644 common/modules/locate.nix delete mode 100644 common/modules/programs.nix diff --git a/common/default.nix b/common/default.nix index 4a201d97..d25bda60 100644 --- a/common/default.nix +++ b/common/default.nix @@ -20,8 +20,8 @@ home-manager.nixosModules.default nh.nixosModules.default - ./modules/programs.nix ./modules/locale.nix + ./modules/locate.nix ]; nixpkgs.config.allowUnfree = true; diff --git a/common/modules/locate.nix b/common/modules/locate.nix new file mode 100644 index 00000000..3c8a6ad8 --- /dev/null +++ b/common/modules/locate.nix @@ -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" + ]; + }; +} diff --git a/common/modules/programs.nix b/common/modules/programs.nix deleted file mode 100644 index 5c5e84df..00000000 --- a/common/modules/programs.nix +++ /dev/null @@ -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" - ]; - }; - }; -}