A Home Manager module that prunes build and dependency folders (like node_modules/, target/, etc.) older than N days, automatically, on a timer.
Add the following to your flake:
inputs.dustpan.url = "github:matthew-hre/dustpan";
outputs = { dustpan, ... }: {
homeManagerModules.dustpan = dustpan.homeManagerModules.dustpan;
};And use it in your Home Manager configuration:
{inputs, ...}: {
imports = [
inputs.dustpan.homeManagerModules.dustpan
];
services.dustpan = {
enable = true;
roots = [ "$HOME/dev" "$HOME/Projects" ];
targets = [ "node_modules" "__pycache__" "target" ".cache" ];
olderThanDays = 30;
frequency = "weekly";
};
}enable: Enable automatic cleanup of old build/dependency folders (default:false).roots: Directories to search for folders to clean (default:["$HOME/projects" "$HOME/Projects", "$HOME/dev"]).targets: Names of folders to clean up (default:["node_modules"]).olderThanDays: Remove folders older than this many days (default:30).frequency: systemd timer OnCalendar value (default:"weekly").
A systemd timer and service is created to periodically run a cleanup. Logs are visible in the journal:
journalctl --user -u dustpan.serviceI usually have a couple GB of node_modules folders lying around in various projects that I no longer work on, and as great as npkill is, I don't run it as much as I should. Inspired by the nix.gc.automatic flag, this module automates the cleanup process, so that old node_modules folders are pruned regularly.
MIT © Matthew Hrehirchuk