Something went wrong. Try again.
Home Manager module for pruning old node_modules folders
Something went wrong. Try again.
Nix 100%
README.md
dustpan #
A Home Manager module that prunes build and dependency folders (like node_modules/, target/, etc.) older than N days, automatically, on a timer.
Install and Usage #
Add the following to your flake:
inputs.dustpan.url = "git+https://tangled.org/matthew-hre.com/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";
};
}
Options #
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").
Result #
A systemd timer and service is created to periodically run a cleanup. Logs are visible in the journal:
journalctl --user -u dustpan.service
Why? #
I 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.
License #
MIT © Matthew Hrehirchuk