Hi,
I’d like to know the size of the complete /nix/store to decide whether to do GC when it gets over a threshold.
Currently I’m reading the nix DB to do that:
sqlite3 'file:/nix/var/nix/db/db.sqlite?readonly=true&immutable=true' 'SELECT SUM(narSize) FROM ValidPaths'
That works, but of course that’s not a supported API, and I’m ignoring the lock which I’m sure could lead to errors (maybe it would be possible to run this with the permissions and in the mount namespace of the nix daemon?).
The manual suggests this, but it’s very inefficient:
· Show the size of the entire Nix store: | # nix path-info --json --all | jq 'map(.narSize) | add' | 49812020936
Is there a way to do the equivalent of the sqlite query through the nix CLI or in the nix language?
If not, would there be interest in adding such a feature?
What I’d ideally like is the same as the min-free
option: https://nix.dev/manual/nix/2.24/command-ref/conf-file.html#conf-min-free
but as max-usage
instead. But just having that sqlite query exposed would be sufficient to do it manually.