use_flake: add gcroot for inputs

This commit is contained in:
Jörg Thalheim 2020-12-25 17:29:44 +01:00
parent 24f58e2ed7
commit e19d62fc02
No known key found for this signature in database
GPG Key ID: 003F2096411B5F92
2 changed files with 9 additions and 1 deletions

View File

@ -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`:

View File

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