mirror of
https://github.com/nix-community/nix-direnv.git
synced 2025-11-08 19:46:11 +01:00
Merge pull request #87 from martinetd/outoftree_flake
use flake: allow optional flake expression
This commit is contained in:
commit
b45b9dc614
2 changed files with 15 additions and 7 deletions
|
|
@ -168,7 +168,13 @@ $ echo "use flake" >> .envrc
|
|||
$ direnv allow
|
||||
```
|
||||
|
||||
in case the project already comes with a `flake.nix`
|
||||
in case the project already comes with a `flake.nix`.
|
||||
Optionally if you do not want flake.nix to be part of the current directory repo,
|
||||
you can specify an arbitrary flake expression as parameter such as:
|
||||
|
||||
```console
|
||||
use flake ~/myflakes#project
|
||||
```
|
||||
|
||||
## Storing .direnv outside the project directory
|
||||
|
||||
|
|
|
|||
14
direnvrc
14
direnvrc
|
|
@ -87,8 +87,10 @@ _nix_add_gcroot() {
|
|||
}
|
||||
|
||||
use_flake() {
|
||||
watch_file flake.nix
|
||||
watch_file flake.lock
|
||||
flake_expr="${1:-.}"
|
||||
flake_dir="${flake_expr%#*}"
|
||||
watch_file "$flake_dir/"flake.nix
|
||||
watch_file "$flake_dir/"flake.lock
|
||||
|
||||
local layout_dir
|
||||
layout_dir=$(direnv_layout_dir)
|
||||
|
|
@ -100,8 +102,8 @@ use_flake() {
|
|||
|| ! -e "$profile_rc"
|
||||
|| "$HOME/.direnvrc" -nt "$profile_rc"
|
||||
|| .envrc -nt "$profile_rc"
|
||||
|| flake.nix -nt "$profile_rc"
|
||||
|| flake.lock -nt "$profile_rc"
|
||||
|| "$flake_dir/"flake.nix -nt "$profile_rc"
|
||||
|| "$flake_dir/"flake.lock -nt "$profile_rc"
|
||||
]];
|
||||
then
|
||||
local tmp_profile="${layout_dir}/flake-profile.$$"
|
||||
|
|
@ -109,7 +111,7 @@ use_flake() {
|
|||
local tmp_profile_rc
|
||||
tmp_profile_rc=$("${NIX_BIN_PREFIX}nix" print-dev-env \
|
||||
--extra-experimental-features "nix-command flakes" \
|
||||
--profile "$tmp_profile")
|
||||
--profile "$tmp_profile" "$flake_expr")
|
||||
# macos does not have realpath
|
||||
if command -v realpath >/dev/null; then
|
||||
drv=$(realpath "$tmp_profile")
|
||||
|
|
@ -126,7 +128,7 @@ use_flake() {
|
|||
mkdir "$flake_inputs"
|
||||
flake_input_paths=$("${NIX_BIN_PREFIX}nix" flake archive --json \
|
||||
--extra-experimental-features "nix-command flakes" \
|
||||
| grep -E -o '/nix/store/[^"]+')
|
||||
"$flake_dir" | grep -E -o '/nix/store/[^"]+')
|
||||
for path in $flake_input_paths; do
|
||||
_nix_add_gcroot "$path" "${flake_inputs}/${path##*/}"
|
||||
done
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue