A Terminal User Interface (TUI) tool for cleaning up orphaned files in NixOS impermanence/persistence setups.
Totally vibe-coded !!!
When using NixOS with impermanence, it's easy to accumulate orphaned files in your persistence directoryβfiles that are no longer actively used by your system configuration.
nixjanitor helps you identify and clean up these orphaned files through an interactive TUI:
- π Auto-detects active persistence paths from your NixOS configuration
- π Displays orphaned files in an interactive checklist
- ποΈ Safe deletion with optional trash (files moved to
.trash/instead of permanent deletion) - π³ Tree view showing parent/child relationships between directories and files
- π Fast scanning with concurrent directory traversal
- β‘ Dry-run mode to preview changes before applying them
nix run github:tharoldD/nixjanitorWith flags:
nix run github:tharoldD/nixjanitor -- --dry-run --persist-root /persistnix profile install github:tharoldD/nixjanitor
nixjanitor --helpAdd to your flake.nix:
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixjanitor.url = "github:tharoldD/nixjanitor";
};
outputs = { self, nixpkgs, nixjanitor, ... }: {
nixosConfigurations.your-hostname = nixpkgs.lib.nixosSystem {
# ... your config ...
environment.systemPackages = [
nixjanitor.packages.${system}.default
];
};
};
}{
inputs.nixjanitor.url = "github:tharoldD/nixjanitor";
nixpkgs.overlays = [ inputs.nixjanitor.overlays.default ];
environment.systemPackages = [ pkgs.nixjanitor ];
}nixjanitorThe tool will:
- Auto-detect your persistence root (
/persist,/nix/persist, or/persistent) - Auto-detect active paths from your NixOS configuration
- Scan for all files in the persistence directory
- Display orphaned files in an interactive checklist
- Allow you to select files for deletion
nixjanitor [OPTIONS]
Options:
--persist-root string Path to persistence storage (auto-detected if empty)
--hostname string NixOS config hostname (auto-detected if empty)
--dry-run Show what would be deleted without deleting
--no-trash Delete directly instead of moving to trashDry-run mode (safe preview):
nixjanitor --dry-runSpecify persistence root:
nixjanitor --persist-root /mnt/persistDelete permanently (skip trash):
nixjanitor --no-trashSpecify hostname for configuration detection:
nixjanitor --hostname my-laptopOnce in the TUI:
- β/β or j/k: Navigate through the file list
- Space: Toggle selection for deletion
- Enter: Expand/collapse directories
- Tab: Jump to next section
- d: Start deletion of selected items
- q: Quit
nixjanitor detects active persistence paths using two methods:
Primary method (recommended): Parses your NixOS configuration via nix eval:
nix eval /etc/nixos#nixosConfigurations.<hostname>.config.environment.persistence --jsonFallback method: Parses /proc/self/mountinfo to find bind mounts.
- Recursively scans the persistence directory
- Skips the
.trash/directory (used for safe deletion) - Builds a tree structure of files and directories
- Marks files as "orphaned" if they're not in the active paths list
- Moves selected files to
.trash/by default (can be permanently deleted with--no-trash) - Shows progress for each file being cleaned
- Handles errors gracefully (e.g., permission denied)
- NixOS with a persistence setup (e.g., using impermanence)
- Nix flakes enabled (for configuration detection)
- Linux (uses
/proc/self/mountinfofor fallback detection) - Root directory mounted as tmpfs or similar ephemeral filesystem
This tool is designed for NixOS systems using impermanence patterns like:
{
environment.persistence."/persist" = {
directories = [
"/etc/nixos"
"/var/log"
"/var/lib/systemd"
];
files = [
"/etc/machine-id"
];
users.youruser = {
directories = [
"Documents"
"Downloads"
".config/nvim"
];
files = [
".ssh/id_ed25519"
];
};
};
}git clone https://github.com/tharoldD/nixjanitor.git
cd nixjanitor
go build -o nixjanitorWith flakes:
nix developLegacy nix-shell (delegates to flake):
nix-shellThe development environment includes:
- Go 1.26.3
- gopls (language server)
- go-tools (staticcheck, etc.)
nixjanitor/
βββ main.go # Entry point, CLI parsing
βββ internal/
β βββ app/ # Bubble Tea TUI model & state machine
β β βββ model.go # Main model & update logic
β β βββ states.go # 6-state pipeline
β β βββ styles.go # Lipgloss styling
β βββ detect/ # Active path detection
β β βββ detect.go # nix eval + /proc/self/mountinfo parsing
β βββ scanner/ # Filesystem scanning
β β βββ scanner.go # Recursive directory walker
β βββ cleanup/ # Deletion logic
β βββ cleanup.go # Move to trash or delete
βββ flake.nix # Nix flake definition
βββ go.mod # Go module dependencies
βββ README.md # This file
- AI Agents.
- Bubble Tea v2 - TUI framework
- Lip Gloss v2 - Terminal styling
- Bubbles v2 - TUI components