FAQ: Difference between revisions

imported>Samueldr
m Why not use nix-env -i foo?: Use the new page
imported>Samueldr
Line 7: Line 7:
Mainly because Nix is intended to be lightweight, easy to learn and portable (zero dependencies). Since 24. April 2017 thanks to [https://github.com/shlevy Shea Levy] and the [https://www.gofundme.com/htuafwrg/ crowdfunding of 54 community members], nix does not have Perl as dependency anymore.
Mainly because Nix is intended to be lightweight, easy to learn and portable (zero dependencies). Since 24. April 2017 thanks to [https://github.com/shlevy Shea Levy] and the [https://www.gofundme.com/htuafwrg/ crowdfunding of 54 community members], nix does not have Perl as dependency anymore.


== I installed a library but my compiler is not finding it. Why? ==
{{:FAQ/Libraries}}
 
With nix, only ''applications'' should be installed into profiles. Libraries are used using nix-shell. If you want to compile a piece of software that requires zlib and uses pkg-config to discover it, run <code>nix-shell -p gcc pkgconfig zlib</code> to get into a shell with the appropriate environment variables set. In there, a configure script will work as expected.
 
This applies to other language environments too. In some cases the expressions to use are a bit different, e.g. because the interpreter needs to be wrapped to have some additional environment variables passed to it. The manual has [https://nixos.org/nixpkgs/manual/#chap-language-support a section] on the subject.
 
If you have a lot of dependencies, you may want to write a nix expression that includes your dependencies so that you can simply use <code>nix-shell</code> rather than writing out each dependency every time or keeping your development environment in your shell history. A minimal example looks like this:
 
<syntaxhighlight lang="nix"># default.nix
with import <nixpkgs> {};
stdenv.mkDerivation {
    name = "dev-environment"; # Probably put a more meaningful name here
    buildInputs = [ pkgconfig zlib ];
}</syntaxhighlight>
=== Why does it work like that? ===
 
This helps ensure purity of builds: on other distributions, the result of building a piece of software may depend on which other software you have installed. Nix attempts to avoid this to the greatest degree possible, which allows builds of a piece of software to be identical (in the ideal case) no matter where they're built, by requiring all dependencies to be declared.
 
{{:FAQ/nix-env -iA}}
{{:FAQ/nix-env -iA}}