Merge branch 'master' into no-grep

This commit is contained in:
mergify[bot] 2023-11-26 13:29:01 +00:00 committed by GitHub
commit c33cad83f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 17 deletions

View file

@ -314,23 +314,23 @@ when deciding to update its cache.
* `flake.lock` * `flake.lock`
* `devshell.toml` if it exists * `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 ```shell
nix_direnv_watch_file your-file.nix watch_file your-file.nix
use nix # or use flake use nix # or use flake
``` ```
Or - if you don't mind the overhead (runtime and conceptual) of watching all nix-files: Or - if you don't mind the overhead (runtime and conceptual) of watching all nix-files:
```shell ```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, Note that this will re-execute direnv for any nix change,
regardless of whether that change is meaningful for the devShell in use. 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 ## General direnv tips

View file

@ -139,7 +139,7 @@ _nix_import_env() {
eval "$(< "$profile_rc")" eval "$(< "$profile_rc")"
# `nix print-dev-env` will create a temporary directory and use it as TMPDIR # `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. # as it may be garbage collected.
# Instead - just remove it immediately. # Instead - just remove it immediately.
# Use recursive & force as it may not be empty. # Use recursive & force as it may not be empty.
@ -188,7 +188,7 @@ _nix_argsum_suffix() {
elif has shasum; then elif has shasum; then
out=$(shasum <<< "$1") out=$(shasum <<< "$1")
else else
# degrate gracefully both tools are not present # degrade gracefully both tools are not present
return return
fi fi
read -r checksum _ <<< "$out" read -r checksum _ <<< "$out"
@ -197,8 +197,29 @@ _nix_argsum_suffix() {
} }
nix_direnv_watch_file() { nix_direnv_watch_file() {
# shellcheck disable=2016
log_error '`nix_direnv_watch_file` is deprecated - use `watch_file`'
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 _nix_direnv_manual_reload=0
@ -206,7 +227,6 @@ nix_direnv_manual_reload() {
_nix_direnv_manual_reload=1 _nix_direnv_manual_reload=1
} }
use_flake() { use_flake() {
_nix_direnv_preflight _nix_direnv_preflight
@ -229,7 +249,7 @@ use_flake() {
files_to_watch+=("$flake_dir/flake.nix" "$flake_dir/flake.lock" "$flake_dir/devshell.toml") files_to_watch+=("$flake_dir/flake.nix" "$flake_dir/flake.lock" "$flake_dir/devshell.toml")
fi fi
nix_direnv_watch_file "${files_to_watch[@]}" watch_file "${files_to_watch[@]}"
local layout_dir profile local layout_dir profile
layout_dir=$(direnv_layout_dir) layout_dir=$(direnv_layout_dir)
@ -238,8 +258,10 @@ use_flake() {
local flake_inputs="${layout_dir}/flake-inputs/" local flake_inputs="${layout_dir}/flake-inputs/"
local need_update=0 local need_update=0
local watches
_nix_direnv_watches watches
local file= local file=
for file in "${nix_watches[@]}"; do for file in "${watches[@]}"; do
if [[ "$file" -nt "$profile_rc" ]]; then if [[ "$file" -nt "$profile_rc" ]]; then
need_update=1 need_update=1
break break
@ -390,11 +412,13 @@ use_nix() {
esac esac
done 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 need_update=0
local watches
_nix_direnv_watches watches
local file= local file=
for file in "${nix_watches[@]}"; do for file in "${watches[@]}"; do
if [[ "$file" -nt "$profile_rc" ]]; then if [[ "$file" -nt "$profile_rc" ]]; then
need_update=1 need_update=1
break break
@ -452,7 +476,6 @@ use_nix() {
if [[ "$#" == 0 ]]; then if [[ "$#" == 0 ]]; then
watch_file default.nix watch_file default.nix shell.nix
watch_file shell.nix
fi fi
} }

6
flake.lock generated
View file

@ -20,11 +20,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1700416016, "lastModified": 1700538105,
"narHash": "sha256-Qp8Of0BUYGjqodmE912h+/uGknB7J11ypcQMKnEDUrg=", "narHash": "sha256-uZhOCmwv8VupEmPZm3erbr9XXmyg7K67Ul3+Rx2XMe0=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "0bf3f5cf6a98b5d077cdcdb00a6d4b3d92bc78b5", "rev": "51a01a7e5515b469886c120e38db325c96694c2f",
"type": "github" "type": "github"
}, },
"original": { "original": {