mirror of
https://github.com/nix-community/nix-direnv.git
synced 2025-11-08 19:46:11 +01:00
use_flake: add gcroot for inputs
This commit is contained in:
parent
24f58e2ed7
commit
e19d62fc02
2 changed files with 9 additions and 1 deletions
|
|
@ -134,11 +134,13 @@ $ echo "use nix" >> .envrc
|
||||||
$ direnv allow
|
$ direnv allow
|
||||||
```
|
```
|
||||||
|
|
||||||
## Experimental flakes support
|
## Flakes support
|
||||||
|
|
||||||
nix-direnv also comes with a flake alternative. The code is tested and works however
|
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
|
since future nix versions might change their api regarding this feature we cannot
|
||||||
guarantee stability after an nix upgrade.
|
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`:
|
Save this file as `flake.nix`:
|
||||||
|
|
||||||
|
|
|
||||||
6
direnvrc
6
direnvrc
|
|
@ -55,6 +55,7 @@ use_flake() {
|
||||||
watch_file flake.lock
|
watch_file flake.lock
|
||||||
|
|
||||||
local profile="$(direnv_layout_dir)/flake-profile"
|
local profile="$(direnv_layout_dir)/flake-profile"
|
||||||
|
local flake="$(direnv_layout_dir)/flake"
|
||||||
local profile_rc="${profile}.rc"
|
local profile_rc="${profile}.rc"
|
||||||
|
|
||||||
if [[ ! -e "$profile"
|
if [[ ! -e "$profile"
|
||||||
|
|
@ -72,6 +73,11 @@ use_flake() {
|
||||||
echo "$tmp_profile_rc" > "$profile_rc"
|
echo "$tmp_profile_rc" > "$profile_rc"
|
||||||
rm -f "$tmp_profile" "$tmp_profile"*
|
rm -f "$tmp_profile" "$tmp_profile"*
|
||||||
_nix_add_gcroot "$drv" "$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
|
log_status renewed cache
|
||||||
else
|
else
|
||||||
log_status using cached dev shell
|
log_status using cached dev shell
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue