2020-07-24 13:56:19 +03:00
# Name
2020-07-23 13:58:42 +03:00
2020-07-24 13:56:19 +03:00
`nix-channel` - manage Nix channels
2020-07-23 13:58:42 +03:00
2020-07-24 13:56:19 +03:00
# Synopsis
2020-07-23 13:58:42 +03:00
2021-05-13 20:33:03 +03:00
`nix-channel` {`--add` url [*name*] | `--remove` *name* | `--list` | `--update` [*names…*] | `--list-generations` | `--rollback` [*generation*] }
2020-07-23 13:58:42 +03:00
# Description
2023-03-05 04:59:17 +02:00
Channels are a mechanism for referencing remote Nix expressions and conveniently retrieving their latest version.
For the list of official channels, visit < https: / / nixos . org / channels > .
> **Note**
>
> The state of a subscribed channel is external to the Nix expressions relying on it.
> This may limit reproducibility.
>
> Dependencies on other Nix expressions can be declared explicitly with:
> - [`fetchurl`](@docroot@/language/builtins.md#builtins-fetchurl), [`fetchTarball`](@docroot@/language/builtins.md#builtins-fetchTarball), or [`fetchGit`](@docroot@/language/builtins.md#builtins-fetchGit) in Nix expressions
> - the [`-I` option](@docroot@/command-ref/opt-common.md#opt-I) in command line invocations
2020-07-23 13:58:42 +03:00
This command has the following operations:
2021-04-23 15:30:42 +03:00
- `--add` *url* \[*name*\]\
2023-03-05 04:59:17 +02:00
Add a channel *name* located at *url* to the list of subscribed channels.
If *name* is omitted, default to the last component of *url* , with the suffixes `-stable` or `-unstable` removed.
> **Note**
>
> `--add` does not automatically perform an update.
> Use `--update` explicitly.
2020-07-23 13:58:42 +03:00
2023-02-17 19:57:15 +02:00
A channel URL must point to a directory containing a file `nixexprs.tar.gz` .
At the top level, that tarball must contain a single directory with a `default.nix` file that serves as the channel’ s entry point.
2021-04-23 15:30:42 +03:00
- `--remove` *name* \
2023-03-05 04:59:17 +02:00
Remove the channel *name* from the list of subscribed channels.
2020-07-23 13:58:42 +03:00
2021-04-23 15:30:42 +03:00
- `--list` \
2023-03-05 04:59:17 +02:00
Print the names and URLs of all subscribed channels on standard output.
2020-07-23 13:58:42 +03:00
2021-04-23 15:30:42 +03:00
- `--update` \[*names*…\]\
2023-03-05 04:59:17 +02:00
Download the Nix expressions of subscribed channels and create a new generation.
Update all channels if none is specified, and only those included in *names* otherwise.
2020-07-23 13:58:42 +03:00
2021-05-13 20:33:03 +03:00
- `--list-generations` \
Prints a list of all the current existing generations for the
channel profile.
Works the same way as
```
nix-env --profile /nix/var/nix/profiles/per-user/$USER/channels --list-generations
```
2021-04-23 15:30:42 +03:00
- `--rollback` \[*generation*\]\
2023-03-05 04:59:17 +02:00
Revert channels to the state before the last call to `nix-channel --update` .
Optionally, you can specify a specific channel *generation* number to restore.
2020-07-23 13:58:42 +03:00
2023-03-23 17:27:41 +02:00
{{#include ./opt-common.md}}
{{#include ./env-common.md}}
2023-05-15 16:26:14 +03:00
# Files
`nix-channel` operates on the following files.
{{#include ./files/channels.md}}
2020-07-23 13:58:42 +03:00
# Examples
2023-03-05 04:59:17 +02:00
Subscribe to the Nixpkgs channel and run `hello` from the GNU Hello package:
2020-07-23 13:58:42 +03:00
2020-07-31 16:43:25 +03:00
```console
$ nix-channel --add https://nixos.org/channels/nixpkgs-unstable
2023-03-05 04:59:17 +02:00
$ nix-channel --list
nixpkgs https://nixos.org/channels/nixpkgs
2020-07-31 16:43:25 +03:00
$ nix-channel --update
2023-03-05 04:59:17 +02:00
$ nix-shell -p hello --run hello
hello
2020-07-31 16:43:25 +03:00
```
2020-07-23 13:58:42 +03:00
2023-03-05 04:59:17 +02:00
Revert channel updates using `--rollback` :
2020-07-23 13:58:42 +03:00
2020-07-31 16:43:25 +03:00
```console
2023-03-05 04:59:17 +02:00
$ nix-instantiate --eval '< nixpkgs > ' --attr lib.version
"22.11pre296212.530a53dcbc9"
2020-07-24 13:56:19 +03:00
2020-07-31 16:43:25 +03:00
$ nix-channel --rollback
switching from generation 483 to 482
2020-07-24 13:56:19 +03:00
2023-03-05 04:59:17 +02:00
$ nix-instantiate --eval '< nixpkgs > ' --attr lib.version
"22.11pre281526.d0419badfad"
```
Remove a channel:
```console
$ nix-channel --remove nixpkgs
$ nix-channel --list
2020-07-31 16:43:25 +03:00
```