home-modules/common: Add direnv use_nix_outputs

This commit is contained in:
Jack O'Sullivan 2022-02-15 02:24:16 +00:00
parent 59d1b5bcd7
commit 99f8695df2

View File

@ -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 = {