Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

nix

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?

like image 672
danidiaz Avatar asked Jun 16 '19 22:06

danidiaz


People also ask

What is a derivation Nixos?

Derivations are the building blocks of a Nix system, from a file system view point. The Nix language is used to describe such derivations.

What is Nix store?

Nix stores all packages into a common place called the Nix store, usually located at /nix/store . Each package is stored in a unique subdirectory in the store, and each package has its own tree structure. For example, a SimGrid package might be stored in /nix/store/l5rah62vpsr3ap63xmk197y0s1l6g2zx-simgrid-3.22.

What is Nix build?

nix-build is essentially a wrapper around nix-instantiate (to translate a high-level Nix expression to a low-level store derivation) and nix-store --realise (to build the store derivation). Warning. The result of the build is automatically registered as a root of the Nix garbage collector.

What is Nix language?

The Nix Expression Language is a dynamic, functional and lazy domain-specific language used to instruct Nix how to build packages. Benefits of Nix programming language are reproducibility, binary caching, multiple versions, distributed and non-privileged builds.


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.

like image 107
Robert Hensing Avatar answered Sep 20 '22 07:09

Robert Hensing