Get path to dependent library in nix store


I am using termite as my terminal emulator. The termite packages depends on vte-ng, which is a derivation of vte with some additional patches.

Now, I want to source the etc/profile.d/ script from within my shell’s init file.

Before upgrading to NixOS 20.03, I did it this way:

vte="$( nix eval -f channel:nixos '(with (import <nixpkgs> {}); builtins.toPath vte-ng)' --raw )/etc/profile.d/"
if [ -r "$vte" ]; then
    TERM=xterm source "$vte"

This is no longer working since vte-ng has been integrated into the termite build and is not available as a separate package (I suppose).

Currently, the path to vte-ng into the nix store is /nix/store/1gr6419lkv34k91brqwgil286v8b7mdx-vte-ng-0.54.2.a. But how can I deduce that info automatically?

I inspected the available information using nix repl, but no dice:

nix-repl> :l <nixos>
Added 11493 variables.

nix-repl> pkgs.termite.vte-ng.outPath


Reading through the forum, I discovered a nix-store command which basically does what I am after:

$ nix-store -q --references $(which termite) | grep vte-ng | head

But, that does not seem very elegant. How does the nix-store query work? Is there a better solution? I’d be thankful for any suggestions!

nix eval --raw nixos.termite.vte-ng

Thanks, but that does not work. It prints the wrong path:

$ nix eval --raw nixos.termite.vte-ng

which is the same path I got from my interactive nix repl session. This path does not exist on my system – I suppose that is the build input or output directory which is not fetched when installing termite via nix-env.

nix eval only evaluates the expression (attribute), it will not build it. In order for path to be available, you need to realize the derivation e.g. by using nix-build or build some other derivation that depends on it.

vte="$( nix-build channel:nixos -A termite.vte-ng)/etc/profile.d/"

Yes of course, I thought he had installed already by installing the dependent package (termite?)

They could have installed termite from a different channel so using the eval would not be reliable.

mmm… He used to have this in the profile:

so I thought that the termite installed was that of the nixos channel, hence the nix eval --raw nixos...

That results in:

error: unable to download '': HTTP error 404

Using nix-build '<nixpkgs>' -A termite.vte-ng works (ie. it realizes the derivation and prints out the path).

But it is rather slow - takes ~0.6 seconds on each run whereas the nix-store command returns almost immediately (0.03 secs).

I’d go with the nix-store command, but I am still wondering where the difference comes from. :thinking:

I can see the /nix/store/1gr6419lkv34k91brqwgil286v8b7mdx-vte-ng-0.54.2.a path inside the drv file of termite but cannot retrieve it with a nix expression…

Well, the termite derivation came from a different revision of the channel.

Ideally, you would inline the path into the file to shift the cost to building your system. Adding something like the following to your configuration.nix:

environment.etc = {
  "profile.d/" = {
    source = pkgs.writeScript "" ''
      if [ -r "$vte" ]; then
          TERM=xterm source "$vte"

or better

environment.etc = {
  "profile.d/".source = "${pkgs.termite.vte-ng}/etc/profile.d/";

or do what vte module does:


Thank you, that steers me into the right direction…

I ended up adding:

programs.zsh.vteIntegration = true;

to my configuration.nix. But then I noticed that this does not work for me since termite sets TERM=termite and there’s a check for that variable in the sourced script, matching on xterm* | vte*

So, your first suggestion should actually work.