From 89f8666e2c3d00c6ae8022ec8f8e10e4c691fd61 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Sat, 5 Aug 2023 15:26:53 -0600 Subject: [PATCH] [NixOS] Add function to find gc roots for a store path --- dotfiles/lib/functions/find_store_path_gc_roots | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 dotfiles/lib/functions/find_store_path_gc_roots diff --git a/dotfiles/lib/functions/find_store_path_gc_roots b/dotfiles/lib/functions/find_store_path_gc_roots new file mode 100755 index 00000000..ca71f80c --- /dev/null +++ b/dotfiles/lib/functions/find_store_path_gc_roots @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +function find_store_path_gc_roots { + store_path="$(realpath $1)" + while IFS=' ' read -r gcroot derivation; do + if [[ ! $gcroot =~ ^/proc ]]; then + if nix-store -qR "$derivation" 2>/dev/null | grep -q "$store_path"; then + echo $gcroot + fi + fi + done < <(nix-store --gc --print-roots | awk '{print $1, $3}') +} + + +find_store_path_gc_roots "$@"