NIX-STORE-GENERATE-BINARY-CACHE-KEY(1)

✨ NAME ✨

nix-store --generate-binary-cache-key β€” bestie, this is the one that pops out a whole key pair for you to use for a binary cache. πŸ’… It lives in the General Commands Manual, and the page you're reading is nix-store ...y-cache-key(1) β€” yes the header got truncated, she's shy, it's fine. πŸ’–


πŸ¦‹ SYNOPSIS πŸ¦‹

nix-store --generate-binary-cache-key key-name secret-key-file public-key-file

🌸 DESCRIPTION 🌸

Okay so picture this: this command generates an Ed25519 key pair, and that pair is literally the thing you use to create a signed binary cache. It takes three mandatory parameters β€” not two, not four, three, she's very specific:

  1. A key name, like cache.example.org-1. This is what gets used to look up keys on the client when it verifies signatures. Fr fr it can be literally anything you want, but the suggested vibe is to use the host name of your cache (so like cache.example.org) with a suffix that denotes the number of the key β€” and you bump that number every single time you need to revoke a key. πŸ”
  2. The file name where the secret key is gonna be stored. 🀫
  3. The file name where the public key is gonna be stored. πŸ“’

That's the whole ritual. Key name, secret file, public file. Slay. ✨


πŸ’… OPTIONS πŸ’…

So these next options are allowed for all nix-store operations, but ngl they might not always have an effect β€” depends on the operation, iykyk.

  • --add-root path β€” this makes the result of a realisation (--realise and --force-realise specifically) get registered as a root of the garbage collector. Your path will be created as a symlink pointing to the resulting store path. And that's not even the extra part β€” a uniquely named symlink to path also gets created in /nix/var/nix/gcroots/auto/. For example, bestie:

$ nix-store --add-root /home/eelco/bla/result --realise ...

$ ls -l /nix/var/nix/gcroots/auto
lrwxrwxrwx    1 ... 2005-03-13 21:10 dn54lcypm8f8... -> /home/eelco/bla/result

$ ls -l /home/eelco/bla/result
lrwxrwxrwx    1 ... 2005-03-13 21:10 /home/eelco/bla/result -> /nix/store/1r11343n6qd4...-f-spot-0.0.10

So the way that works is: when /home/eelco/bla/result gets removed, the GC root in the auto directory becomes a dangling symlink, and the collector just ignores it. Ghosted. πŸ‘»

⚠️ Warning ⚠️ Note that it is not possible to move or rename GC roots, because the symlink in the auto directory will still be pointing at the old location. So like, don't even try it, the symlink does not care about your rebrand. πŸ’€

And if there are multiple results? Then multiple symlinks get created, and past the first one they're sequentially numbered β€” so like foo, foo-2, foo-3, and so on. 🌈 Numbered besties, one after another.

<h2>πŸ’… Common Options πŸ’…</h2>

Okay bestie, here's the tea: most Nix commands accept this same lil' set of command-line options, and honestly? They're lowkey iconic. Let's go through them one by one, no skips, no cap. 🫢

  • --help β€” prints out a summary of the command syntax and then dips out (exits). Short, sweet, slay.
  • --version β€” prints out the Nix version number on standard output and exits. That's it, that's the whole vibe. ✨
  • --verbose / -v β€” bumps up the level of verbosity of diagnostic messages printed on standard error. Here's the important part, bestie: for each Nix operation, the info printed on standard output is well-defined β€” any diagnostic info goes to standard error, never to standard output. Not once. Not ever.

