LinuxCommandLibrary

nix-channel

Manage Nix package channels

TLDR

List current channels

$ nix-channel --list
copy

Add a channel
$ nix-channel --add [https://nixos.org/channels/nixpkgs-unstable]
copy

Update package list of all channels
$ nix-channel --update
copy

SYNOPSIS

nix-channel [OPTIONS] SUBCOMMAND [ARGUMENTS...]

nix-channel --add URL NAME
nix-channel --remove NAME
nix-channel --update [NAME...]
nix-channel --list

PARAMETERS

--add URL NAME
    Adds a new Nix channel. URL is the web address pointing to the channel's Nix expressions (e.g., a Git repository or tarball URL), and NAME is a local identifier for the channel (e.g., 'nixpkgs', 'nixos').

--remove NAME
    Removes the specified channel identified by NAME from the list of subscribed channels. This means the packages defined by that channel will no longer be considered for updates.

--update [NAME...]
    Fetches the latest Nix expressions for one or more specified channels. If no NAME is provided, all currently subscribed channels are updated. This operation downloads new Nix expressions but does not install or update packages themselves.

--list
    Lists all currently subscribed Nix channels, showing their local name and the URL they point to.

--dry-run
    Used with --update, this option shows what channels would be updated without actually performing the update. Useful for previewing changes.

--help
    Displays a help message with usage information for the nix-channel command.

DESCRIPTION

The nix-channel command is a crucial utility within the Nix package manager ecosystem, designed to manage channels. Nix channels are essentially URLs pointing to a collection of Nix expressions, which define a consistent set of packages available at a given time. Users subscribe to channels to receive updates for their Nix packages. For instance, the 'nixos' channel represents the official NixOS distribution, while 'nixpkgs' is the primary collection of packages.

nix-channel allows users to add new channels, remove existing ones, list currently subscribed channels, and most importantly, update them. When a channel is updated, nix-channel fetches the latest set of Nix expressions from the channel's URL, making newer versions of packages available for installation or upgrade via commands like nix-env -u. This mechanism ensures that users can easily track and consume the latest stable or unstable package sets provided by the Nix community or their own organizations.

CAVEATS

Channels can become quite large, and updating them (especially the first time or after a long period) can involve significant data transfer. While nix-channel --update fetches new expressions, it does not automatically upgrade your installed packages; for that, you typically run nix-env -u or rebuild your NixOS system. Mixing channels from different sources or maturity levels (e.g., stable and unstable) can sometimes lead to dependency conflicts or unexpected behavior.

HOW CHANNELS WORK

A Nix channel is essentially a Git repository or a tarball containing Nix expressions. When you 'update' a channel, nix-channel downloads the latest version of this repository/tarball and stores it in your Nix user profile (typically ~/.nix-channels). This updated local copy is then used by other Nix commands (like nix-env) to determine which packages and versions are available. Channels are versioned, often tied to specific Git commits or dates, ensuring that the set of packages they define is coherent and reproducible.

USER-SPECIFIC MANAGEMENT

By default, nix-channel operates on a per-user basis. Each user on a Nix system maintains their own set of subscribed channels in their home directory. This means that adding or updating channels by one user does not affect the channels managed by another user or the system-wide NixOS configuration, unless the command is run with root privileges or within the NixOS configuration build process.

HISTORY

The nix-channel command has been a fundamental component of the Nix package manager since its early days. It emerged as a solution to efficiently distribute and manage consistent sets of Nix expressions, enabling the purely functional deployment model Nix is known for. Its design reflects the need for reproducible builds and atomic upgrades across different user environments. Over time, while the underlying channel mechanism has remained robust, enhancements have focused on performance and usability, ensuring it continues to serve as the primary gateway for users to access and update the vast Nix package collection.

SEE ALSO

Copied to clipboard