How to find a derivation path in the store, starting from the compiled package path?

Viewed 1642

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?

1 Answers

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.

Related