title: How to find a derivation path in the store, starting from the compiled package path?
body: <p>I'm using Nix 2.2.1, in particular <a href="https://hub.docker.com/r/nixos/nix" rel="noreferrer">this</a> NixOS Docker image.</p>
  
  <p>I install Vim like this:</p>
  
  <pre><code># nix-env --install --file '&lt;nixpkgs&gt;' vim
  </code></pre>
  
  <p>The store path of the Vim executable is</p>
  
  <pre><code># readlink -f $(which vim)
  /nix/store/8ayymgnlv77p0h8skf294323maabwq91-vim-8.1.0675/bin/vim
  </code></pre>
  
  <p>Now I want to find out the derivation path in the store from the compiled package path. </p>
  
  <p>I tried this command</p>
  
  <pre><code># nix-store --query --deriver $(readlink -f $(which vim))
  /nix/store/q5zqdr193d8k5w91lb9wqr1wk3418zix-vim-8.1.0675.drv
  </code></pre>
  
  <p>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.</p>
  
  <p>I also tried this:</p>
  
  <pre><code># nix-env --query --drv-path --file '&lt;nixpkgs&gt;' vim
  </code></pre>
  
  <p>But it doesn't give a useful result:</p>
  
  <pre><code>vim-8.1.0675  -
  </code></pre>
  
  <p>Am I using the wrong commands, or is this a bug?</p>