.\" -*- mode: troff; coding: utf-8 -*- .TH "nix-channel" "1" "" .SH Name .LP \f(CRnix-channel\fR - manage Nix channels .SH Synopsis .LP \f(CRnix-channel\fR {\f(CR--add\fR url [\fIname\fR] | \f(CR--remove\fR \fIname\fR | \f(CR--list\fR | \f(CR--update\fR [\fInames…\fR] | \f(CR--list-generations\fR | \f(CR--rollback\fR [\fIgeneration\fR] } .SH Description .LP Channels are a mechanism for referencing remote Nix expressions and conveniently retrieving their latest version. .PP The moving parts of channels are: - The official channels listed at \fIhttps://nixos.org/channels\fR - The user-specific list of \fBsubscribed channels\fR - The \fBdownloaded channel contents\fR - The \fBNix expression search path\fR, set with the \fB\f(CR-I\fR option\fR or the \fB\f(CRNIX_PATH\fR environment variable\fR .RS .PP \fBNote\fR .PP The state of a subscribed channel is external to the Nix expressions relying on it. This may limit reproducibility. .PP Dependencies on other Nix expressions can be declared explicitly with: - \fB\f(CRfetchurl\fR\fR, \fB\f(CRfetchTarball\fR\fR, or \fB\f(CRfetchGit\fR\fR in Nix expressions - the \fB\f(CR-I\fR option\fR in command line invocations .RE .PP This command has the following operations: .IP "\(bu" 3 \f(CR--add\fR \fIurl\fR [\fIname\fR] .br Add a channel \fIname\fR located at \fIurl\fR to the list of subscribed channels. If \fIname\fR is omitted, default to the last component of \fIurl\fR, with the suffixes \f(CR-stable\fR or \f(CR-unstable\fR removed. .RS .IP \fBNote\fR .IP \f(CR--add\fR does not automatically perform an update. Use \f(CR--update\fR explicitly. .RE .IP A channel URL must point to a directory containing a file \f(CRnixexprs.tar.gz\fR. At the top level, that tarball must contain a single directory with a \f(CRdefault.nix\fR file that serves as the channel’s entry point. .IP "\(bu" 3 \f(CR--remove\fR \fIname\fR .br Remove the channel \fIname\fR from the list of subscribed channels. .IP "\(bu" 3 \f(CR--list\fR .br Print the names and URLs of all subscribed channels on standard output. .IP "\(bu" 3 \f(CR--update\fR [\fInames\fR…] .br Download the Nix expressions of subscribed channels and create a new generation. Update all channels if none is specified, and only those included in \fInames\fR otherwise. .IP "\(bu" 3 \f(CR--list-generations\fR .br Prints a list of all the current existing generations for the channel profile. .IP Works the same way as \f(CR nix-env --profile /nix/var/nix/profiles/per-user/$USER/channels --list-generations \fR .IP "\(bu" 3 \f(CR--rollback\fR [\fIgeneration\fR] .br Revert channels to the state before the last call to \f(CRnix-channel --update\fR. Optionally, you can specify a specific channel \fIgeneration\fR number to restore. .SH Common Options .LP Most Nix commands accept the following command-line options: .IP "\(bu" 3 \fB\f(CR--help\fR\fR .IP Prints out a summary of the command syntax and exits. .IP "\(bu" 3 \fB\f(CR--version\fR\fR .IP Prints out the Nix version number on standard output and exits. .IP "\(bu" 3 \fB\f(CR--verbose\fR\fR / \f(CR-v\fR .IP Increases the level of verbosity of diagnostic messages printed on standard error. For each Nix operation, the information printed on standard output is well-defined; any diagnostic information is printed on standard error, never on standard output. .IP This option may be specified repeatedly. Currently, the following verbosity levels exist: .RS .IP "\(bu" 3 \f(CR0\fR “Errors only” .RE .IP Only print messages explaining why the Nix invocation failed. .RS .IP "\(bu" 3 \f(CR1\fR “Informational” .RE .IP Print \fIuseful\fR messages about what Nix is doing. This is the default. .RS .IP "\(bu" 3 \f(CR2\fR “Talkative” .RE .IP Print more informational messages. .RS .IP "\(bu" 3 \f(CR3\fR “Chatty” .RE .IP Print even more informational messages. .RS .IP "\(bu" 3 \f(CR4\fR “Debug” .RE .IP Print debug information. .RS .IP "\(bu" 3 \f(CR5\fR “Vomit” .RE .IP Print vast amounts of debug information. .IP "\(bu" 3 \fB\f(CR--quiet\fR\fR .IP Decreases the level of verbosity of diagnostic messages printed on standard error. This is the inverse option to \f(CR-v\fR / \f(CR--verbose\fR. .IP This option may be specified repeatedly. See the previous verbosity levels list. .IP "\(bu" 3 \fB\f(CR--log-format\fR\fR \fIformat\fR .IP This option can be used to change the output of the log format, with \fIformat\fR being one of: .RS .IP "\(bu" 3 \f(CRraw\fR .RE .IP This is the raw format, as outputted by nix-build. .RS .IP "\(bu" 3 \f(CRinternal-json\fR .RE .IP Outputs the logs in a structured manner. .RS .IP \fBWarning\fR .IP While the schema itself is relatively stable, the format of the error-messages (namely of the \f(CRmsg\fR-field) can change between releases. .RE .RS .IP "\(bu" 3 \f(CRbar\fR .RE .IP Only display a progress bar during the builds. .RS .IP "\(bu" 3 \f(CRbar-with-logs\fR .RE .IP Display the raw logs, with the progress bar at the bottom. .IP "\(bu" 3 \fB\f(CR--no-build-output\fR\fR / \f(CR-Q\fR .IP By default, output written by builders to standard output and standard error is echoed to the Nix command\(cqs standard error. This option suppresses this behaviour. Note that the builder\(cqs standard output and error are always written to a log file in \f(CRprefix/nix/var/log/nix\fR. .IP "\(bu" 3 \fB\f(CR--max-jobs\fR\fR / \f(CR-j\fR \fInumber\fR .IP Sets the maximum number of build jobs that Nix will perform in parallel to the specified number. Specify \f(CRauto\fR to use the number of CPUs in the system. The default is specified by the \f(CRmax-jobs\fR configuration setting, which itself defaults to \f(CR1\fR. A higher value is useful on SMP systems or to exploit I/O latency. .IP Setting it to \f(CR0\fR disallows building on the local machine, which is useful when you want builds to happen only on remote builders. .IP "\(bu" 3 \fB\f(CR--cores\fR\fR .IP Sets the value of the \f(CRNIX_BUILD_CORES\fR environment variable in the invocation of builders. Builders can use this variable at their discretion to control the maximum amount of parallelism. For instance, in Nixpkgs, if the derivation attribute \f(CRenableParallelBuilding\fR is set to \f(CRtrue\fR, the builder passes the \f(CR-jN\fR flag to GNU Make. It defaults to the value of the \f(CRcores\fR configuration setting, if set, or \f(CR1\fR otherwise. The value \f(CR0\fR means that the builder should use all available CPU cores in the system. .IP "\(bu" 3 \fB\f(CR--max-silent-time\fR\fR .IP Sets the maximum number of seconds that a builder can go without producing any data on standard output or standard error. The default is specified by the \f(CRmax-silent-time\fR configuration setting. \f(CR0\fR means no time-out. .IP "\(bu" 3 \fB\f(CR--timeout\fR\fR .IP Sets the maximum number of seconds that a builder can run. The default is specified by the \f(CRtimeout\fR configuration setting. \f(CR0\fR means no timeout. .IP "\(bu" 3 \fB\f(CR--keep-going\fR\fR / \f(CR-k\fR .IP Keep going in case of failed builds, to the greatest extent possible. That is, if building an input of some derivation fails, Nix will still build the other inputs, but not the derivation itself. Without this option, Nix stops if any build fails (except for builds of substitutes), possibly killing builds in progress (in case of parallel or distributed builds). .IP "\(bu" 3 \fB\f(CR--keep-failed\fR\fR / \f(CR-K\fR .IP Specifies that in case of a build failure, the temporary directory (usually in \f(CR/tmp\fR) in which the build takes place should not be deleted. The path of the build directory is printed as an informational message. .IP "\(bu" 3 \fB\f(CR--fallback\fR\fR .IP Whenever Nix attempts to build a derivation for which substitutes are known for each output path, but realising the output paths through the substitutes fails, fall back on building the derivation. .IP The most common scenario in which this is useful is when we have registered substitutes in order to perform binary distribution from, say, a network repository. If the repository is down, the realisation of the derivation will fail. When this option is specified, Nix will build the derivation instead. Thus, installation from binaries falls back on installation from source. This option is not the default since it is generally not desirable for a transient failure in obtaining the substitutes to lead to a full build from source (with the related consumption of resources). .IP "\(bu" 3 \fB\f(CR--readonly-mode\fR\fR .IP When this option is used, no attempt is made to open the Nix database. Most Nix operations do need database access, so those operations will fail. .IP "\(bu" 3 \fB\f(CR--arg\fR\fR \fIname\fR \fIvalue\fR .IP This option is accepted by \f(CRnix-env\fR, \f(CRnix-instantiate\fR, \f(CRnix-shell\fR and \f(CRnix-build\fR. When evaluating Nix expressions, the expression evaluator will automatically try to call functions that it encounters. It can automatically call functions for which every argument has a \fBdefault value\fR (e.g., \f(CR{ argName ? defaultValue }: ...\fR). .IP With \f(CR--arg\fR, you can also call functions that have arguments without a default value (or override a default value). That is, if the evaluator encounters a function with an argument named \fIname\fR, it will call it with value \fIvalue\fR. .IP For instance, the top-level \f(CRdefault.nix\fR in Nixpkgs is actually a function: .LP .EX { # The system (e.g., \(gai686-linux') for which to build the packages. system ? builtins.currentSystem \&... }: ... .EE .IP So if you call this Nix expression (e.g., when you do \f(CRnix-env --install --attr pkgname\fR), the function will be called automatically using the value \fB\f(CRbuiltins.currentSystem\fR\fR for the \f(CRsystem\fR argument. You can override this using \f(CR--arg\fR, e.g., \f(CRnix-env --install --attr pkgname --arg system \e\(dqi686-freebsd\e\(dq\fR. (Note that since the argument is a Nix string literal, you have to escape the quotes.) .IP "\(bu" 3 \fB\f(CR--argstr\fR\fR \fIname\fR \fIvalue\fR .IP This option is like \f(CR--arg\fR, only the value is not a Nix expression but a string. So instead of \f(CR--arg system \e\(dqi686-linux\e\(dq\fR (the outer quotes are to keep the shell happy) you can say \f(CR--argstr system i686-linux\fR. .IP "\(bu" 3 \fB\f(CR--attr\fR\fR / \f(CR-A\fR \fIattrPath\fR .IP Select an attribute from the top-level Nix expression being evaluated. (\f(CRnix-env\fR, \f(CRnix-instantiate\fR, \f(CRnix-build\fR and \f(CRnix-shell\fR only.) The \fIattribute path\fR \fIattrPath\fR is a sequence of attribute names separated by dots. For instance, given a top-level Nix expression \fIe\fR, the attribute path \f(CRxorg.xorgserver\fR would cause the expression \f(CRe.xorg.xorgserver\fR to be used. See \fB\f(CRnix-env --install\fR\fR for some concrete examples. .IP In addition to attribute names, you can also specify array indices. For instance, the attribute path \f(CRfoo.3.bar\fR selects the \f(CRbar\fR attribute of the fourth element of the array in the \f(CRfoo\fR attribute of the top-level expression. .IP "\(bu" 3 \fB\f(CR--expr\fR\fR / \f(CR-E\fR .IP Interpret the command line arguments as a list of Nix expressions to be parsed and evaluated, rather than as a list of file names of Nix expressions. (\f(CRnix-instantiate\fR, \f(CRnix-build\fR and \f(CRnix-shell\fR only.) .IP For \f(CRnix-shell\fR, this option is commonly used to give you a shell in which you can build the packages returned by the expression. If you want to get a shell which contain the \fIbuilt\fR packages ready for use, give your expression to the \f(CRnix-shell --packages\fR convenience flag instead. .IP "\(bu" 3 \fB\f(CR-I\fR\fR \fIpath\fR .IP Add an entry to the \fBNix expression search path\fR. This option may be given multiple times. Paths added through \f(CR-I\fR take precedence over \fB\f(CRNIX_PATH\fR\fR. .IP "\(bu" 3 \fB\f(CR--option\fR\fR \fIname\fR \fIvalue\fR .IP Set the Nix configuration option \fIname\fR to \fIvalue\fR. This overrides settings in the Nix configuration file (see nix.conf5). .IP "\(bu" 3 \fB\f(CR--repair\fR\fR .IP Fix corrupted or missing store paths by redownloading or rebuilding them. Note that this is slow because it requires computing a cryptographic hash of the contents of every path in the closure of the build. Also note the warning under \f(CRnix-store --repair-path\fR. .SH Common Environment Variables .LP Most Nix commands interpret the following environment variables: .IP "\(bu" 3 \fB\f(CRIN_NIX_SHELL\fR\fR .br Indicator that tells if the current environment was set up by \f(CRnix-shell\fR. It can have the values \f(CRpure\fR or \f(CRimpure\fR. .IP "\(bu" 3 \fB\f(CRNIX_PATH\fR\fR .br A colon-separated list of directories used to look up the location of Nix expressions using \fBpaths\fR enclosed in angle brackets (i.e., \f(CR\fR), e.g. \f(CR/home/eelco/Dev:/etc/nixos\fR. It can be extended using the \fB\f(CR-I\fR option\fR. .IP If \f(CRNIX_PATH\fR is not set at all, Nix will fall back to the following list in \fBimpure\fR and \fBunrestricted\fR evaluation mode: .RS .IP "1." 3 \f(CR$HOME/.nix-defexpr/channels\fR .if n \ .sp -1 .if t \ .sp -0.25v .IP "2." 3 \f(CRnixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixpkgs\fR .if n \ .sp -1 .if t \ .sp -0.25v .IP "3." 3 \f(CR/nix/var/nix/profiles/per-user/root/channels\fR .RE .IP If \f(CRNIX_PATH\fR is set to an empty string, resolving search paths will always fail. For example, attempting to use \f(CR\fR will produce: .LP .EX error: file 'nixpkgs' was not found in the Nix search path .EE .IP "\(bu" 3 \fB\f(CRNIX_IGNORE_SYMLINK_STORE\fR\fR .br Normally, the Nix store directory (typically \f(CR/nix/store\fR) is not allowed to contain any symlink components. This is to prevent “impure” builds. Builders sometimes “canonicalise” paths by resolving all symlink components. Thus, builds on different machines (with \f(CR/nix/store\fR resolving to different locations) could yield different results. This is generally not a problem, except when builds are deployed to machines where \f(CR/nix/store\fR resolves differently. If you are sure that you’re not going to do that, you can set \f(CRNIX_IGNORE_SYMLINK_STORE\fR to \f(CR1\fR. .IP Note that if you’re symlinking the Nix store so that you can put it on another file system than the root file system, on Linux you’re better off using \f(CRbind\fR mount points, e.g., .LP .EX $ mkdir /nix $ mount -o bind /mnt/otherdisk/nix /nix .EE .IP Consult the mount 8 manual page for details. .IP "\(bu" 3 \fB\f(CRNIX_STORE_DIR\fR\fR .br Overrides the location of the Nix store (default \f(CRprefix/store\fR). .IP "\(bu" 3 \fB\f(CRNIX_DATA_DIR\fR\fR .br Overrides the location of the Nix static data directory (default \f(CRprefix/share\fR). .IP "\(bu" 3 \fB\f(CRNIX_LOG_DIR\fR\fR .br Overrides the location of the Nix log directory (default \f(CRprefix/var/log/nix\fR). .IP "\(bu" 3 \fB\f(CRNIX_STATE_DIR\fR\fR .br Overrides the location of the Nix state directory (default \f(CRprefix/var/nix\fR). .IP "\(bu" 3 \fB\f(CRNIX_CONF_DIR\fR\fR .br Overrides the location of the system Nix configuration directory (default \f(CRprefix/etc/nix\fR). .IP "\(bu" 3 \fB\f(CRNIX_CONFIG\fR\fR .br Applies settings from Nix configuration from the environment. The content is treated as if it was read from a Nix configuration file. Settings are separated by the newline character. .IP "\(bu" 3 \fB\f(CRNIX_USER_CONF_FILES\fR\fR .br Overrides the location of the Nix user configuration files to load from. .IP The default are the locations according to the \fBXDG Base Directory Specification\fR. See the \fBXDG Base Directories\fR sub-section for details. .IP The variable is treated as a list separated by the \f(CR:\fR token. .IP "\(bu" 3 \fB\f(CRTMPDIR\fR\fR .br Use the specified directory to store temporary files. In particular, this includes temporary build directories; these can take up substantial amounts of disk space. The default is \f(CR/tmp\fR. .IP "\(bu" 3 \fB\f(CRNIX_REMOTE\fR\fR .br This variable should be set to \f(CRdaemon\fR if you want to use the Nix daemon to execute Nix operations. This is necessary in \fBmulti-user Nix installations\fR. If the Nix daemon\(cqs Unix socket is at some non-standard path, this variable should be set to \f(CRunix://path/to/socket\fR. Otherwise, it should be left unset. .IP "\(bu" 3 \fB\f(CRNIX_SHOW_STATS\fR\fR .br If set to \f(CR1\fR, Nix will print some evaluation statistics, such as the number of values allocated. .IP "\(bu" 3 \fB\f(CRNIX_COUNT_CALLS\fR\fR .br If set to \f(CR1\fR, Nix will print how often functions were called during Nix expression evaluation. This is useful for profiling your Nix expressions. .IP "\(bu" 3 \fB\f(CRGC_INITIAL_HEAP_SIZE\fR\fR .br If Nix has been configured to use the Boehm garbage collector, this variable sets the initial size of the heap in bytes. It defaults to 384 MiB. Setting it to a low value reduces memory consumption, but will increase runtime due to the overhead of garbage collection. .SS XDG Base Directories .LP Nix follows the \fBXDG Base Directory Specification\fR. .PP For backwards compatibility, Nix commands will follow the standard only when \fB\f(CRuse-xdg-base-directories\fR\fR is enabled. \fBNew Nix commands\fR (experimental) conform to the standard by default. .PP The following environment variables are used to determine locations of various state and configuration files: .IP "\(bu" 3 [\f(CRXDG_CONFIG_HOME\fR]{#env-XDG\fICONFIG\fRHOME} (default \f(CR\(ti/.config\fR) .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 [\f(CRXDG_STATE_HOME\fR]{#env-XDG\fISTATE\fRHOME} (default \f(CR\(ti/.local/state\fR) .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 [\f(CRXDG_CACHE_HOME\fR]{#env-XDG\fICACHE\fRHOME} (default \f(CR\(ti/.cache\fR) .SH Files .LP \f(CRnix-channel\fR operates on the following files. .SS Channels .LP A directory containing symlinks to Nix channels, managed by \fB\f(CRnix-channel\fR\fR: .IP "\(bu" 3 \f(CR$XDG_STATE_HOME/nix/profiles/channels\fR for regular users .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \f(CR$NIX_STATE_DIR/profiles/per-user/root/channels\fR for \f(CRroot\fR .LP \fB\f(CRnix-channel\fR\fR uses a \fBprofile\fR to store channels. This profile contains symlinks to the contents of those channels. .SS Subscribed channels .LP The list of subscribed channels is stored in .IP "\(bu" 3 \f(CR\(ti/.nix-channels\fR .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \f(CR$XDG_STATE_HOME/nix/channels\fR if \fB\f(CRuse-xdg-base-directories\fR\fR is set to \f(CRtrue\fR .LP in the following format: .LP .EX \&... .EE .SH Examples .LP Subscribe to the Nixpkgs channel and run \f(CRhello\fR from the GNU Hello package: .LP .EX $ nix-channel --add https://nixos.org/channels/nixpkgs-unstable $ nix-channel --list nixpkgs https://nixos.org/channels/nixpkgs $ nix-channel --update $ nix-shell -p hello --run hello hello .EE .PP Revert channel updates using \f(CR--rollback\fR: .LP .EX $ nix-instantiate --eval '' --attr lib.version \(dq22.11pre296212.530a53dcbc9\(dq $ nix-channel --rollback switching from generation 483 to 482 $ nix-instantiate --eval '' --attr lib.version \(dq22.11pre281526.d0419badfad\(dq .EE .PP Remove a channel: .LP .EX $ nix-channel --remove nixpkgs $ nix-channel --list .EE