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-root path β€” okay so this one causes the result of a realisation (that's --realise and --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 by nix-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 in prefix/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 say auto to just use however many CPUs the system has. the default comes from the max-jobs configuration setting, which itself defaults to 1. cranking it higher is useful on SMP systems or to exploit I/O latency (yes, exploiting latency, we love a resourceful queen). setting it to 0 disallows 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 the NIX_BUILD_CORES environment 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 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 that's set, or 1 otherwise. and the value 0 means 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 the max-silent-time configuration setting. 0 means no time-out. silent treatment not tolerated πŸ«₯
  • --timeout β€” sets the max number of seconds a builder can run, total. default comes from the timeout configuration setting. 0 means 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 by nix-env, nix-instantiate, nix-shell and nix-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-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. πŸ’…

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-store store-url β€” the URL of the Nix store to use for **evaluation, i.e. where to store derivations (.drv files) 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-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. 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 -I take precedence over the nix-path configuration setting and the NIX_PATH environment 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 (see nix.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 under nix-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/store resolving to different locations) could yield different results. Generally that's not a problem β€” except when builds are deployed to machines where /nix/store resolves differently. If you're sure you're not gonna do that, you can set NIX_IGNORE_SYMLINK_STORE to 1. πŸ’…
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 the libstore:store-dir build 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 the log-dir build 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, where localstatedir is 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 to daemon-socket/socket within the state directory (see NIX_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 to 1, Nix will print some evaluation statistics, such as the number of values allocated πŸ“Š
  • 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 πŸ—‘οΈ
  • 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 🫢 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:

  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. πŸ’…

πŸŽ€ Miscellaneous environment variables

  • IN_NIX_SHELL β€” an indicator that tells if the current environment was set up by nix-shell. It can have the values pure or impure 🐚

πŸ“š 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 ~/.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 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

✨ 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