This option may be specified repeatedly (stack it like your iced coffee orders β˜•). Currently, these are the verbosity levels that exist:

  • 0 β€œErrors only” β€” only print messages explaining why the Nix invocation failed. The bare minimum era. 😭
  • 1 β€œInformational” β€” print useful messages about what Nix is doing. This is the default, so this is the vibe you're already living in.
  • 2 β€œTalkative” β€” print more informational messages. She's opening up. πŸ¦‹
  • 3 β€œChatty” β€” print even more informational messages. Now she will not stop talking.
  • 4 β€œDebug” β€” print debug information. Detective mode πŸ”
  • 5 β€œVomit” β€” print vast amounts of debug information. Truly unhinged, unbothered, in her flop era of word count. πŸ’€
  • --quiet β€” decreases the level of verbosity of diagnostic messages printed on standard error. It's the inverse option to -v / --verbose β€” the anti-girlie. May also be specified repeatedly; see the verbosity levels list right above. πŸ‘†
  • --log-format format β€” use this to change the output of the log format, where format is one of the following:
    • 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 don't go building a whole personality around parsing it, ok?
  • bar β€” only display a progress bar during the builds. Aesthetic, minimal, focused. πŸ’…
  • bar-with-logs β€” display the raw logs, with the progress bar at the bottom. Best of both worlds, fr fr.
  • --no-build-output / -Q β€” by default, output written by builders to standard output and standard error is echoed to the Nix command's standard error. This option suppresses that behaviour. Note that the builder's standard output and error are always written to a log file in prefix/nix/var/log/nix β€” like, you can't escape the receipts, bestie. πŸ“
  • --max-jobs / -j number β€” sets the maximum number of build jobs that Nix will perform in parallel to the specified number. Specify auto to use the number of CPUs in the system. The default is specified by the max-jobs configuration setting, which itself defaults to 1. A higher value is useful on SMP systems or to exploit I/O latency. Multitasking queen energy. πŸ‘‘

