Kakoune cannot run other programs because its PATH is minimal

I’ve noticed that running commands like pbcopy from kakoune stopped working suddenly. I’m not sure if it’s when I upgraded nixpkgs a week ago or when I switched from Homebrew kakoune to Nix’s.

The reason is that the PATH does not contain my PATH, e.g. /usr/bin. If I run nix shell nixpkgs#kakoune and then type !echo $PATH, I get only entries in the Nix store:

/nix/store/4prvdgwxgw4a4f96c183h49qdrvd99z1-kakoune-unwrapped-2024.05.18/bin/../libexec/kak:/nix/store/7k0qi2r54imwjfs2bklg7fv0mn5jglil-coreutils-9.5/bin:/nix/store/y01yv3ylb4zyadnh8cmpv3h8j0vw9slx-findutils-4.10.0/bin:/nix/store/pj9qh3y52knawg34qfnk9nq1kk12lh48-diffutils-3.10/bin:/nix/store/0x1mwb2bl2mjm658kcciwyg7n5avzvfp-gnused-4.9/bin:/nix/store/5g9xsw7dyihfh1kcf73nqqrla3zyy3r0-gnugrep-3.11/bin:/nix/store/ssprxb26mz01akbhlswdb7nbc30iyjjh-gawk-5.2.2/bin:/nix/store/lzndf97akrpmd3vjdq06xzwk8fnjc4j7-gnutar-1.35/bin:/nix/store/ynhzyabgbx6fz49sy944ws9wnskangxc-gzip-1.13/bin:/nix/store/ci1mxirfvn961zh3m4w9mr513ii7s2lz-bzip2-1.0.8-bin/bin:/nix/store/6gylp4vygmsm12rafhzvklrfkbhwwq40-gnumake-4.4.1/bin:/nix/store/fyjay93q3dq2hx3dhx7zhr8kyjnkh9m8-bash-5.2p26/bin:/nix/store/ga67f01j6g0qq7y9flgf3fzr1lbdi58y-patch-2.7.6/bin:/nix/store/6rk472mwpc5zwfhh6siyycl28y2baqrf-xz-5.6.2-bin/bin:/nix/store/apqqsrdg6xsz9icx04siw3l4z9yrxws3-file-5.45/bin:/nix/store/az4w4ccdg4v8vy4fxkblfl3ibh5b0mlw-kakoune-2024.05.18/share/kak/bin

If I run nix run nixpkgs#vim and then get the path from there, this problem does not happen. With the Homebrew kakoune, this problem does not happen.

Is this a bug in the kakoune nixpkgs package (it seems a bit too hermetic :slight_smile: ), or a new Nix feature, or what? I didn’t see anything related-seeming in the history of nixpkgs/pkgs/applications/editors/kakoune/default.nix at cb9a96f23c491c081b38eab96d22fa958043c9fa · NixOS/nixpkgs · GitHub

Is there something that can be done?

Fancy seeing you here!

This was broken by kakoune: create a directory for bins that kakoune needs · NixOS/nixpkgs@e4da18a · GitHub and should be fixed by kakoune: restore the ability to find ambient programs by alois31 · Pull Request #333642 · NixOS/nixpkgs · GitHub.

2 Likes

Hi Emily! Makes sense, glad it’s fixed, thank you very much! I’ll track Nixpkgs PR #333642 ("kakoune: restore the ability to find ambient programs") progress now.

I can’t find any sort of “Marked as Answered” button, but I’m good now :slight_smile: (Update: Found the “Solution” button)

Actually, since I’m here, here’s a vaguely related question:

What is the difference between the “wrapped” kakoune and kakoune-unwrapped? As far as I can tell, the bug never affected the latter.

I’ve seen that many of my Nix programs are installed “wrapped” by default and some also have “unwrapped” versions. I’m not sure what difference that makes in practice.

Wrappers set relevant envvars and CLI args for a program, naturally the unwrapped package would not have PATH pre-set that way.

How important are these envvars and CLI args? Is it completely specific to each package, or are there conventions on what the wrappers tend to do?

In other words, what downsides should I expect to just running the “unwrapped” version?

Yes, some packages don’t have a separate wrapper package either, and just use the wrapper directly in the original expression (see: most electron apps).
Ultimately you’d have to check the code to see what is part of the wrapper and whether you want that behaviour or not.

Generally, wrappers add paths to auxiliary executables, libraries, and data files, as well as setting any other required environment variables. You should expect the experience of an unwrapped binary to vary between “some functionality that uses external executables doesn’t function out of the box” and “won’t even start at all”.

The wrapper, and the unwrapped executable, are basically implementation details; if a wrapper exists, there’s not really any guarantee or support for running the unwrapped executable unless you know what you’re doing. Usually there aren’t bugs quite this bad in them, though!

In the case of Kakoune, however, the wrapper just sets up Nix‐packaged plugins you have opted into using, so unless you use those there should be no downside to using the unwrapped binary. Much of the time (e.g. for all Python, GTK, and Qt apps) the wrappers are more important than that, though. Since Nix uses a weird filesystem layout we are often having to tell applications where they can actually find things. Environment variables aren’t the ideal way to do that – they leak into subprocesses, which can cause issues with Python’s PYTHONPATH, for instance – but they’re often what we have to work with.

1 Like