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:
- 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 likecache.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. π - The file name where the secret key is gonna be stored. π€«
- 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-rootpath β this makes the result of a realisation (--realiseand--force-realisespecifically) 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-formatformat β 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 bynix-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 inprefix/nix/var/log/nixβ like, you can't escape the receipts, bestie. π--max-jobs/-jnumber β sets the maximum number of build jobs that Nix will perform in parallel to the specified number. Specifyautoto use the number of CPUs in the system. The default is specified by themax-jobsconfiguration setting, which itself defaults to1. 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 theNIX_BUILD_CORESenvironment 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 attributeenableParallelBuildingis set totrue, the builder passes the-jNflag to GNU Make. It defaults to the value of thecoresconfiguration setting, if set, or1otherwise. The value0means 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 themax-silent-timeconfiguration setting.0means 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 thetimeoutconfiguration setting.0means 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. π--argname value β this option is accepted bynix-env,nix-instantiate,nix-shellandnix-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-filename path β pass the contents of file path as the argument name to Nix functions. File-based, very organized of you. π--arg-from-stdinname β pass the contents of stdin as the argument name to Nix functions. Pipe it straight in, no middleman. π«Ά--argstrname 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/-AattrPath β select an attribute from the top-level Nix expression being evaluated. (nix-env,nix-instantiate,nix-buildandnix-shellonly.) The attribute path attrPath is a sequence of attribute names separated by dots. For instance, given a top-level Nix expression e, the attribute pathxorg.xorgserverwould cause the expressione.xorg.xorgserverto be used. Seenix-env --installfor 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-storestore-url β the URL to the Nix store to use for evaluation, i.e. where to store derivations (.drvfiles) 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-buildandnix-shellonly.)
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/--includepath β 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. π--optionname value β set the Nix configuration option name to value. This overrides settings in the Nix configuration file (seenix.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 undernix-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/storeresolves to different locations) could yield different results. π Normally that's chill β except when builds get deployed to machines where/nix/storeresolves differently. If you are sure you're not going to do that, you can setNIX_IGNORE_SYMLINK_STOREto1.
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 thelibstore:store-dirbuild 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 thelog-dirbuild 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, wherelocalstatediris 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 todaemon-socket/socketwithin the state directory (scroll up forNIX_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 thestoresetting.
π§ Nix language evaluator settings π
NIX_SHOW_STATSβ if set to1, Nix will print some evaluation statistics, like the number of values allocated. little receipts, obsessed. β¨NIX_COUNT_CALLSβ if set to1, 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 to384 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 thenix-pathconfiguration setting, and it can be extended using the-Ioption. π«
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:
$NIX_CONFIG_HOME, if it is defined- Otherwise, the platform default (e.g.
$XDG_CONFIG_HOME/nixon 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 bynix-shell. It can have the valuespureorimpure.
π 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 afterXDG_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
- fedora 44: nix-legacy 2.35.3-2.fc44 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms