Get path to dependent library in nix store

Hi.

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/vte.sh 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/vte.sh"
if [ -r "$vte" ]; then
    TERM=xterm source "$vte"
fi

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
"/nix/store/2r8kr671cll3ykdj90vgpbp3lxnn7jzz-vte-0.58.2"

edit:

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
/nix/store/1gr6419lkv34k91brqwgil286v8b7mdx-vte-ng-0.54.2.a

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
/nix/store/2r8kr671cll3ykdj90vgpbp3lxnn7jzz-vte-0.58.2

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/vte.sh"

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 'https://nixos.org/channels/nixos/nixexprs.tar.xz': 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/vte.sh" = {
    source = pkgs.writeScript "vte.sh" ''
      vte="${pkgs.termite.vte-ng}/etc/profile.d/vte.sh"
      if [ -r "$vte" ]; then
          TERM=xterm source "$vte"
      fi
    '';
  };
};

or better

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

or do what vte module does:

https://github.com/NixOS/nixpkgs/blob/ea38cf9d964900e7ecf395331122a222553ff835/nixos/modules/config/vte.nix#L48-L54

3 Likes

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.