NIX-STORE-SERVE(1)
β¨ nix-store --serve(1) β¨
okay bestie, gather round, because we're about to talk about the manual page for nix-store --serve from the General Commands Manual. yes, THAT one. the ssh-flavoured one. let's get into it π
πΈ Name πΈ
nix-store --serve β serve local Nix store over SSH π¦
π Synopsis π
nix-store --serve [--write]
likeβ¦ that's it. that's the whole vibe. two words and a maybe-flag. iconic honestly β¨
π Description π
so the --serve operation is basically your store's little customer service desk π«Ά. It hands out access to the Nix store over stdin and stdout, and the whole point of it is to give Nix store access to a restricted ssh user. yes. a restricted one. we're being polite and also locked down. the duality π
The following flags are available:
--writeβ lets the connected client ask for derivations to actually get realized. In effect, this can be used to make the host act as a remote builder. it's giving "you can build here, bestie" π₯
β¨ Options β¨
heads up! these options are allowed for all nix-store operations, but ngl they might not always do anything. they're invited to the party, not guaranteed to dance π
--add-rootpath β this one makes the result of a realisation (--realiseand--force-realise) get registered as a root of the garbage collector. path gets created as a symlink pointing at the resulting store path. AND, as a little bonus, 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 the way that works is π: when /home/eelco/bla/result gets removed, the GC root sitting in the auto directory turns into a dangling symlink and the collector will justβ¦ ignore it. ghosted, fr fr π«₯
β οΈ Warning β οΈ bestie, listen. 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. it does not care about your rebrand. it does not follow you to the new place. π
If there are multiple results, then multiple symlinks will be created, and anything past the first one gets numbered sequentially β like foo, foo-2, foo-3, and so on. slay, they're a set now π
okay that's the options section β more of this page is coming, don't go anywhere, we're not done yet π
β¨ Common Options β¨
Okay bestie, so most Nix commands take these same command-line options, and they're the bread and butter of literally everything. Let's go one by one π«Ά
--helpβ prints out a lil summary of the command syntax and then exits. That's it, that's the whole vibe.--versionβ prints the Nix version number to standard output and exits. Iconic, brief, no notes.--verbose,-vβ turns up the volume on diagnostic messages that get printed to standard error. Here's the tea: for every Nix operation, the stuff printed to standard output is well-defined, and any diagnostic info goes to standard error, never to standard output. No cap.
You can pass this flag over and over to keep cranking it up. Right now these are the verbosity levels that exist:
- 0 β "Errors only" β only prints messages explaining why your Nix invocation flaked out π
- 1 β "Informational" β prints useful messages about what Nix is doing. This is the default, so it's the baseline main-character setting.
- 2 β "Talkative" β more informational messages, she's chatty now.
- 3 β "Chatty" β even more informational messages, at this point she's telling you everything.
- 4 β "Debug" β prints debug information π
- 5 β "Vomit" β prints vast amounts of debug information. Truly it's giving everything everywhere all at once.
--quietβ turns the volume down on those diagnostic messages on standard error. It's literally the inverse option to-v/--verbose. You can also stack this one repeatedly β same verbosity levels list as above, just walkin' backwards π--log-formatformat β changes how the log output looks. format has to be one of these:rawβ the raw format, exactly as outputted bynix-build.internal-jsonβ spits the logs out in a structured way.
β οΈ Warning β the schema itself is relatively stable, but the format of the error-messages (namely of the msg-field) can totally change between releases. Don't get attached.
barβ only shows a progress bar while the builds are happening. That's the whole display.bar-with-logsβ shows the raw logs, with the progress bar chillin' at the bottom.
--no-build-output,-Qβ by default, whatever the builders write to standard output and standard error gets echoed to the Nix command's standard error. This option shuts that behaviour down. But heads up: the builder's standard output and error are always written to a log file inprefix/nix/var/log/nix, so nothing's actually lost π--max-jobs,-jnumber β sets the max number of build jobs Nix will do in parallel to whatever number you give it. You can passautoto use the number of CPUs in the system. The default comes from themax-jobsconfiguration setting, which itself defaults to1. A higher value is useful on SMP systems or to exploit I/O latency. And setting it to0disallows building on the local machine, which slays when you want builds to happen only on remote builders π₯--coresβ sets the value of theNIX_BUILD_CORESenvironment variable when builders get invoked. Builders can use that variable however they want 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 that's set, or1otherwise. And the value0means the builder should use all the available CPU cores in the system. Go big π§--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 themax-silent-timeconfiguration setting.0means no time-out at all, live your truth.--timeoutβ sets the maximum number of seconds a builder can run. The default is specified by thetimeoutconfiguration setting.0means no timeout.--keep-going,-kβ keeps going when builds fail, to the greatest extent possible. So like, 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 for builds of substitutes), and it might even kill builds that are in progress in the case of parallel or distributed builds. Chaos behavior avoided π--keep-failed,-Kβ says that if a build fails, the temporary directory where the build took place (usually in/tmp) should not be deleted. The path of the build directory gets printed as an informational message, so you can go snoop.--fallbackβ whenever Nix tries to build a derivation where substitutes are known for each output path, but realising those output paths through the substitutes fails, it falls back on actually building the derivation.
The most common scenario where this is useful is when you've registered substitutes to do binary distribution from, say, a network repository. If the repository is down, realising the derivation will fail. With this option, Nix builds the derivation instead. So installation from binaries falls back on installation from source. It's not the default, because it's generally not desirable for a transient failure in getting the substitutes to lead to a full build from source (with all the related resource consumption that comes with it). Expensive queen behavior, so it's opt-in πΈ
--readonly-modeβ when this is used, no attempt is made to open the Nix database. Most Nix operations do need database access, so those operations will just fail. Lowkey a locked-door situation πͺ--argname value β accepted bynix-env,nix-instantiate,nix-shellandnix-build. When evaluating Nix expressions, the expression evaluator automatically tries to call functions that it encounters. It can automatically call functions where 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). So if the evaluator encounters a function with an argument named name, it'll call it with 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 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\". (Note that since the argument is a Nix string literal, you have to escape the quotes. Yes, really.)
--arg-from-filename path β passes the contents of the file path as the argument name to Nix functions. File girlies rise π--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\"(those 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 instance, given a top-level Nix expressione, the attribute pathxorg.xorgserverwould cause the expressione.xorg.xorgserverto be used. Seenix-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 β 0 is the first one, that's just how it is π
)
--eval-storestore-url β the URL of the Nix store to use for evaluation, i.e. where to store derivations (.drvfiles) and inputs referenced by them.--expr,-Eβ interprets the command line arguments as a list of Nix expressions to be parsed and evaluated, instead of 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 a shell that contains the built packages ready to use, hand your expression to the nix-shell --packages convenience flag instead. Different vibe, different shell πΈ
-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-Itake precedence over thenix-pathconfiguration setting and theNIX_PATHenvironment variable. She jumps the queue, respectfully π--impureβ allows access to mutable paths and repositories. Wild child energy.--optionname value β sets the Nix configuration option name to value. This overrides settings in the Nix configuration file (seenix.conf5).--repairβ fixes 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. It's giving patience, bestie π
π Note β see man nix.conf for overriding configuration settings with command line flags.
π COMMON ENVIRONMENT VARIABLES π
okay bestie, so most Nix commands actually read these environment variables β they're not just decorative, they're load-bearing. π
βοΈ Configuration environment variables
These ones control how Nix loads its configuration β like, the vibe of where your settings even come from. Full deets live in the configuration file documentation, but here's the squad:
NIX_CONF_DIRβ overrides where the system configuration directory lives.NIX_USER_CONF_FILESβ overrides the locations of the user configuration files.NIX_CONFIGβ lets you hand Nix configuration settings inline, right there in the variable. no file needed, we're doing this live π€
πͺ Store setting environment variables
NIX_IGNORE_SYMLINK_STOREβ okay so normally the Nix store directory (usually/nix/store) is not allowed to contain ANY symlink components, and that's on purpose: it keeps builds from being "impure". here's the tea β builders sometimes "canonicalise" paths by resolving all the symlink components, so builds on different machines (where/nix/storeresolves to different places) could produce different results. usually that's fine, EXCEPT when you deploy builds to machines where/nix/storeresolves somewhere else. If you're sure you're never gonna do that, you can setNIX_IGNORE_SYMLINK_STOREto1.
also: if you're symlinking the Nix store to park it on a different file system than root, on Linux you're way better off using bind mount points, like:
$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix
Consult the mount 8 manual page for 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 at all β the default is%PROGRAMDATA%\nix\store, figured out at runtime using the%PROGRAMDATA%Known Folder.
See the Store Types chapter β every store has a store setting that links 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, again, no compile-time setting: the default is%PROGRAMDATA%\nix\log, resolved at runtime via 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. π
NIX_STATE_DIRβ overrides the location of the Nix state directory. On Unix the default is${localstatedir}/nix, wherelocalstatediris a compile-time build option that defaults to/nix/var. On Windows: no compile-time setting, default is%PROGRAMDATA%\nix\state, resolved at runtime with the%PROGRAMDATA%Known Folder.
Same energy as above β 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 todaemon-socket/socketinside the state directory (that'sNIX_STATE_DIR, hello π).
See the Local Daemon Store documentation for the whole story on how the socket path gets resolved.
TMPDIRβ use this directory for temporary files. and yes, that includes temporary build directories, which can absolutely EAT your disk space, so choose wisely bestie. default is/tmp.NIX_REMOTEβ overrides the store setting.
π§ Nix language evaluator settings
NIX_SHOW_STATSβ set it to1and Nix prints out some evaluation statistics, like how many values got allocated. numbers! for the girls who love numbers πNIX_COUNT_CALLSβ set it to1and Nix prints how often functions were called during Nix expression evaluation. 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. defaults to384 MiB. Setting it low cuts memory consumption, but it'll slow you down at runtime because garbage collection overhead goes up. classic tradeoff π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
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)
ποΈ User Directories
Nix supports per-user configuration, state, and cache directories β yes bestie, it's giving organised β¨. These environment variables override where those directories live:
- 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 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 (like nix-env, nix-channel) use the 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 π
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. πΈ
π² Miscellaneous environment variables
IN_NIX_SHELLβ a little indicator telling you whether the current environment was set up bynix-shell. It can have the valuespureorimpure. the vibe check of shells π¦
π Appendix: OS-specific conventions
This info isn't Nix-specific, it's just referenced above. lowkey a bonus chapter for you π
π§ Unix: XDG Base Directories
The XDG Base Directory Specification defines standard locations for user-specific configuration, state, and cache files on Unix systems.
The environment variables in play:
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 afterXDG_CONFIG_HOME
πͺ Windows: Known Folders
On Windows, Known Folders provide standard locations for application data. the relevant ones:
%APPDATA%β per-user roaming application data%LOCALAPPDATA%β per-user local application data%PROGRAMDATA%β system-wide application data
π Examples
To turn a host into a build server, the authorized_keys file can be used to give build access to a given SSH public key. iconic setup, no cap π
$ cat <<EOF >>/root/.ssh/authorized_keys
command="nice -n20 nix-store --serve --write" ssh-rsa AAAAB3NzaC1yc2EAAAA...
EOF
and that's a wrap bestie!! π you just read the whole thing, root and branch β every flag, every variable, every path. this was nix-store --serve(1), straight from the Nix source (version and date are chillin' in the footer where they belong). go forth and --serve responsibly, 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