NIX-STORE-ADD(1)
π NAME π
nix-store --add β bestie, it adds paths to the Nix store, that's the whole vibe β¨
π¦ SYNOPSIS π¦
nix-store --add pathsβ¦
πΈ DESCRIPTION πΈ
Okay so the --add operation takes the paths you give it and drops them into the Nix store. Then it prints the resulting store paths right to standard output, so you can copy them or pipe them or whatever your little heart desires π
And here's the tea: paths that point at symlinks are not dereferenced. Nope. They get added to the store as symlinks, keeping the exact same target. No cap, that's just how it is π«Ά
β¨ OPTIONS β¨
The options below are allowed for all nix-store operations, but ngl they might not always actually do anything. It's giving "permission granted, effect optional" π
--add-rootpath β makes the result of a realisation (--realiseand--force-realise) get registered as a root of the garbage collector. Here's the deal: path gets created as a symlink pointing to the resulting store path. And on top of that, a uniquely named symlink to path gets created over in/nix/var/nix/gcroots/auto/. For instance π
$ 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 like, when /home/eelco/bla/result gets removed, the GC root in the auto directory turns into a dangling symlink and the collector justβ¦ ignores it. Iconic behaviour honestly β¨
β οΈ Warning β οΈ β bestie, hear me on this one: it is not possible to move or rename GC roots, because the symlink sitting in the auto directory will still be pointing at the old location. It's committed to that path. Loyal to a fault π
And if there are multiple results, then multiple symlinks get created β beyond the first one they're numbered sequentially (foo, foo-2, foo-3, and so on). Cute little queue of links π
β¨ Common Options β¨
okay bestie, so most Nix commands are gonna hand you this exact same pile of command-line options, and honestly they carry the whole operation. let's go one by one, no skipping, no skimming, we're eating this whole plate π½οΈ
--helpβ prints a lil summary of the command syntax and then leaves. that's it, that's the whole thing.--versionβ prints the Nix version number on standard output and exits. short king behavior.--verbose,-vβ turns the volume UP on the diagnostic messages that get printed to standard error. and here's the tea: for every Nix operation, whatever goes to standard output is well-defined and clean β all the diagnostic stuff goes to standard error, never to standard output. no mixing, no crossover π
You can pass this option over and over, and it stacks. The verbosity levels that currently exist are:
0βErrors onlyβ β only prints the messages telling you why the Nix invocation failed. cold. minimal. slightly ominous.1βInformationalβ β prints actually useful messages about what Nix is doing. this is the default, so if you didn't touch anything, congrats, you're here.2βTalkativeβ β prints more informational messages.3βChattyβ β prints even MORE informational messages.4βDebugβ β prints debug information.5βVomitβ β prints a vast, truly unhinged amount of debug information. π
--quietβ turns the volume DOWN on diagnostic messages on standard error. it's literally the inverse of-v/--verbose.
Same deal as the loud one: you can pass it repeatedly, and it walks back through that verbosity levels list from above.
--log-formatformat β changes how the log output is formatted, where format is one of these cuties:rawβ the raw format, exactly as outputted bynix-build.internal-jsonβ outputs the logs in a structured way.
Warning β οΈ the schema itself is comparatively stable, but the format of the error-messages (specifically the msg-field) can change between releases. so like, plan accordingly bestie.
barβ only shows a progress bar while the builds are happening.bar-with-logsβ shows the raw logs, with the progress bar chilling at the bottom.
--no-build-output,-Qβ by default, anything the builders write to standard output and standard error gets echoed to the Nix command's standard error. this option shuts that behavior down. but heads up: the builder's stdout and stderr are always written to a log file inprefix/nix/var/log/nix, whether you like it or not.--max-jobs,-jnumber β sets the max number of build jobs Nix will run in parallel to number. passautoand it'll use however many CPUs the system has. the default comes from themax-jobsconfiguration setting, which itself defaults to1. a higher value is genuinely useful on SMP systems, or if you're tryna exploit I/O latency.
Set it to 0 and building on the local machine is disallowed β which is exactly what you want when builds should only happen on remote builders. bye local, hello remote βοΈ
--coresβ sets the value of theNIX_BUILD_CORESenvironment variable in the invocation of builders. builders can use it however they want to cap their parallelism β for example, in Nixpkgs, if the derivation attributeenableParallelBuildingis set totrue, the builder passes the-jNflag to GNU Make. The default is the value of thecoresconfiguration setting if it's set, and1otherwise. the value0means the builder should use all the CPU cores available on the system. go big or go home fr.--max-silent-timeβ sets the max number of seconds a builder can go without producing any data at all on standard output or standard error. default is whatever themax-silent-timeconfiguration setting says.0means no time-out. silence is fine actually.--timeoutβ sets the max number of seconds a builder can run. default is whatever thetimeoutconfiguration setting says.0means no timeout.--keep-going,-kβ keeps going after failed builds, to the greatest extent possible. meaning: if building an input of some derivation fails, Nix will still build the other inputs β just not the derivation itself. without this option, Nix stops the second any build fails (except builds of substitutes) and might straight-up kill builds that are in progress, especially with parallel or distributed builds. πͺ--keep-failed,-Kβ says that when a build fails, the temporary directory where the build happened (usually somewhere in/tmp) should not be deleted. the path of the build directory gets printed as an informational message so you can go poke around in it.--fallbackβ whenever Nix tries to build a derivation where substitutes are known for each output path, but realizing those output paths through the substitutes fails, it falls back on actually building the derivation.
The most common scenario where this saves you: you've registered substitutes so you can do binary distribution from, say, a network repository. if that repository is down, realizing the derivation fails. with this option on, Nix builds the derivation instead β so installing from binaries falls back on installing from source. This is not the default, because it's generally not desirable for some transient failure in fetching substitutes to snowball into a full build from source with all the resources that eats. πΈ
--readonly-modeβ with this on, no attempt is made to open the Nix database. most Nix operations do need database access, so those operations will just fail. it's giving "read only, do not perceive me" π--argname value β accepted bynix-env,nix-instantiate,nix-shellandnix-build. When it evaluates Nix expressions, the evaluator automatically tries to call functions it runs into. It can automatically call functions where every argument has a default value (like{ argName ? defaultValue }: ...).
With --arg, you can also call functions that have arguments without a default value (or override a default value). So if the evaluator hits a function with an argument named name, it calls 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 when you call this Nix expression (like when you do nix-env --install --attr pkgname), the function gets called automatically using the value builtins.currentSystem for the system argument. You can override that with --arg, e.g. nix-env --install --attr pkgname --arg system \"i686-freebsd\". (and note: because the argument is a Nix string literal, you gotta escape the quotes. don't forget or the shell will be weird about it π)
--arg-from-filename path β passes the contents of file path as the argument name to Nix functions.--arg-from-stdinname β passes the contents of stdin as the argument name to Nix functions.--argstrname value β just like--arg, except the value isn't a Nix expression, it's a string. so instead of--arg system \"i686-linux\"(the outer quotes are there to keep the shell happy), you can just say--argstr system i686-linux. way less escaping drama.--attr,-AattrPath β selects 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 example, given a top-level Nix expressione, the attribute pathxorg.xorgserverwould cause the expressione.xorg.xorgserverto be used. peepnix-env --installfor some concrete examples.
Besides 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, fourth β it's zero-indexed babes, stay sharp π₯)
--eval-storestore-url β the URL to the Nix store to use for evaluation, i.e. where to store derivations (.drvfiles) and the inputs referenced by them.--expr,-Eβ interprets the command line arguments as a list of Nix expressions to parse and evaluate, rather than as a list of file names of Nix expressions. (nix-instantiate,nix-buildandnix-shellonly.)
For nix-shell, this is commonly used to give you a shell where you can build the packages returned by the expression. If you want a shell that already contains the built packages, ready to use, hand your expression to the nix-shell --packages convenience flag instead. two different vibes, pick your fighter.
-I,--includepath β adds an entry to the list of search paths used to resolve lookup paths. You can give this option multiple times.
Paths added through -I take precedence over the nix-path configuration setting and over the NIX_PATH environment variable. they said "priority" and they meant it π
--impureβ allows access to mutable paths and repositories. messy, but make it fashion.--optionname value β sets the Nix configuration option name to value. This overrides settings in the Nix configuration file (checknix.conf5).--repairβ fixes corrupted or missing store paths by redownloading or rebuilding them. Warning 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 undernix-store --repair-path. this one is not a quick lil errand, it's a whole thing π’
Note: see man nix.conf for overriding configuration settings with command line flags.
π Common Environment Variables π
okay bestie, most Nix commands literally read these environment variables, so if something is acting weird and you can't figure out why, check here first fr fr π
π Configuration environment variables
These cuties decide how Nix loads its config. Full deets live in the configuration file documentation, but here's the vibe:
NIX_CONF_DIRβ overrides where the system configuration directory lives. slay.NIX_USER_CONF_FILESβ overrides where the user configuration files hang out.NIX_CONFIGβ lets you drop configuration settings inline, no file needed. iconic β¨
ποΈ Store setting environment variables
NIX_IGNORE_SYMLINK_STOREβ normally the Nix store directory (typically/nix/store) is not allowed to contain any symlink components, and that's on purpose: it stops "impure" builds. here's why, no cap β builders sometimes "canonicalise" paths by resolving all symlink components, so builds on different machines (where/nix/storeresolves to different locations) could yield different results. Usually that's not a problem, except when builds get deployed to machines where/nix/storeresolves differently. If you're 100% sure you're not going to do that, you can setNIX_IGNORE_SYMLINK_STOREto1.
heads up bestie π if you're symlinking the Nix store so you can park it on another file system than the root file system, then on Linux you're way better off using bind mount points, like:
$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix
and go consult the mount(8) manual page for the details, mwah π«Ά
NIX_STORE_DIRβ overrides where the Nix store lives. On Unix the default is/nix/store, set at compile time by thelibstore:store-dirbuild option. On Windows there's no compile-time setting; the default is%PROGRAMDATA%\nix\store, determined at runtime using the%PROGRAMDATA%Known Folder.
See the Store Types chapter β each store has a store setting that links back to this as its default. cute, right? π
NIX_LOG_DIRβ overrides where the Nix log directory lives. 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; 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 layers omg π
NIX_STATE_DIRβ overrides where the Nix state directory lives. 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; the default is%PROGRAMDATA%\nix\state, determined at runtime using the%PROGRAMDATA%Known Folder.
Same deal as above: 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 talk to the Nix daemon πΈ it defaults todaemon-socket/socketwithin the state directory (peepNIX_STATE_DIR). See the Local Daemon Store documentation for how the socket path actually gets resolved.TMPDIRβ use this directory to store temporary files. Specifically this includes temporary build directories, and those can eat up substantial amounts of disk space, so choose wisely bestie π the default is/tmp.NIX_REMOTEβ overrides the store setting. that's it, that's the whole thing.
π§ Nix language evaluator settings
NIX_SHOW_STATSβ if you set it to1, Nix prints some evaluation statistics, like the number of values allocated. numbers go brrr πNIX_COUNT_CALLSβ if you set it to1, Nix prints how often functions were called during Nix expression evaluation. lowkey super useful for profiling your Nix expressions π₯GC_INITIAL_HEAP_SIZEβ if Nix was configured to use the Boehm garbage collector, this sets the initial size of the heap in bytes, and it defaults to 384 MiB. setting it low reduces memory consumption, but will increase runtime because of garbage collection overhead (the classic trade-off, rip π).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.
It can be extended using the -I option π
Example
$ export NIX_PATH=/home/eelco/Dev:nixos-config=/etc/nixos
and here's the spicy bit: if NIX_PATH is set to an empty string, resolving search paths will always fail.
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)
yeah. she's dramatic like that π
π User Directories
Nix does per-user configuration, state, and cache directories, because everyone deserves their own little corner of the filesystem π«Ά these environment variables override where those directories go:
- [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 aren't 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. glow up era β
When use-xdg-base-directories is enabled, the configuration directory is resolved like this:
$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. same energy, different folders π
π² Miscellaneous environment variables
IN_NIX_SHELLβ an indicator that tells you if the current environment was set up bynix-shell. It can have the valuespureorimpure. yes queen, know your vibe check β¨
π¦ Appendix: OS-specific conventions π¦
ngl this info isn't Nix-specific, but it got referenced up above, so here it is for completeness π
π§ Unix: XDG Base Directories
The XDG Base Directory Specification defines standard locations for user-specific configuration, state, and cache files on Unix systems.
These environment variables are the ones in play:
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) β a 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.
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
β¨ Example β¨
here's the moment you've been waiting for, bestie π
$ nix-store --add ./foo.c
/nix/store/m7lrha58ph6rcnv109yzx1nk1cj7k7zf-foo.c
ate, no crumbs π
and that's a wrap on nix-store --add(1) π huge thanks to the source/version and date info living in the footer, and to everyone who keeps documenting this stuff β y'all are the main characters fr fr. go forth and add your store paths, queen ππ
π¦ 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