Nix (package manager): Difference between revisions

imported>Fricklerhandwerk
m Fricklerhandwerk moved page Nix to Nix package manager: always use the full name for clarity
imported>Raphi
Update commands and sandboxing defaults
Line 10: Line 10:
=== Nix commands ===
=== Nix commands ===


Since nix 2.0 there is a new style of commands. Those are not documented in the official manual.
Since nix 2.0 there is a new style of commands. Those are [https://nixos.org/manual/nix/stable/command-ref/experimental-commands.html documented in the official manual].
See [[Nix command]] for an exhaustive guide.
See [[Nix command]] for additional information.


=== Declarative Configuration ===
=== Declarative Configuration ===
Line 23: Line 23:
=== Imperative Operations ===
=== Imperative Operations ===


To a large extent, package and environment management in Nix is imperative; user environments - including package installation and removal - is managed with the <code>nix-env</code> command, while <code>nix-channels</code> determine which version of [Nixpkgs] is used, and thus which version your packages will have.
To a large extent, package and environment management in Nix is imperative; user environments - including package installation and removal - is managed with the <code>nix-env</code> command, while <code>nix-channels</code> determine which version of [[Nixpkgs]] is used, and thus which version your packages will have.


====  User Environments ====
====  User Environments ====
Line 33: Line 33:
|-
|-
|Searching for packages
|Searching for packages
|<code>nix search packagename</code>
|<code>nix search nixpkgs packagename</code>
|-
|-
|Installing a package
|Installing a package
Line 50: Line 50:
==== Channels ====
==== Channels ====


Nix packages are distributed through a number of Nix channels: mechanisms for distributing Nix expressions as well as the associated binary caches for them. These channels are what determine which versions your packages have, and they can be broadly categorized into ''stable'' and ''unstable'' channels. Most users will want the stable channel, currently <code>nixos-20.03</code>. For more information on channels and how to choose them, see the [[Nix Channels]] article.
Nix packages are distributed through a number of Nix channels: mechanisms for distributing Nix expressions as well as the associated binary caches for them. These channels are what determine which versions your packages have, and they can be broadly categorized into ''stable'' and ''unstable'' channels. Most users will want the stable channel, currently <code>nixos-22.05</code>. For more information on channels and how to choose them, see the [[Nix Channels]] article.


{| class="wikitable"
{| class="wikitable"
Line 88: Line 88:
When sandbox builds are enabled, Nix will setup an isolated environment for each build process. It is used to remove further hidden dependencies set by the build environment to improve reproducibility. This includes access to the network during the build outside of <code>fetch*</code> functions and files outside the Nix store.  Depending on the operating system access to other resources are blocked as well (ex. inter process communication is isolated on Linux); see [https://nixos.org/nix/manual/#sec-conf-file nix.conf section] in the Nix manual for details.
When sandbox builds are enabled, Nix will setup an isolated environment for each build process. It is used to remove further hidden dependencies set by the build environment to improve reproducibility. This includes access to the network during the build outside of <code>fetch*</code> functions and files outside the Nix store.  Depending on the operating system access to other resources are blocked as well (ex. inter process communication is isolated on Linux); see [https://nixos.org/nix/manual/#sec-conf-file nix.conf section] in the Nix manual for details.


Sandboxes are not enabled by default in Nix as there are cases where it makes building packages harder (for example <code>npm install</code> will not work due missing network access).  
Sandboxing is enabled by default on Linux, and disabled by default on macOS.
In pull requests for [https://github.com/NixOS/nixpkgs/ Nixpkgs] people are asked to test builds with sandboxing enabled (see <code>Tested using sandboxing</code> in the pull request template) because in [https://nixos.org/hydra/ official Hydra builds] sandboxing is also used.
In pull requests for [https://github.com/NixOS/nixpkgs/ Nixpkgs] people are asked to test builds with sandboxing enabled (see <code>Tested using sandboxing</code> in the pull request template) because in [https://nixos.org/hydra/ official Hydra builds] sandboxing is also used.