nix-channel(1)

πŸ’… nix-channel(1) β€” General Commands Manual

okay bestie, welcome to the nix-channel page, fresh out of the General Commands Manual. this is the one that manages your Nix channels and honestly? she's iconic. let's get into it πŸŽ€


✨ Name ✨

nix-channel β€” manage Nix channels πŸ¦‹


✨ Synopsis ✨

nix-channel {--add url [name] | --remove name | --list | --update
[names…] | --list-generations | --rollback [generation] }

like, that's the whole menu of operations. pick one, she's a one-op-at-a-time kinda girl πŸ’…


✨ Description ✨

Channels are a mechanism for referencing remote Nix expressions and conveniently retrieving their latest version. (translation: they're how you point at something far away and go "yeah that, keep it fresh" 🌈)

The moving parts of channels are:

  • The official channels listed at https://channels.nixos.org
  • The user-specific list of subscribed channels
  • The downloaded channel contents
  • The Nix expression search path, set with the -I option or the NIX_PATH environment variable
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, fetchTarball, or fetchGit in Nix expressions - the -I option in command line invocations

fr fr, if you want reproducibility you gotta say what you depend on out loud, not just vibe with whatever's currently downloaded πŸ‘‘

This command has the following operations:

  • --add url [name]

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.

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. no random loose files at the top level bestie, she has standards ✨

  • --remove name

Remove the channel name from the list of subscribed channels. unsubscribing, but make it Nix πŸ“

  • --list

Print the names and URLs of all subscribed channels on standard output. it's giving receipts πŸ’–

  • --update [names…]

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. main character energy: either everyone gets a glow-up or just the ones you named πŸ‘‘

Note πŸŽ€ Downloaded channel contents are cached. Use --tarball-ttl or the tarball-ttl configuration option to change the validity period of cached downloads.
  • --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

literally the exact same thing, just shorter to type πŸ’…

  • --rollback [generation]

Revert channels to the state before the last call to nix-channel --update. Optionally, you can specify a specific channel generation number to restore. the undo button we all wish life had 😭

πŸ’… COMMON OPTIONS πŸ’…

okay so most Nix commands accept these same command-line options, no matter which one you're running β€” think of it as the shared group chat of the Nix CLI. here's the whole list, bestie, go off:

  • --help β€” prints out a summary of the command syntax and then exits. that's the whole thing, it dips immediately πŸ’¨
  • --version β€” prints out the Nix version number on standard output and exits. short, sweet, slays.
  • --verbose, -v β€” cranks up the level of verbosity of diagnostic messages printed on standard error. and here's the tea: for each Nix operation, the information printed on standard output is well-defined, and any diagnostic information goes on standard error, never on standard output. this option can be specified repeatedly. currently these verbosity levels exist:
    • 0 β€œErrors only” β€” only prints messages explaining why the Nix invocation failed πŸ’€
    • 1 β€œInformational” β€” prints useful messages about what Nix is doing. this is the default.
    • 2 β€œTalkative” β€” prints more informational messages.
    • 3 β€œChatty” β€” prints even more informational messages.
    • 4 β€œDebug” β€” prints debug information.
    • 5 β€œVomit” β€” prints vast amounts of debug information. yes, they really named it β€œVomit”. iconic behavior honestly.
  • --quiet β€” decreases the level of verbosity of diagnostic messages printed on standard error. it's the inverse option to -v / --verbose. also may be specified repeatedly β€” go look at that verbosity levels list right above ⬆️
  • --log-format format β€” changes the output of the log format, where format is one of:
    • raw β€” this is the raw format, as outputted by nix-build.
    • internal-json β€” outputs the logs in a structured manner.
Warning 🚨 while the schema itself is relatively stable, the format of the error-messages (namely of the msg-field) can change between releases. so like, don't build your whole personality on it.
  • bar β€” only display a progress bar during the builds.
  • bar-with-logs β€” display the raw logs, with the progress bar at the bottom.
  • --no-build-output, -Q β€” by default, output written by builders to standard output and standard error gets echoed to the Nix command's standard error. this option suppresses that behavior. note that the builder's standard output and error are always written to a log file in prefix/nix/var/log/nix.
  • --max-jobs, -j number β€” sets the maximum number of build jobs Nix will perform in parallel to number. throw auto at it to use however many CPUs are in the system. the default comes from the max-jobs configuration setting, which itself defaults to 1. a higher value is useful on SMP systems, or to exploit I/O latency. setting it to 0 disallows building on the local machine, which is exactly what you want when builds should only happen on remote builders.
  • --cores β€” sets the value of the NIX_BUILD_CORES environment variable in the invocation of builders. builders can use this variable at their discretion to control the maximum amount of parallelism. in Nixpkgs, for instance, if the derivation attribute enableParallelBuilding is set to true, the builder passes the -jN flag to GNU Make. it defaults to the value of the cores configuration setting if it's set, or 1 otherwise. the value 0 means the builder should use all available CPU cores in the system.
  • --max-silent-time β€” sets the maximum number of seconds a builder can go without producing any data on standard output or standard error. the default is specified by the max-silent-time configuration setting. 0 means no time-out.
  • --timeout β€” sets the maximum number of seconds a builder can run. the default is specified by the timeout configuration setting. 0 means no timeout.
  • --keep-going, -k β€” keep going in case of failed builds, to the greatest extent possible. so basically, 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), and it may even kill builds in progress (in the parallel or distributed build case 😭).
  • --keep-failed, -K β€” says that in case of a build failure, the temporary directory (usually in /tmp) in which the build takes place should not be deleted. the path of the build directory is printed as an informational message.
  • --fallback β€” 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, it falls back on building the derivation.

