Nix package manager: Difference between revisions
imported>Ixxie Rewrote introductory paragraph. |
imported>Ixxie Moved nix-env and channels section from NixOS |
||
Line 12: | Line 12: | ||
Support for declarative configuration in Nix is limited, and the solutions are somewhat fragmented. The only only configuration file officially associated with Nix is <code>nix.conf</code> (usually found in <code>/etc/nix/</code>), which defines a number of settings relating to how Nix, including build, garbage collection, sandboxing, and user permissions. Details on the available options are found in the [https://nixos.org/nix/manual/#sec-conf-file|nix.conf section of the manual]. Since most scenarios involve using [[Nixpkgs]], configuration of <code>~/.config/nixpkgs/config.nix</code> is often also helpful; here package overrides can be specified. Work on Nix user profiles is well underway, see [https://github.com/NixOS/nixpkgs/pull/9250|PR 9250]. | Support for declarative configuration in Nix is limited, and the solutions are somewhat fragmented. The only only configuration file officially associated with Nix is <code>nix.conf</code> (usually found in <code>/etc/nix/</code>), which defines a number of settings relating to how Nix, including build, garbage collection, sandboxing, and user permissions. Details on the available options are found in the [https://nixos.org/nix/manual/#sec-conf-file|nix.conf section of the manual]. Since most scenarios involve using [[Nixpkgs]], configuration of <code>~/.config/nixpkgs/config.nix</code> is often also helpful; here package overrides can be specified. Work on Nix user profiles is well underway, see [https://github.com/NixOS/nixpkgs/pull/9250|PR 9250]. | ||
=== Imperative Operations === | |||
==== User Environments ==== | |||
Nix offers an imperative package management command line tool - <code>nix-env</code> - which can be used to install packages at the user level. Packages installed using <code>nix-env</code> are only available to the given user, and do not change system state. | |||
{| class="wikitable" | |||
|+ Common <code>nix-env</code> Commands | |||
|- | |||
|Searching for packages | |||
|<code>nix-env -qaP '.*packagename.*'</code> | |||
|- | |||
|Installing a package | |||
|<code>nix-env -i packagename</code> | |||
|- | |||
|List installed packages | |||
|<code>nix-env -q</code> | |||
|- | |||
|Uninstall packages | |||
|<code>nix-env -e packagename</code> | |||
|- | |||
|Upgrade packages | |||
|<code>nix-env -u</code> | |||
|} | |||
==== Channels ==== | |||
Nix ''channels'' are mechanisms for distributing Nix expressions as well as the associated binaries for them; a Nix channel corresponds to a repository in a conventional package management system. Official Nix channels are automatically updated once tests are passed in Nixpkgs' [[Hydra]] instance. It is also possible to create one's own Nix channels, but here we focus the official channels. See the NixOS site for [https://nixos.org/channels/ a full list of official channels]. | |||
NixOS is distributed through a number of channels. These NixOS channels can be broadly categorised into ''stable'' and ''unstable'' channels, and ''large'' and ''small'' channels: | |||
* Stable/unstable: | |||
** Stable channels (<code>nixos-17.09</code>) provide conservative updates for fixing bugs and security vulnerabilities, but do not receive major updates after initial release. New stable channels are released every six months. | |||
** Unstable channels (<code>nixos-unstable</code>, <code>nixos-unstable-small</code>) correspond to the main development branch of Nixpkgs, delivering the latest tested updates on a rolling basis. | |||
* Large/small: | |||
** Large channels (<code>nixos-17.09</code>, <code>nixos-unstable</code>) provide binary builds for the full breadth of Nixpkgs. | |||
** Small channels (<code>nixos-17.09-small</code>, <code>nixos-unstable-small</code>) are identical to large channels, but contain fewer binaries. This means they update faster, but require more to be built from source. | |||
Most users will want the stable/large channel, currently <code>nixos-17.09</code>. | |||
Like packages installed via <code>nix-env</code>, channels are managed at user-level. The following are the most common commands for Nix channel management: | |||
{| class="wikitable" | |||
|+ Common nix-channel commands | |||
|- | |||
|Listing current channels | |||
|<code>nix-channel --list</code> | |||
|- | |||
| Adding a primary channel | |||
|<code><nowiki>nix-channel --add https://nixos.org/channels/channel-name nixos</nowiki></code> | |||
|- | |||
| Adding other channels | |||
|<code><nowiki>nix-channel --add https://some.channel/url my-alias</nowiki></code> | |||
|- | |||
| Remove a channel | |||
|<code>nix-channel --remove channel-alias</code> | |||
|- | |||
| Updating a channel | |||
|<code>nix-channel --update channel-alias</code> | |||
|- | |||
| Updating all channels | |||
|<code>nix-channel --update</code> | |||
|} | |||
Note that updating channels won't cause a rebuild in itself; if you want to update channels and rebuild, you can run <code>nixos rebuild --upgrade</code> to do both in one step. | |||
== Internals == | == Internals == |