Files
2026-10-28 08:00:16 +05:30

27 lines
1.9 KiB
Markdown

# i-am-gcroot
Go tool (TUI via bubbletea, optional htmx web UI) to list, filter and delete Nix GC roots. User docs are in README.md.
## Layout
- `main.go`: subcommands (`tui` default, `list`, `rm`, `gc`, `web`, `version`) with stdlib `flag`.
- `internal/roots`: discovery (`scan.go`, mirrors `findRoots` in libstore `gc.cc`: gcroots tree + `auto/` indirect roots + profiles dir; runtime roots via `nix-store --gc --print-roots`), `Set` (thread-safe shared state used by TUI and web, background size computation), `size.go` (`nix path-info --json -S`, accepts both object and array JSON formats), `delete.go` (only removes symlinks; profile generations via `nix-env --delete-generations`; protected roots need `Force`), `collect.go` (targeted GC: closure of deleted targets minus closure of all `--print-roots` targets, then `nix-store --delete`, retrying without paths nix reports alive). `Root.Hidden` marks nix cache roots (`hiddenPatterns` in `scan.go`); `filter.Apply` drops them unless `showHidden` or the query has `is:hidden`.
- `internal/filter`: query language and sorting shared by all frontends.
- `internal/tui`: bubbletea model (`model.go`) and rendering (`view.go`).
- `internal/web`: HTTP server, `templates/index.html` (page + `rows` fragment), `static/htmx.min.js` (vendored htmx 2.0.4, embedded).
- `nix/vm-test.nix` + `nix/vm-test.py`: NixOS VM integration test. The Python lives in its own file because nix `''` strings do not strip tab indentation.
`roots.Config` holds store/state dirs and binary names so tests run against a fake tree in a temp dir.
## Development
```
nix develop # go, gopls (CGO_ENABLED=0)
go test ./...
nix build # runs go tests too
nix build .#checks.x86_64-linux.vm -L # VM test
nix flake check
```
When Go dependencies change, set `vendorHash` in `flake.nix` to a fake hash, run `nix build`, and copy the `got:` hash. Nix files are indented with tabs.