What is the purpose of nix-instantiate? What is a store-derivation?

牧云@^-^@ 提交于 2019-11-30 12:12:26

What is nix-instantiate good for ?

The command nix-instantiate sole purpose is to evaluate Nix expressions. The primary purpose of the Nix languages is to generate derivations.

What is a store-derivation?

A derivation (see example) is a computer-friendly representation of the build recipes used for building (realize) packages. They are files with the extension .drv which are listed in the store directory, usually /nix/store.

These build recipes are understood by the Nix daemon, and are used to ensure that all the dependencies are built before, and stored in the pre-computed paths. Once all dependencies are successfully compiled, then the Nix daemon can look for substitute, or realize the derivation locally. All the detailed explanation is available in Eelco Dolstra PhD Thesis.

These files are created each time the nix-instantiate command evaluates the derivation function of the Nix language, unless the --eval command line option is provided.

Why one would generate store derivations using nix-instantiate ?

If you are interested in the build output, you should prefer nix-build, which is equivalent to:

$ nix-store -r $(nix-instantiate '<nixpkgs>' -A hello)

In some cases you are not interested in the build results, but in looking at the compilation time dependencies. For example, if you want you to investigate the build time dependencies of hello. Then using the nix-store command as follow, you can request all the dependencies of the build recipe:

$ nix-store --tree -q $(nix-instantiate '<nixpkgs>' -A hello)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!