11

I'm using Nix 2.2.1, in particular this NixOS Docker image.

I install Vim like this:

# nix-env --install --file '<nixpkgs>' vim

The store path of the Vim executable is

# readlink -f $(which vim)
/nix/store/8ayymgnlv77p0h8skf294323maabwq91-vim-8.1.0675/bin/vim

Now I want to find out the derivation path in the store from the compiled package path.

I tried this command

# nix-store --query --deriver $(readlink -f $(which vim))
/nix/store/q5zqdr193d8k5w91lb9wqr1wk3418zix-vim-8.1.0675.drv

This did return a path in the store but, to my surprise, the path didn't exist! There is a derivation for vim in the store, but it doesn't match the output of the command.

I also tried this:

# nix-env --query --drv-path --file '<nixpkgs>' vim

But it doesn't give a useful result:

vim-8.1.0675  -

Am I using the wrong commands, or is this a bug?

danidiaz
  • 26,936
  • 4
  • 45
  • 95
  • I think you probably found the right derivation path, but it doesn't exist because Nix never needed it to exist. What kind of answer are you looking for? Do you need the derivation to exist on your system in order to an accept an answer to this question? – David Grayson Jun 17 '19 at 23:44
  • @DavidGrayson I was trying to understand how things work, so an explanation of why the derivation doesn't need to exist would be fine. – danidiaz Jun 18 '19 at 06:19

1 Answers1

2

Your nix-store invocation looks ok.

Derivation files may be garbage collected, unless you set keep-derivations = true in nix.conf or nix.extraOptions in NixOS. This may explain the situation.

Robert Hensing
  • 6,708
  • 18
  • 23
  • I tried that, but it doesn't seem to work. Perhaps there's something wrong with my Nix installation; the problem happens with other packages as well. – danidiaz Jun 17 '19 at 21:00
  • 1
    You may also try [keep-env-derivations](https://nixos.org/nix/manual/#conf-keep-env-derivations) which seems to be `nix-env`-specific. I must admit I don't normally use `nix-env` because if prefer more declarative approaches like NixOS and home-manager. – Robert Hensing Jun 18 '19 at 12:22