the most common scenario where this is useful is when we have registered substitutes so we can perform binary distribution from, like, a network repository. if the repository is down, the realisation of the derivation will fail. when this option is specified, Nix builds the derivation instead. so installation from binaries falls back on installation from source. this option is not the default, since it's 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 that comes with that).

  • --readonly-mode β€” 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. πŸ™ˆ
  • --arg name value β€” this option is accepted by nix-env, nix-instantiate, nix-shell and nix-build. 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 default value (e.g., { argName ? defaultValue }: ...).

with --arg, 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 name, it will call it with the value you gave.

for instance, the top-level default.nix in Nixpkgs is actually a function:

{ # The system (e.g., `i686-linux') for which to build the packages.
system ? builtins.currentSystem
...
}: ...

so if you call this Nix expression (e.g., when you do nix-env --install --attr pkgname), the function will be called automatically using the value builtins.currentSystem for the system argument. you can override this using --arg, e.g., nix-env --install --attr pkgname --arg system "i686-freebsd". (note that since the argument is a Nix string literal, you have to escape the quotes.)

  • --arg-from-file name path β€” passes the contents of file path as the argument name to Nix functions.
  • --arg-from-stdin name β€” passes the contents of stdin as the argument name to Nix functions.
  • --argstr name value β€” this option is like --arg, only the value is not a Nix expression but a string. so instead of --arg system "i686-linux" (the outer quotes are there to keep the shell happy) you can say --argstr system i686-linux.
  • --attr, -A attrPath β€” selects an attribute from the top-level Nix expression being evaluated. (nix-env, nix-instantiate, nix-build and nix-shell only.) the attribute path attrPath is a sequence of attribute names separated by dots. for instance, given a top-level Nix expression e, the attribute path xorg.xorgserver would cause the expression e.xorg.xorgserver to be used. see nix-env --install for some concrete examples πŸ‘‘

in addition to attribute names, you can also specify array indices. for instance, the attribute path foo.3.bar selects the bar attribute of the fourth element of the array in the foo attribute of the top-level expression.

  • --eval-store store-url β€” the URL to the Nix store to use for evaluation, i.e. where to store derivations (.drv files) and inputs referenced by them.
  • --expr, -E β€” interprets 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. (nix-instantiate, nix-build and nix-shell only.)

for nix-shell, 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 built packages ready for use, give your expression to the nix-shell --packages convenience flag instead 🫢

  • -I, --include path β€” adds an entry to the list of search paths used to resolve lookup paths. this option may be given multiple times. paths added through -I take precedence over the nix-path configuration setting and the NIX_PATH environment variable.
  • --impure β€” allows access to mutable paths and repositories.
  • --option name value β€” sets the Nix configuration option name to value. this overrides settings in the Nix configuration file (see nix.conf5).
  • --repair β€” fixes corrupted or missing store paths by redownloading or rebuilding them. heads up though, this is slow, because it requires computing a cryptographic hash of the contents of every path in the closure of the build. also peep the warning under nix-store --repair-path.
