From 99f8695df2ab2944b099181d7d0c0ac3a03302b0 Mon Sep 17 00:00:00 2001 From: Jack O'Sullivan Date: Tue, 15 Feb 2022 02:24:16 +0000 Subject: [PATCH] home-modules/common: Add direnv `use_nix_outputs` --- home-modules/common.nix | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 = {