Setting it to 0 disallows building on the local machine, which is useful when you want builds to happen only on remote builders. Not in this house! 🚫🏠

  • --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. For instance, in Nixpkgs, 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 set, or 1 otherwise. The value 0 means that the builder should use all available CPU cores in the system β€” she said all of them. πŸ”₯
  • --max-silent-time β€” 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 max-silent-time configuration setting. 0 means no time-out. The silent treatment protection clause. πŸ™ˆ
  • --timeout β€” sets the maximum number of seconds that a builder can run. The default is specified by the timeout configuration setting. 0 means no timeout. Give her all the time she needs, no rush. 🌸
  • --keep-going / -k β€” 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). She doesn't give up on the whole group project just because one person ghosted. πŸ’ͺ
  • --keep-failed / -K β€” specifies 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. She's preserving the evidence, forensic girlie. πŸ”
  • --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, fall back on building the derivation.

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). Like, a lil' wifi blip should not trigger a whole source-build saga, ok? 😭

  • --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. She's just here to look, not to touch. πŸ‘€
  • --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 value value.

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.) Character-for-character important, bestie, don't freehand it. πŸŽ€

  • --arg-from-file name path β€” pass the contents of file path as the argument name to Nix functions. File-based, very organized of you. πŸ“
  • --arg-from-stdin name β€” pass the contents of stdin as the argument name to Nix functions. Pipe it straight in, no middleman. 🫢
  • --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 to keep the shell happy) you can say --argstr system i686-linux. Same energy, less escaping drama. ✨
  • --attr / -A attrPath β€” select 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. Yes, zero-indexed, bestie, count like a programmer. πŸ”’

  • --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. She's gotta have a home base. 🏠
  • --expr / -E β€” 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. (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. Two different girlies, two different jobs. πŸ’…

  • -I / --include path β€” add 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. She said my paths first, periodt. πŸ‘‘

  • --impure β€” allow access to mutable paths and repositories. Living dangerously, we love that for her. 🌈
  • --option name value β€” set the Nix configuration option name to value. This overrides settings in the Nix configuration file (see nix.conf5). Runtime override, main character energy. ⭐
  • --repair β€” 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 nix-store --repair-path. Healing era but make it computationally expensive. 😭
Note πŸ“Œ See man nix.conf for overriding configuration settings with command line flags.

🌸 Common Environment Variables 🌸

Okay so bestie, most Nix commands read these environment variables. Think of them as the group chat every command is secretly lurking in. πŸ’¬βœ¨


βš™οΈ Configuration environment variables πŸŽ€

These ones decide how Nix loads its config. Full deets live in the configuration file documentation, so go read that if you want the whole story. πŸ“–

  • NIX_CONF_DIR β€” overrides the system configuration directory.
  • NIX_USER_CONF_FILES β€” overrides where the user configuration files live.
  • NIX_CONFIG β€” lets you provide configuration settings inline. no file, just vibes.

πŸ›’ Store setting environment variables πŸ’Ύ

  • NIX_IGNORE_SYMLINK_STORE β€” bestie, listen. Normally the Nix store directory (typically /nix/store) is not allowed to contain any symlink components. Why? To prevent "impure" builds. See, builders sometimes "canonicalise" paths by resolving all symlink components. So builds on different machines (where /nix/store resolves to different locations) could yield different results. 😭 Normally that's chill β€” except when builds get deployed to machines where /nix/store resolves differently. If you are sure you're not going to do that, you can set NIX_IGNORE_SYMLINK_STORE to 1.

And note β€” if you're symlinking the Nix store so you can put it on another file system than the root file system, on Linux you're genuinely better off using bind mount points, like this:

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

Then go consult the mount 8 manual page for the details. 🫢

  • NIX_STORE_DIR β€” overrides the location of the Nix store. 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, so the default is %PROGRAMDATA%\nix\store, determined at runtime using the %PROGRAMDATA% Known Folder. πŸͺŸ

Peep the Store Types chapter β€” every store has a store setting linking back to this as its default.

  • 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 there's no compile-time setting, so 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. no cap.

  • 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 defaulting to /nix/var. On Windows there's no compile-time setting, so the default is %PROGRAMDATA%\nix\state, determined at runtime using the %PROGRAMDATA% Known Folder.

Again: the Local Store, Local Daemon Store, and Experimental SSH Store with filesystem mounted have per-store settings that override this. πŸ’…

  • NIX_DAEMON_SOCKET_PATH β€” overrides the path to the Unix domain socket used to communicate with the Nix daemon. Defaults to daemon-socket/socket within the state directory (scroll up for NIX_STATE_DIR πŸ’–).

See the Local Daemon Store documentation for details on how the socket path is resolved.

  • TMPDIR β€” use this specified directory to store temporary files. In particular this includes temporary build directories, and those can take up substantial amounts of disk space, fr fr. The default is /tmp.
  • NIX_REMOTE β€” overrides the store setting.

🧠 Nix language evaluator settings 🌈

  • NIX_SHOW_STATS β€” if set to 1, Nix will print some evaluation statistics, like the number of values allocated. little receipts, obsessed. ✨
  • NIX_COUNT_CALLS β€” if set to 1, Nix will print how often functions were called during Nix expression evaluation. Super useful for profiling your Nix expressions. πŸ”₯
  • GC_INITIAL_HEAP_SIZE β€” 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. πŸ—‘οΈ trade-offs, we love her.
  • 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, and it can be extended using the -I option. πŸ’«

Example:

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

If NIX_PATH is set to an empty string, resolving search paths will always fail. πŸ’€ screaming.

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 the locations for those directories:

  • [user configuration directory]{#user-conf-dir}: [NIX_CONFIG_HOME]{#env-NIXCONFIGHOME}
  • user state directory: [NIX_STATE_HOME]{#env-NIXSTATEHOME}
  • user cache directory: [NIX_CACHE_HOME]{#env-NIXCACHEHOME}

When these are not set, the defaults depend on the 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

For backwards compatibility, legacy Nix commands (e.g. nix-env, nix-channel) use dotfiles in $HOME instead of these directories β€” unless use-xdg-base-directories is enabled. New Nix commands (experimental) use the proper directories by default. the glow-up is real. πŸ‘‘

When use-xdg-base-directories is enabled, the configuration directory is resolved as:

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

Likewise for the state and cache directories. symmetry, we adore her. πŸ’œ


🎲 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 🌍

Heads up bestie β€” this info is not Nix-specific, it's just referenced above. 🫢

🐧 Unix: XDG Base Directories

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

The following environment variables are used:

  • [XDG_CONFIG_HOME]{#env-XDGCONFIGHOME} (default ~/.config)
  • [XDG_STATE_HOME]{#env-XDGSTATEHOME} (default ~/.local/state)
  • [XDG_CACHE_HOME]{#env-XDGCACHEHOME} (default ~/.cache)
  • [XDG_CONFIG_DIRS]{#env-XDGCONFIGDIRS} (default /etc/xdg) β€” colon-separated list of additional configuration base directories, searched after XDG_CONFIG_HOME

πŸͺŸ Windows: Known Folders

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

The relevant folders are:

  • [%APPDATA%]{#env-APPDATA} β€” per-user roaming application data
  • [%LOCALAPPDATA%]{#env-LOCALAPPDATA} β€” per-user local application data
  • [%PROGRAMDATA%]{#env-PROGRAMDATA} β€” system-wide application data

and that's the whole page, bestie!! πŸ’– πŸ¦‹ no more sections, no secrets, you've officially read every single line. and per the footer, this is the nix-store ...y-cache-key(1) page β€” that's the source/version-and-date line chillin' at the very bottom, serving as our lil sign-off. mwah. πŸ’…πŸŽ€πŸŒΈ

πŸ“¦ where this page comes from