# Executable & symlink behave differently

**URL:** https://discourse.nixos.org/t/executable-symlink-behave-differently/36939
**Category:** Help
**Created:** [December 16, 2023, 5:27am UTC](https://discourse.nixos.org/t/executable-symlink-behave-differently/36939 "2023-12-16T05:27:59Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mcint](https://discourse.nixos.org/user_avatar/discourse.nixos.org/mcint/32/35417_2.png) [@mcint](https://discourse.nixos.org/u/mcint)
#### Post date: [December 16, 2023, 5:27am UTC](https://discourse.nixos.org/t/executable-symlink-behave-differently/36939/1 "2023-12-16T05:27:59Z")

</div>

### Problem as encountered

I use `z` as an intregral part of my workflow, specifically [`z.lua`](https://github.com/skywind3000/z.lua), in general, an alternative `cd` with long history and expressive matching & ranking with ‘frecency’. Installed [from nixpkgs](https://search.nixos.org/packages?channel=23.11&show=z-lua&from=0&size=50&sort=relevance&type=packages&query=z-lua).

My tools are not behaving, _this will be a learning experience_.

Normal usage (`z.lua` symlinked as `z`):

> ```auto
> $ z -l | wc -l
> -bash: /nix/store/03j6z2lbbqv85ajrd1ckbcbns378z6p9-lua-5.2.4/bin/lua: No such file or directory
> 0
> 
> ```

z fails.

> ```auto
> $ z.lua -l | wc -l
> 161
> 
> ```

z.lua succeeds.

They point to the same executable. `z` is a symlink in the `z-lua` package to the `z.lua` executable.

```bash
~$ realpath `which z z.lua`
/nix/store/q1lf50syn97bjvb96v30fm0bd2s9sdv8-z-lua-1.8.16/bin/z.lua
/nix/store/q1lf50syn97bjvb96v30fm0bd2s9sdv8-z-lua-1.8.16/bin/z.lua

```

Invoked as `z.lua` it can read & print history, and echo usage, but cannot do it’s primary function of changing directory, to a hinted location.

### Conclusions

I think I have a few conclusions.

1. I need to fix the dependency specification for this package (aforementioned _learning_)
2. I’m curious why invocation as `z.lua` fails to trigger an error, but it seems neigh certain this is a quirk of lua, not nix.

This post may just be a log of my learnings & thinking aloud.

* * *

##### Debugging note:

- Bash has not cached path, this fails in new shells too, `hash -l z z.lua` returns nothing.

#### Curiosity

I do have 5 distinct version of lua-5.2.4 installed, with differing binaries, shared library file, and pkgconfigs — though pkgconfig differences are only due to differing paths, and the included header files are identical.

Arrived at with lots of fun of chained fd, xargs, md5sum, sort, awk (attempted), & ulitmately [pyp / pypyp](https://pypi.org/projects/pypyp).

---

<div class="post-metadata">

### Author: ![\_Andrew](https://discourse.nixos.org/user_avatar/discourse.nixos.org/_andrew/32/10331_2.png) [@\_Andrew](https://discourse.nixos.org/u/_Andrew)
#### Post date: [December 16, 2023, 10:09pm UTC](https://discourse.nixos.org/t/executable-symlink-behave-differently/36939/2 "2023-12-16T22:09:44Z")

</div>

In your shell is `z` the alias created by [`--init`](https://github.com/skywind3000/z.lua/tree/1.8.16#install) or is it the [backwards compatibility symlink](https://github.com/NixOS/nixpkgs/blob/a8e36c7201d4e4b477eadb9e47d25dae5b06dcd4/pkgs/tools/misc/z-lua/default.nix#L25-L26)?

```plaintext
$ type z
z is /nix/store/q1w4xgww2hw5f15cwxsr506z2n2yp5as-z-lua-1.8.16/bin/z
$ eval "$(z.lua --init bash)"
$ type z
z is aliased to `_zlua'

```

Only the function `_zlua` is capable of changing the shell’s working directory.

---

<div class="post-metadata">

### Author: ![mcint](https://discourse.nixos.org/user_avatar/discourse.nixos.org/mcint/32/35417_2.png) [@mcint](https://discourse.nixos.org/u/mcint)
#### Post date: [December 19, 2023, 8:24pm UTC](https://discourse.nixos.org/t/executable-symlink-behave-differently/36939/3 "2023-12-19T20:24:42Z")

</div>

Good answer, thank you. In my shell, both are defined, so `z` as alias takes priority.

I snapshot `$(z.lua --init bash)` to a file, which appears to be my problem. I think I did this to reduce shell startup time—looks like 15ms to 3ms, under no load, but things add up. My old alias was calling the old version. Don’t understand why, but invoking them, `z` and `z.lua` directly, still reports lua version error.

It looks like I can’t use `bkt --modtime <file> -- z --init bash` to cache the value until `z` is updated, modification times are not valid in the nix store.

---

<div class="post-metadata">

### Author: ![mcint](https://discourse.nixos.org/user_avatar/discourse.nixos.org/mcint/32/35417_2.png) [@mcint](https://discourse.nixos.org/u/mcint)
#### Post date: [December 19, 2023, 10:21pm UTC](https://discourse.nixos.org/t/executable-symlink-behave-differently/36939/4 "2023-12-19T22:21:18Z")

</div>

I can’t quite think through all of what’s happening here.

I think I should make a flake that depends on z-lua, to do the caching I want (or upstream it) and bump the version manually (or do some version following / pass-through?). It’s too frustrating to juggle these pieces, remember them on upgrades.

### Relevant pieces

| component | path | contribution / role |
| --- | --- | --- |
| fs | /nix/store/{…} | flakes & profiles |
| fs home | .nix-profile | current profile |
| tmux env (g) | `tmux show-env -g` | carrying PROMPT\_COMMAND to new shells |
| `z --init bash` | \> `z-init.snapshot.bash` | cache/snapshot of init, 15ms-\>3ms, unloaded system |
| in `.bashrc` | `. [snapshot]` | load snapshot |
