diff --git a/home-modules/common.nix b/home-modules/common.nix index 0a6e8d0..6b4d19a 100644 --- a/home-modules/common.nix +++ b/home-modules/common.nix @@ -28,6 +28,23 @@ mkMerge [ direnv = { enable = mkDefault true; nix-direnv.enable = true; + stdlib = + '' + # addition to nix-direnv's use_nix that registers outputs as gc roots (as well as the .drv) + use_nix_outputs() { + local layout_dir drv deps + layout_dir="$(direnv_layout_dir)" + drv="$layout_dir/drv" + deps="$layout_dir/deps" + + if [ ! -e "$deps" ] || (( "$(stat --format=%Z "$drv")" > "$(stat --format=%Z "$deps")" )); then + rm -rf "$deps" + mkdir -p "$deps" + nix-store --indirect --add-root "$deps/out" --realise $(nix-store --query --references "$drv") > /dev/null + log_status renewed outputs gc roots + fi + } + ''; }; htop = {