nix_version=2.3.3
nix_openpgp=B541D55301270E0BCF15CA5D8170B4726D7198DE
nixpkgs_channel=nixos-unstable-small
-nixshell_sources=(.envrc shell.nix overlays.nix
- .config/nixpkgs-channel/"$nixpkgs_channel".nix
+nixshell_sources=".envrc shell.nix overlays.nix
+ .config/nixpkgs-channel/$nixpkgs_channel.nix
$(for d in patches shell overlays; do
test ! -d "$d" || find "$d" -type f -not -name "*~"
done | sort
)
-)
+"
# nix
if ! has nix || test "$(nix --version)" != "nix (Nix) $nix_version"
then log_status "installing Nix core tools"
- gpg2 --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys "$nix_openpgp"
+ gpg2 --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys "$nix_openpgp"
mkdir -p .config/nix/"$nix_version"
{
flock --exclusive 3
# nix-shell
has shasum || { log_error "shasum is needed to cache environment"; return 1; }
-for e in "${nixshell_sources[@]}"
-do watch_file "$e"; done
-hash=$(shasum -a 256 "${nixshell_sources[@]}" | shasum -a 256 | cut -c -64)
+for src in $nixshell_sources
+do watch_file "$src"; done
+hash=$(shasum -a 256 $nixshell_sources | shasum -a 256 | cut -c -64)
cache=.cache/nix-shell/"$hash"
unset DIRENV_DUMP_FILE_PATH
if test -e "$cache/dump"
log_status "reusing $cache/"
{
flock --shared 3
+ direnv_watches=$DIRENV_WATCHES
# Load the cached environment
direnv_load sh -c "cat >\$DIRENV_DUMP_FILE_PATH $cache/dump"
+ # Restore DIRENV_WATCHES to prevent infinite reload
+ # when a watched file is touched without being modified
+ # and thus without changing $hash.
+ DIRENV_WATCHES=$direnv_watches
+ #{ printf "\x1f\x8b\x08\x00\x00\x00\x00\x00"; echo $DIRENV_WATCHES | tr _- /+ | base64 -d; } | gzip -dc
# Re-run the shellHook to update envvars like GPG_TTY,
# and run gpg-connect-agent updatestartuptty /bye
eval "$shellHook"
- } 3<$cache/dump
+ } 3<"$cache"/dump
else
log_status "building $cache/"
mkdir -p "$cache"
${TRACE:+--show-trace} \
${OFFLINE:+--option substituters ""} &&
nix-store >/dev/null --indirect --add-root "$cache"/shell.dep \
- --realise $(nix-store --query --references $cache/shell.drv) \
+ --realise $(nix-store --query --references "$cache"/shell.drv) \
${OFFLINE:+--option substituters ""} &&
direnv_load sh -c "nix-shell ${TRACE:+--show-trace} \
--run \"DIRENV_DUMP_FILE_PATH= $direnv dump | tee $cache/dump >\$DIRENV_DUMP_FILE_PATH\" \
log_error "cannot build shell.nix"
return 1
}
- } 3>$cache/dump
+ } 3>"$cache"/dump
fi