Note ✨ see man nix.conf for overriding configuration settings with command line flags.

πŸ’– Common Environment Variables πŸ’–

okay bestie, so most Nix commands (yes, including nix-channel) peek at these lil environment variables to figure out what's going on. Think of them as the settings your shell whispers into Nix's ear. 🫢

πŸŽ€ Configuration environment variables

These ones decide how Nix loads its config. For the full tea, go read the configuration file documentation.

  • NIX_CONF_DIR β€” overrides the system configuration directory. you're basically saying "not there, here" πŸ’…
  • NIX_USER_CONF_FILES β€” overrides where the user configuration files live.
  • NIX_CONFIG β€” lets you drop configuration settings in inline, right there in the variable. no file needed, periodt.

🌸 Store setting environment variables

  • NIX_IGNORE_SYMLINK_STORE β€” so normally the Nix store directory (typically /nix/store) is not allowed to have any symlink components in it, and that's on purpose: it's how we stop "impure" builds. here's why it matters 🧐 β€” builders sometimes "canonicalise" paths by resolving every symlink component, which means builds on different machines (where /nix/store resolves to different places) could give you different results. usually that's fine… except when you deploy those builds to machines where /nix/store resolves differently. so if you're sure you're never gonna do that, you can set NIX_IGNORE_SYMLINK_STORE to 1.

and ngl, a little note: if you're symlinking the Nix store just so you can put it on a different file system than the root file system, on Linux you're better off using bind mount points, like this:

$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix

go consult the mount 8 manual page for the deets, bestie.

  • NIX_STORE_DIR β€” overrides where the Nix store lives. On Unix the default is /nix/store, set at compile time by the libstore:store-dir build option. On Windows there's no compile-time setting at all; the default is %PROGRAMDATA%\nix\store, figured out at runtime using the %PROGRAMDATA% Known Folder.

also, check the Store Types chapter β€” every store has a store setting that links back to this one as its default. iconic behavior honestly ✨

  • NIX_LOG_DIR β€” overrides the location of the Nix log directory. On Unix the default is /nix/var/log/nix, set at compile time by the log-dir build option. On Windows, no compile-time setting; the default is %PROGRAMDATA%\nix\log, determined at runtime using the %PROGRAMDATA% Known Folder.

the Local Store, Local Daemon Store, and Experimental SSH Store with filesystem mounted all have per-store settings that override this. so many little bosses 😭

  • NIX_STATE_DIR β€” overrides the location of the Nix state directory. On Unix the default is ${localstatedir}/nix, where localstatedir is a compile-time build option that defaults to /nix/var. On Windows there's no compile-time setting; the default is %PROGRAMDATA%\nix\state, determined at runtime using the %PROGRAMDATA% Known Folder.

same deal as the log dir: the Local Store, Local Daemon Store, and Experimental SSH Store with filesystem mounted have per-store settings that override it.

  • NIX_DAEMON_SOCKET_PATH β€” overrides the path to the Unix domain socket used to talk to the Nix daemon. defaults to daemon-socket/socket inside the state directory (see NIX_STATE_DIR).

if you wanna know exactly how the socket path gets resolved, the Local Daemon Store documentation has you covered.

  • TMPDIR β€” use this directory for temporary files. and yes, that includes temporary build directories, which can eat up a substantial amount of disk space, so choose wisely πŸ“. the default is /tmp.
  • NIX_REMOTE β€” overrides the store setting.

πŸ¦‹ Nix language evaluator settings

  • NIX_SHOW_STATS β€” set it to 1 and Nix will print out some evaluation statistics, like how many values got allocated. stats girlies rise πŸ‘‘
  • NIX_COUNT_CALLS β€” set it to 1 and Nix prints how often functions were called while evaluating Nix expressions. super useful for profiling your Nix expressions, fr fr.
  • GC_INITIAL_HEAP_SIZE β€” if Nix was configured to use the Boehm garbage collector, this sets the initial heap size in bytes. it defaults to 384 MiB. set it low and you use less memory, but runtime goes up because of all the garbage collection overhead. tradeoffs, bestie πŸ’€
  • NIX_PATH β€” a colon-separated list of search path entries used to resolve lookup paths.

this environment variable overrides the value of the nix-path configuration setting.

you can extend it using the -I option.

Example:

$ export NIX_PATH=/home/eelco/Dev:nixos-config=/etc/nixos

and heads up: if NIX_PATH is set to an empty string, resolving search paths will always fail. not sometimes. always. 😭

Example:

$ NIX_PATH= nix-instantiate --eval '<nixpkgs>'
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

πŸ’œ User Directories

Nix supports per-user configuration, state, and cache directories. these environment variables override where those directories go:

  • user configuration directory: NIX_CONFIG_HOME
  • user state directory: NIX_STATE_HOME
  • user cache directory: NIX_CACHE_HOME

when they're not set, the defaults depend on your platform:

  • On Unix, the XDG base directories: $XDG_CONFIG_HOME/nix, $XDG_STATE_HOME/nix, $XDG_CACHE_HOME/nix
  • On Windows, the Windows Known Folders: %APPDATA%\nix\config, %LOCALAPPDATA%\nix\state, %LOCALAPPDATA%\nix\cache

okay so for backwards compatibility, the legacy Nix commands (hi, nix-env, hi, nix-channel πŸ‘‹) use dotfiles in $HOME instead of these directories β€” unless use-xdg-base-directories is enabled. the new Nix commands (the experimental ones) use the proper directories by default. glow up 🌈

when use-xdg-base-directories is enabled, the configuration directory gets resolved like this:

  1. $NIX_CONFIG_HOME, if it is defined
  2. otherwise, the platform default (e.g. $XDG_CONFIG_HOME/nix on Unix)

and it's the exact same logic for the state and cache directories.

✨ Miscellaneous environment variables

  • IN_NIX_SHELL β€” an indicator that tells you whether the current environment was set up by nix-shell. it can have the values pure or impure.

Appendix: OS-specific conventions

just so you know, this info isn't Nix-specific, but it got referenced up there, so here it is 🫢

Unix: XDG Base Directories

The XDG Base Directory Specification defines standard locations for user-specific configuration, state, and cache files on Unix systems.

these are the environment variables it uses:

  • XDG_CONFIG_HOME (default ~/.config)
  • XDG_STATE_HOME (default ~/.local/state)
  • XDG_CACHE_HOME (default ~/.cache)
  • XDG_CONFIG_DIRS (default /etc/xdg) β€” a colon-separated list of additional configuration base directories, searched after XDG_CONFIG_HOME

Windows: Known Folders

On Windows, Known Folders provide the standard locations for application data.

the relevant folders are:

  • %APPDATA% β€” per-user roaming application data
  • %LOCALAPPDATA% β€” per-user local application data
  • %PROGRAMDATA% β€” system-wide application data

πŸŽ€ Files πŸŽ€

nix-channel operates on the following files. yes, actual files. we love a filesystem moment.

Channels

a directory containing symlinks to Nix channels, managed by nix-channel:

  • $XDG_STATE_HOME/nix/profiles/channels for regular users
  • $NIX_STATE_DIR/profiles/per-user/root/channels for root

nix-channel uses a profile to store channels. this profile contains symlinks to the contents of those channels. it's giving link farm, but make it organized πŸ’…

Subscribed channels

the list of subscribed channels is stored in

  • ~/.nix-channels
  • $XDG_STATE_HOME/nix/channels if use-xdg-base-directories is set to true

in this format:

<url> <name>
...

πŸ”₯ Examples πŸ”₯

Subscribe to the Nixpkgs channel and run hello from the GNU Hello package:

$ nix-channel --add https://channels.nixos.org/nixpkgs-unstable
$ nix-channel --list
nixpkgs https://channels.nixos.org/nixpkgs
$ nix-channel --update
$ nix-shell -p hello --run hello
hello

Revert channel updates using --rollback:

$ nix-instantiate --eval '<nixpkgs>' --attr lib.version
"22.11pre296212.530a53dcbc9"

$ nix-channel --rollback
switching from generation 483 to 482

$ nix-instantiate --eval '<nixpkgs>' --attr lib.version
"22.11pre281526.d0419badfad"

Remove a channel:

$ nix-channel --remove nixpkgs
$ nix-channel --list

and that's the whole page, bestie, you made it to the end πŸ₯³ the lil footer at the very bottom is just the source/version stamp and the date for nix-channel(1) β€” the official page name and its timestamp, nothing spooky. now go update those channels. slay πŸ’…βœ¨

πŸ“¦ where this page comes from