zimfw / direnv

Sets up the direnv Zsh shell integration
MIT License
1 stars 0 forks source link

direnv-hook-zsh.zsh gets out of date #1

Open antoineco opened 4 hours ago

antoineco commented 4 hours ago

Prerequisites

Bug description

The current logic generates direnv-hook-zsh.zsh once, which does not take possible relocations of the direnv executable into account.

Steps to reproduce

  1. cd ${$(mktemp -d):A} && \
       ZDOTDIR=${PWD} HOME=${PWD} ZIM_HOME=${PWD}/.zim && \
       curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh && \
       exec zsh
  2. Add zmodule direnv to zimrc
  3. Install direnv
  4. Open a new shell
  5. Install direnv to a new location

My particular scenario is a direnv program installed via the Nix package manager using nix profile install 'nixpkgs#direnv' (or declarative equivalent on NixOS). Upon updating the program, its location changes inside the Nix store, and Zim's cached hook file no longer matches the current output of direnv hook zsh:

 _direnv_hook() {
   trap -- '' SIGINT
-  eval "$("/nix/store/bri4plkp5ykp2dvjs1bwzd92z7grp6h7-direnv-2.34.0/bin/direnv" export zsh)"
+  eval "$("/nix/store/3lv7pgadn5b587s69y23lpj90170q0n5-direnv-2.35.0/bin/direnv" export zsh)"
   trap - SIGINT
 }

Current behavior

direnv-hook-zsh.zsh is never updated despite the direnv executable being a newer version installed at a different location on the filesystem.

Expected behavior

direnv-hook-zsh.zsh is updated along with direnv when necessary, e.g. when the location of the current direnv no longer matches the one in the cached hook file).

zimfw info

zimfw version:        1.15.1 (built at 2024-10-10 00:28:19 UTC, previous commit is 331f1c5)
LANG:                 en_US.UTF-8
OSTYPE:               linux-gnu
TERM:                 wezterm
TERM_PROGRAM:         WezTerm
TERM_PROGRAM_VERSION: 20240812-215703-30345b36
ZIM_HOME:             /home/acotten/.zim
ZSH_VERSION:          5.9

Additional context

No response

antoineco commented 3 hours ago

I forgot to mention that the location of direnv in the PATH does not change. It is the target of the symlink which changes:

% echo "${commands[direnv]}"
/etc/profiles/per-user/acotten/bin/direnv
% ls -l "${commands[direnv]}"
lrwxrwxrwx 1 root root 68 Jan  1  1970 /etc/profiles/per-user/acotten/bin/direnv -> /nix/store/3lv7pgadn5b587s69y23lpj90170q0n5-direnv-2.35.0/bin/direnv

It seems like the 0 timestamps used across the Nix store are tripping the current -nt conditional expression: https://github.com/zimfw/direnv/blob/8d395e563315b0193f375f2a83d27d93b249a5ea/init.zsh#L5

% stat /nix/store/3lv7pgadn5b587s69y23lpj90170q0n5-direnv-2.35.0/bin/direnv
  File: /nix/store/3lv7pgadn5b587s69y23lpj90170q0n5-direnv-2.35.0/bin/direnv
  Size: 8284784         Blocks: 16184      IO Block: 4096   regular file
Device: 8,32    Inode: 2533042     Links: 1
Access: (0555/-r-xr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2024-11-16 11:05:11.000000000 +0000
Modify: 1970-01-01 00:00:01.000000000 +0000
Change: 2024-11-16 11:05:11.396581001 +0000
 Birth: 2024-11-16 11:05:11.077581001 +0000

This makes me wonder whether this issue can actually be addressed when using Nix.