mirror of
https://github.com/nix-community/nix-direnv.git
synced 2025-11-08 19:46:11 +01:00
Merge branch 'master' into no-grep
This commit is contained in:
commit
c33cad83f8
3 changed files with 40 additions and 17 deletions
|
|
@ -314,23 +314,23 @@ when deciding to update its cache.
|
|||
* `flake.lock`
|
||||
* `devshell.toml` if it exists
|
||||
|
||||
To add more files to be checked use `nix_direnv_watch_file` like this
|
||||
To add more files to be checked use `watch_file` like this
|
||||
|
||||
```shell
|
||||
nix_direnv_watch_file your-file.nix
|
||||
watch_file your-file.nix
|
||||
use nix # or use flake
|
||||
```
|
||||
|
||||
Or - if you don't mind the overhead (runtime and conceptual) of watching all nix-files:
|
||||
|
||||
```shell
|
||||
nix_direnv_watch_file $(find . -name "*.nix" -printf '"%p" ')
|
||||
watch_file $(find . -name "*.nix" -printf '"%p" ')
|
||||
```
|
||||
|
||||
Note that this will re-execute direnv for any nix change,
|
||||
regardless of whether that change is meaningful for the devShell in use.
|
||||
|
||||
`nix_direnv_watch_file` must be invoked before either `use flake` or `use nix` to take effect.
|
||||
`watch_file` must be invoked before either `use flake` or `use nix` to take effect.
|
||||
|
||||
## General direnv tips
|
||||
|
||||
|
|
|
|||
43
direnvrc
43
direnvrc
|
|
@ -139,7 +139,7 @@ _nix_import_env() {
|
|||
|
||||
eval "$(< "$profile_rc")"
|
||||
# `nix print-dev-env` will create a temporary directory and use it as TMPDIR
|
||||
# We cannot rely on this directory being availble at all times,
|
||||
# We cannot rely on this directory being available at all times,
|
||||
# as it may be garbage collected.
|
||||
# Instead - just remove it immediately.
|
||||
# Use recursive & force as it may not be empty.
|
||||
|
|
@ -188,7 +188,7 @@ _nix_argsum_suffix() {
|
|||
elif has shasum; then
|
||||
out=$(shasum <<< "$1")
|
||||
else
|
||||
# degrate gracefully both tools are not present
|
||||
# degrade gracefully both tools are not present
|
||||
return
|
||||
fi
|
||||
read -r checksum _ <<< "$out"
|
||||
|
|
@ -197,8 +197,29 @@ _nix_argsum_suffix() {
|
|||
}
|
||||
|
||||
nix_direnv_watch_file() {
|
||||
# shellcheck disable=2016
|
||||
log_error '`nix_direnv_watch_file` is deprecated - use `watch_file`'
|
||||
watch_file "$@"
|
||||
nix_watches+=("$@")
|
||||
}
|
||||
|
||||
_nix_direnv_watches() {
|
||||
local -n _watches=$1
|
||||
if [[ -z "${DIRENV_WATCHES-}" ]]; then
|
||||
return
|
||||
fi
|
||||
while IFS= read -r line; do
|
||||
local regex='"path": "(.+)"$'
|
||||
if [[ "$line" =~ $regex ]]; then
|
||||
local path="${BASH_REMATCH[1]}"
|
||||
if [[ "$path" == "${XDG_DATA_HOME:-${HOME:-/var/empty}/.local/share}/direnv/allow/"* ]]; then
|
||||
continue
|
||||
fi
|
||||
# expand new lines and other json escapes
|
||||
# shellcheck disable=2059
|
||||
path=$(printf "$path")
|
||||
_watches+=("$path")
|
||||
fi
|
||||
done < <(direnv show_dump "${DIRENV_WATCHES}")
|
||||
}
|
||||
|
||||
_nix_direnv_manual_reload=0
|
||||
|
|
@ -206,7 +227,6 @@ nix_direnv_manual_reload() {
|
|||
_nix_direnv_manual_reload=1
|
||||
}
|
||||
|
||||
|
||||
use_flake() {
|
||||
_nix_direnv_preflight
|
||||
|
||||
|
|
@ -229,7 +249,7 @@ use_flake() {
|
|||
files_to_watch+=("$flake_dir/flake.nix" "$flake_dir/flake.lock" "$flake_dir/devshell.toml")
|
||||
fi
|
||||
|
||||
nix_direnv_watch_file "${files_to_watch[@]}"
|
||||
watch_file "${files_to_watch[@]}"
|
||||
|
||||
local layout_dir profile
|
||||
layout_dir=$(direnv_layout_dir)
|
||||
|
|
@ -238,8 +258,10 @@ use_flake() {
|
|||
local flake_inputs="${layout_dir}/flake-inputs/"
|
||||
|
||||
local need_update=0
|
||||
local watches
|
||||
_nix_direnv_watches watches
|
||||
local file=
|
||||
for file in "${nix_watches[@]}"; do
|
||||
for file in "${watches[@]}"; do
|
||||
if [[ "$file" -nt "$profile_rc" ]]; then
|
||||
need_update=1
|
||||
break
|
||||
|
|
@ -390,11 +412,13 @@ use_nix() {
|
|||
esac
|
||||
done
|
||||
|
||||
nix_direnv_watch_file "$HOME/.direnvrc" "$HOME/.config/direnv/direnvrc" ".envrc" "shell.nix" "default.nix"
|
||||
watch_file "$HOME/.direnvrc" "$HOME/.config/direnv/direnvrc" ".envrc" "shell.nix" "default.nix"
|
||||
|
||||
local need_update=0
|
||||
local watches
|
||||
_nix_direnv_watches watches
|
||||
local file=
|
||||
for file in "${nix_watches[@]}"; do
|
||||
for file in "${watches[@]}"; do
|
||||
if [[ "$file" -nt "$profile_rc" ]]; then
|
||||
need_update=1
|
||||
break
|
||||
|
|
@ -452,7 +476,6 @@ use_nix() {
|
|||
|
||||
|
||||
if [[ "$#" == 0 ]]; then
|
||||
watch_file default.nix
|
||||
watch_file shell.nix
|
||||
watch_file default.nix shell.nix
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
6
flake.lock
generated
6
flake.lock
generated
|
|
@ -20,11 +20,11 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1700416016,
|
||||
"narHash": "sha256-Qp8Of0BUYGjqodmE912h+/uGknB7J11ypcQMKnEDUrg=",
|
||||
"lastModified": 1700538105,
|
||||
"narHash": "sha256-uZhOCmwv8VupEmPZm3erbr9XXmyg7K67Ul3+Rx2XMe0=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "0bf3f5cf6a98b5d077cdcdb00a6d4b3d92bc78b5",
|
||||
"rev": "51a01a7e5515b469886c120e38db325c96694c2f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue