Created
February 15, 2023 14:40
-
-
Save oxalica/c7fd0ce85e305fef7dfca86902e5e25f to your computer and use it in GitHub Desktop.
Query all reachable nix store paths
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
roots_file="$(mktemp)" | |
find /nix/var/nix/gcroots -type l | xargs realpath 2>/dev/null >"$roots_file" | |
sqlite3 --readonly --batch db.sqlite <<EOF | |
CREATE TEMPORARY TABLE roots (path TEXT); | |
.mode csv | |
.import $roots_file roots | |
WITH RECURSIVE closure(id) AS MATERIALIZED ( | |
SELECT id | |
FROM roots | |
JOIN ValidPaths USING (path) | |
UNION | |
SELECT ValidPaths.id | |
FROM Refs | |
JOIN ValidPaths ON (reference = ValidPaths.id) | |
WHERE referrer = id | |
) | |
SELECT path | |
FROM closure | |
JOIN ValidPaths USING (id); | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment