diff --git a/README.md b/README.md index 86d1d9e..cc5e76c 100644 --- a/README.md +++ b/README.md @@ -134,11 +134,13 @@ $ echo "use nix" >> .envrc $ direnv allow ``` -## Experimental flakes support +## Flakes support nix-direnv also comes with a flake alternative. The code is tested and works however since future nix versions might change their api regarding this feature we cannot guarantee stability after an nix upgrade. +Likewise `use_nix` the `use_flake` implementation will prevent garbage +collection of downloaded packages and also for flake inputs. Save this file as `flake.nix`: diff --git a/direnvrc b/direnvrc index 59cb14d..8c3055a 100644 --- a/direnvrc +++ b/direnvrc @@ -55,6 +55,7 @@ use_flake() { watch_file flake.lock local profile="$(direnv_layout_dir)/flake-profile" + local flake="$(direnv_layout_dir)/flake" local profile_rc="${profile}.rc" if [[ ! -e "$profile" @@ -72,6 +73,11 @@ use_flake() { echo "$tmp_profile_rc" > "$profile_rc" rm -f "$tmp_profile" "$tmp_profile"* _nix_add_gcroot "$drv" "$profile" + + # also add garbage collection root for source + local flake_source=$(nix eval --impure --raw --expr 'builtins.getFlake (toString ./.)') + _nix_add_gcroot "$flake_source" "$flake" + log_status renewed cache else log_status using cached dev shell