diff options
| author | Arpit Chakladar <arpitchakladar+git@gmail.com> | 2026-07-18 14:55:21 +0530 |
|---|---|---|
| committer | Arpit Chakladar <arpitchakladar+git@gmail.com> | 2026-07-18 14:55:21 +0530 |
| commit | 03bd9b6ad5335aff65d9cb6fb1d117b5cb4b7919 (patch) | |
| tree | 04780c0d23aac335fe60320c181bd3ac6850d5d3 /modules/scripts/deep-clean | |
| parent | bde84587b2a408970086f4c708ac9a629abfa554 (diff) | |
| download | home-manager-config-03bd9b6ad5335aff65d9cb6fb1d117b5cb4b7919.tar.gz home-manager-config-03bd9b6ad5335aff65d9cb6fb1d117b5cb4b7919.zip | |
refactor(scripts): split monolithic module into per-script submodules
Extract shared `mkScript` and `mkScriptModule` helpers into `lib.nix`
Split each script into `modules/scripts/<name>/` with its own
`default.nix`, `script.sh`, and `assertions.nix`
Remove `conditions` parameter from `mkScriptModule`; move condition
assertions into per-script `assertions.nix` files with inline checks
and error messages
Simplify `mkScriptModule` to return `{ options, moduleConfig }` instead
of a module function, taking `config` as a direct parameter
Add `description` field to `mkScript` that inserts the description as
a `# <text>` comment between the shebang and env vars
Thread `description` through `mkScriptModule` to each `default.nix`
Move top comment lines from each `script.sh` into the `description`
field and remove from sources to avoid duplication
Remove old flat `.sh` files from `modules/scripts/` root
Diffstat (limited to 'modules/scripts/deep-clean')
| -rw-r--r-- | modules/scripts/deep-clean/default.nix | 19 | ||||
| -rw-r--r-- | modules/scripts/deep-clean/script.sh | 30 |
2 files changed, 49 insertions, 0 deletions
diff --git a/modules/scripts/deep-clean/default.nix b/modules/scripts/deep-clean/default.nix new file mode 100644 index 0000000..dc93c2c --- /dev/null +++ b/modules/scripts/deep-clean/default.nix @@ -0,0 +1,19 @@ +{ + config, + lib, + pkgs, + ... +}: +let + inherit ((import ../lib.nix { inherit lib pkgs; })) mkScriptModule; + base = mkScriptModule { + name = "deep-clean"; + path = ./script.sh; + description = "Deep clean script for Nix systems\nRemoves old generations, garbage, and optimizes store\nWARNING: Do NOT run with sudo - run as normal user"; + inherit config; + }; +in +{ + options = base.options; + config = base.moduleConfig; +} diff --git a/modules/scripts/deep-clean/script.sh b/modules/scripts/deep-clean/script.sh new file mode 100644 index 0000000..dcbd62b --- /dev/null +++ b/modules/scripts/deep-clean/script.sh @@ -0,0 +1,30 @@ +echo "--- Starting Nix Deep Clean ---" + +if [[ $EUID -eq 0 ]]; then + echo "Error: Do not run this script with 'sudo ./clean-nix.sh'." + echo "Run it as your normal user; it will ask for your password when needed." + exit 1 +fi + +echo "Cleaning system generations..." +sudo nix-env -p /nix/var/nix/profiles/system --delete-generations old + +if command -v home-manager &> /dev/null; then + echo "Cleaning Home Manager generations..." + home-manager expire-generations "-0 days" +fi + +echo "Cleaning user generations..." +nix-env --delete-generations old + +echo "Removing 'result' symlinks in current directory..." +find . -name "result" -type l -delete + +echo "Running Garbage Collector..." +sudo nix-collect-garbage -d +nix-collect-garbage -d + +echo "Optimising the store (deduplicating files)..." +nix store optimise + +echo "--- Clean Up Complete ---" |
