NIX-STORE-IMPORT(1)
π nix-store --import(1) β the manual page bestie π
okay so you're reading the manual for nix-store --import, and it lives in the General Commands Manual, and honestly? it's giving "I just want to move my store objects around, why is this so deep". but we're gonna get through it together π«Ά
β¨ NAME β¨
nix-store --import β import Nix Archive into the store πΈ
π SYNOPSIS π
nix-store --import
that's it. that's the whole vibe. no extra args, no little flags hanging off it. just the operation and vibes β¨
π DESCRIPTION π
okay so the --import operation is literally the bestie of nix-store --export. the way it works: it reads a serialisation of a set of store objects β the kinda thing nix-store --export produces β from standard input, and then it just adds those store objects to the specified Nix store. slay. iconic. it does exactly what it says on the tin π
now here's the important bits, no cap:
- paths that already exist in the target Nix store? ignored. it's like "oh you're already here? ok periodt, moving on π "
- but if a path refers to another path that doesn't exist in the target Nix store? the import fails. π like fully fails. no partial rescue arc. so make sure your closure is complete before you send it off, bestie.
π Note: for the efficient transfer of closures to remote machines over SSH β and by efficient I mean the good way, the blessed way β use nix-copy-closure. don't do the manual thing when there's a whole tool for it. iykyk.
β OPTIONS β
so here's the thing. these options are allowed for all nix-store operations, but ngl they may not always have an effect. depends on the operation, babe. so don't come for me if you pass one and nothing happens π
--add-rootpath β okay so this one causes the result of a realisation (that's--realiseand--force-realise, if you're keeping track) to be registered as a root of the garbage collector. so like, you're telling the GC "hey bestie, hands off this one π"
path itself gets created as a symlink pointing to the resulting store path. and then β plot twist β a uniquely named symlink to path also gets created in /nix/var/nix/gcroots/auto/. it's giving double symlink energy. 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
and the way this works out is kind of iconic actually: when /home/eelco/bla/result is removed, the GC root in the auto directory becomes a dangling symlink and the collector ignores it. so it self-cleans. no manual garbage. we love that for us π
β οΈ Warning: it is not possible to move or rename GC roots β the symlink in the auto directory will still point to the old location. so like, don't try it. it will not work. it's a trap. /nix/var/nix/gcroots/auto/ has main character energy and it will not be relocating for you π
and if there's multiple results? then multiple symlinks get created β the ones beyond the first get sequentially numbered, e.g. foo, foo-2, foo-3, and so on. go off, numbered symlinks π
π COMMON OPTIONS π
okay so basically every Nix command is gonna accept these bad boys. like, this is the shared lore, the group chat everyone's in. bestie, take notes π
--helpβ prints a lil summary of how to use the command and then dips. that's it, that's the whole vibe.--versionβ spits out the Nix version number on standard output and bounces. iconic behavior honestly.--verbose/-vβ turns the volume UP on diagnostic messages, which get printed to standard error. here's the tea: for every Nix operation, whatever goes to standard output is well-defined and clean β all the messy diagnostic stuff goes to standard error, never standard output. periodt.
you can stack this flag as many times as you want. currently the verbosity levels are:
- 0 βErrors onlyβ β only prints messages explaining why the Nix invocation failed. like, it literally only speaks up when something's wrong π
- 1 βInformationalβ β prints useful messages about what Nix is doing. this is the default, the moment, the baseline π
- 2 βTalkativeβ β more informational messages. she's chatty now.
- 3 βChattyβ β even more informational messages. someone get her a mic.
- 4 βDebugβ β prints debug information. nerd hours π¬
- 5 βVomitβ β prints vast amounts of debug information. yes that's the real name. it's giving firehose. π
--quietβ turns the volume DOWN on diagnostic messages on standard error. it's the inverse option to-v/--verbose. you can stack this one too, over and over. same verbosity levels list as above, just read it backwards β¨- *
--log-format*format β lets you change what the log output actually looks like. format has to be one of these:rawβ the raw format, exactly as outputted bynix-build.internal-jsonβ outputs the logs in a structured manner. very organized, very demure.
Warning β οΈ β the schema itself is relatively stable, but the format of the error messages (specifically the msg field) can change between releases. so like, don't hardcode your whole personality around it, iykyk.
barβ only displays a progress bar during the builds. minimal. aesthetic. no thoughts, just bar. πbar-with-logsβ displays the raw logs, but with the progress bar chilling at the bottom. best of both worlds fr fr.
--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 suppresses that whole behavior. but heads up: the builder's standard output and error are always written to a log file inprefix/nix/var/log/nix, no matter what. so nothing's actually lost, she's just being quiet about it. π- *
--max-jobs/-j*number β sets the max number of build jobs Nix will do in parallel to that number. you can sayautoto just use however many CPUs the system has. the default comes from themax-jobsconfiguration setting, which itself defaults to1. cranking it higher is useful on SMP systems or to exploit I/O latency (yes, exploiting latency, we love a resourceful queen). setting it to0disallows building on the local machine entirely β which is exactly what you want when builds should only happen on remote builders. ποΈ --coresβ sets the value of theNIX_BUILD_CORESenvironment variable in the invocation of builders. builders can use that variable however they want to control max 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 available CPU cores on the system. go big or go home πͺ--max-silent-timeβ sets the max 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. silent treatment not tolerated π«₯--timeoutβ sets the max number of seconds a builder can run, total. default comes from 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 moment any build fails (except for builds of substitutes), possibly killing builds that are already in progress, which is especially dramatic with parallel or distributed builds. π--keep-failed/-Kβ says that if a build fails, the temporary directory where the build happened (usually in/tmp) should not be deleted. the path of the build directory gets printed as an informational message. keep your receipts bestie π§Ύ--fallbackβ whenever Nix tries to build a derivation for which substitutes are known for each output path, but realising those output paths through the substitutes fails, it falls back on building the derivation instead.
the most common scenario where this saves you: you've got registered substitutes so you can do binary distribution from, say, a network repository. if the repo is down, realising the derivation will fail. with this option, Nix just builds the derivation instead. so installation from binaries falls back on installation from source. π¦
this is not the default, and there's a reason β it's generally not desirable for a transient failure in getting substitutes to snowball into a full build from source, with all the related resource consumption. lowkey understandable ngl.
--readonly-modeβ when this is on, no attempt is made to open the Nix database. and since most Nix operations do need database access, those operations will fail. so like, use this knowingly. π«- *
--arg*name value β this one is accepted bynix-env,nix-instantiate,nix-shellandnix-build. when evaluating Nix expressions, the expression evaluator will automatically try to call functions 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 gotta escape the quotes. don't forget, bestie, or the shell will simply eat them π½οΈ)
- *
--arg-from-file*name path β passes the contents of the file path as the argument name to Nix functions. file-based, very organized β¨ - *
--arg-from-stdin*name β passes the contents of stdin as the argument name to Nix functions. piping it straight from the source π - *
--argstr*name value β same as--arg, except the value is not a Nix expression, it's a string. so instead of--arg system "i686-linux"(the outer quotes are just to keep the shell happy), you can say--argstr system i686-linux. so much less escaping drama π - *
--attr/-A*attrPath β 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 β zero-indexed, we're counting from 0 like the computer girlies we are π’)
--eval-storestore-url β the URL of 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 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. but if you want a shell that contains the built packages, ready to use, you should hand your expression to the nix-shell --packages convenience flag instead. different vibe, pick your fighter π₯
- *
-I/--include*path β adds an entry to the list of search paths used to resolve lookup paths. this option can be given multiple times. paths added through-Itake precedence over thenix-pathconfiguration setting and theNIX_PATHenvironment variable. so she's the main character, she goes first. π --impureβ allows access to mutable paths and repositories. chaotic energy, but consensually. π₯- *
--option*name 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. β οΈ fair warning: this is slow, because it requires computing a cryptographic hash of the contents of every path in the closure of the build. also please go read the warning undernix-store --repair-path, seriously, it matters. π¨
Note π β see man nix.conf for overriding configuration settings with command line flags.
π Common Environment Variables π
Okay bestie, this is the part where Nix reads your vibe β I mean, your env vars π Most Nix commands interpret the ones below, so β¨ pay attention β¨
βοΈ Configuration environment variables
These decide how Nix loads its configuration. The configuration file documentation has the full tea π΅
NIX_CONF_DIRβ overrides the system configuration directory.NIX_USER_CONF_FILESβ overrides the user configuration file locations.NIX_CONFIGβ provides configuration settings inline. slay, no file needed β¨
π Store setting environment variables
NIX_IGNORE_SYMLINK_STOREβ okay so normally, the Nix store directory (typically/nix/store) is not allowed to contain any symlink components. That rule exists to prevent "impure" builds, because builders sometimes "canonicalise" paths by resolving all symlink components π so builds on different machines (with/nix/storeresolving to different locations) could yield different results. Generally that's not a problem β except when builds are deployed to machines where/nix/storeresolves differently. If you're sure you're not gonna do that, you can setNIX_IGNORE_SYMLINK_STOREto1. π
Note that if you're symlinking the Nix store so that you can put it on another file system than the root file system, on Linux you're better off using bind mount points, e.g.
$ 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; 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 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; 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 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 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. 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 (seeNIX_STATE_DIR). See the Local Daemon Store documentation for details on how the socket path is resolved.TMPDIRβ use the specified directory to store temporary files. In particular this includes temporary build directories, and bestie, those can take up substantial amounts of disk space π The default is/tmp.NIX_REMOTEβ overrides the store setting.
π§ Nix language evaluator settings
NIX_SHOW_STATSβ if set to1, Nix will print some evaluation statistics, such as the number of values allocated π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 ποΈ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. 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 π
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 π«Ά The following environment variables override the locations for these 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 π
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. π
π Miscellaneous environment variables
IN_NIX_SHELLβ an indicator that tells if the current environment was set up bynix-shell. It can have the valuespureorimpureπ
π Appendix: OS-specific conventions
Just so you know, this information 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~/.configXDG_STATE_HOME(#env-XDGSTATEHOME) β default~/.local/stateXDG_CACHE_HOME(#env-XDGCACHEHOME) β default~/.cacheXDG_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 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
β¨ Examples β¨
Example: given a closure of GNU Hello as a file:
$ storePath="$(nix-build '<nixpkgs>' -I nixpkgs=channel:nixpkgs-unstable -A hello --no-out-link)"
$ nix-store --export $(nix-store --query --requisites $storePath) > hello.closure
Import the closure into a remote SSH store using the --store option:
$ nix-store --import --store ssh://alice@itchy.example.org < hello.closure
aaaand that's the whole entire nix-store --import(1) page bestie ππ every last env var, every anchor, every last drop. go forth and import your closures with main character energy π you ate, no cap π¦
π¦ 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