nix-copy-closure(1)
π nix-copy-closure(1) π
okay bestie, welcome to the General Commands Manual page for nix-copy-closure β she's a real one, and by the end of this you're gonna be obsessed. no cap. πΈ
β¨ Name β¨
nix-copy-closure β copy store objects to or from a remote machine via SSH π¦
like. that's the whole vibe. store objects, remote machine, SSH. main character energy fr fr.
β¨ Synopsis β¨
nix-copy-closure [--to | --from ] [--gzip] [--include-outputs] [--use-substitutes | -s] [-v] [user@]machine[:port] paths
look at her go π she's so organized.
β¨ Description β¨
so here's the tea π β you hand nix-copy-closure some paths from one machine, and she goes and computes the closure of those paths, which is just a fancy way of saying all their dependencies in the Nix store. then she copies the store objects in that closure over to another machine via SSH. π
and the best part?? she's not gonna waste your bandwidth β she doesn't copy store objects that are already chillin' on the other machine. queen behavior, honestly. π
β οΈ Note: okay so listen β while you can specify the Nix store to use on the local machine with the --store option on the command line, the Nix store that gets accessed on the remote machine can only be configured statically on that remote machine. no command-line shortcuts for the far-away store, bestie. that's just how she is. π
and since nix-copy-closure calls ssh, you might need to authenticate with the remote machine. in fact β and this is the part that lowkey jumps you π β you may be asked for authentication twice, because nix-copy-closure currently connects twice to the remote machine:
- first, to get the set of paths missing on the target machine
- second, to send the dump of those paths
two trips. two vibes. two auth prompts. she's thorough. π
when you're using public key authentication, you can dodge the passphrase-typing entirely with ssh-agent. life hack. take it. β¨
β¨ Options β¨
--toβ copy the closure ofpathsfrom a Nix store accessible from the local machine over to the Nix store on the remote machine. π this is the default behavior, so if you don't say anything, this is what she does. iconic default energy.--fromβ copy the closure ofpathsfrom the Nix store on the remote machine over to the local machine's specified Nix store. π reverse uno card, but make it Nix.--gzipβ enable compression of the SSH connection. ποΈ small pipes, big closure, no problem.--include-outputsβ also copy the outputs of store derivations included in the closure. π¦ the closure's plus-ones are coming too, apparently.--use-substitutes,-sβ attempt to download missing store objects on the target from substituters. π any store objects that cannot be substituted on the target are still copied normally from the source β so nothing gets left behind, she just tries the shortcut first. this is useful, for instance, if the connection between the source and target machine is slow, but the connection between the target machine andcache.nixos.org(aka the default binary cache server) is fast. π your sourceβtarget link is giving dial-up, but the cache link is giving fiber. let the fast one do the work.-vβ π«Ά verbosity, as listed in the synopsis up there. she's chatty when you ask her to be.
β¨ Common Options β¨
okay bestie, so like most Nix commands accept all of these, and they're the little knobs you get on basically every tool in the toolbox ποΈπ
--helpβ prints a lil summary of the command syntax and then dips out. bye π--versionβ prints the Nix version number to standard output and exits. that's it, that's the tea β--verbose,-vβ turns the volume UP on the diagnostic messages printed to standard error π For every Nix operation the stuff on standard output is well-defined; all diagnostic info goes to standard error, never standard output. no cap.
you can pass this one again and again and again (spam it, queen). currently these are the verbosity levels:
- 0 βErrors onlyβ β only prints messages explaining why the Nix invocation failed. (rude but honest)
- 1 βInformationalβ β prints useful messages about what Nix is doing. this is β¨the defaultβ¨
- 2 βTalkativeβ β more informational messages. she's chatty now π¬
- 3 βChattyβ β even MORE informational messages π
- 4 βDebugβ β prints debug information π
- 5 βVomitβ β prints vast amounts of debug information π yeah. that's the actual name. drink water.
--quietβ turns the volume DOWN on the diagnostic messages printed to standard error. it's the inverse option to-v/--verbose. you can also spam this one; check the verbosity levels list above π--log-formatformat β use this to change the output format of the logs, where format is one of:rawβ 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 like, don't get too attached lol
barβ only display a progress bar during the builds πbar-with-logsβ display the raw logs, with the progress bar at the bottom π«Ά
--no-build-output,-Qβ by default, output written by builders to standard output and standard error gets 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β that part is non-negotiable, she journals π--max-jobs,-jnumber β sets the maximum number of build jobs Nix will do in parallel to number. sayautoto use the number of CPUs in the system (she'll count them herself π’). 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. setting it to0disallows building on the local machine β perfect when you want builds to happen only on remote builders π°οΈ--coresβ sets the value of theNIX_BUILD_CORESenvironment variable in the invocation of builders. builders can use that 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 the builder should use all available CPU cores in the system. slay π--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.--timeoutβ sets the maximum number of seconds that a builder can run. the default is specified by thetimeoutconfiguration setting.0means no timeout β°--keep-going,-kβ keep going in case of failed builds, to the greatest extent possible. that means: 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 does not simply give up πͺ--keep-failed,-Kβ says that in case of a build failure, the temporary directory (usually in/tmp) where the build takes place 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 for which substitutes are known for each output path, but realising the output paths through the substitutes fails, it falls back on building the derivation.
the most common scenario where this is useful: you've registered substitutes so you can 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 π§ the reason it's not the default is that it's generally not desirable for a transient failure in obtaining substitutes to lead to a full build from source (with all the related resource consumption). lowkey a big deal.
--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 fail π look but don't touch.--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 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 as the 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 donix-env --install --attr pkgname), the function gets called automatically using the valuebuiltins.currentSystemfor thesystemargument. you can override this with--arg, e.g.nix-env --install --attr pkgname --arg system "i686-freebsd". (heads up: since the argument is a Nix string literal, you have to escape the quotes.) π
--arg-from-filename path β pass the contents of file path as the argument name to Nix functions π--arg-from-stdinname β pass the contents of stdin as the argument name to Nix functions π₯--argstrname value β 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 just say--argstr system i686-linux. way less quoting drama bestie π--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, 3 = fourth, that's just how the vibes work π)
--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β 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 a shell that contains the built packages ready for use, give your expression to the nix-shell --packages convenience flag instead π
-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. yes queen, priority β¨
--impureβ allows access to mutable paths and repositories π--optionname value β set the Nix configuration option name to value. this overrides settings in the Nix configuration file (seenix.conf5).--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.
π Note β see man nix.conf for overriding configuration settings with command line flags.
πΈ Environment variables πΈ
NIX_SSHOPTSβ additional options to be passed tosshon the command line π°οΈ ssh but make it extra.
πΈ Common Environment Variables πΈ
okay bestie so basically almost every Nix command ever reads these same env vars, so this section is like the shared group chat that everybody's in π¬β¨
βοΈ Configuration environment variables
These ones decide how Nix loads up its configuration. The configuration file docs have the full tea if you want every last detail, but here's the lineup π«Ά
NIX_CONF_DIRβ overrides the system configuration directory. yes, the system one, main character energy πNIX_USER_CONF_FILESβ overrides where the user configuration files live. this one's for your files πNIX_CONFIGβ lets you hand configuration settings straight to Nix inline. no files, no drama, just vibes β¨
π¬ Store setting environment variables
NIX_IGNORE_SYMLINK_STOREβ normally, the Nix store directory (typically/nix/store) is not allowed to contain any symlink components. why? to prevent "impure" builds π builders sometimes "canonicalise" paths by resolving all symlink components, so builds on different machines (where/nix/storeresolves to different locations) could totally yield different results. this is generally not a problem, except when builds get deployed to machines where/nix/storeresolves differently. if you're sure you're not gonna do that, you can setNIX_IGNORE_SYMLINK_STOREto1. slay, but carefully.
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 way better off using bind mount points, like this π§
$ 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 is no compile-time setting; the default is%PROGRAMDATA%\nix\store, determined at runtime using the%PROGRAMDATA%Known Folder. see the Store Types chapter, because 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; 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 π«‘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. 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. defaults todaemon-socket/socketinside the state directory (seeNIX_STATE_DIR). check the Local Daemon Store documentation for the whole story on how that socket path gets resolved πTMPDIRβ use the specified directory to store temporary files. this includes temporary build directories, which can eat up substantial amounts of disk space π the default is/tmp.NIX_REMOTEβ overrides the store setting. short and iconic, that's it π
π§ Nix language evaluator settings
NIX_SHOW_STATSβ if set to1, Nix prints out some evaluation statistics, like the number of values allocated. numbers go brrr πNIX_COUNT_CALLSβ if set to1, Nix prints 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 sets the initial size of the heap in bytes. it defaults to384 MiB. setting it low reduces memory consumption, but it'll run slower because of garbage collection overhead. tradeoffs, bestie βοΈ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
and if NIX_PATH is set to an empty string, resolving search paths will always fail. yep, always.
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 does per-user configuration, state, and cache directories, because of course it does π these environment variables override where those directories live:
- 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) still use dotfiles in $HOME instead of these directories, unless use-xdg-base-directories is enabled. the new Nix commands (experimental) use the proper directories by default. glow up fr fr π
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β an indicator that tells you whether the current environment was set up bynix-shell. it can have the valuespureorimpure. vibe check for your shell π
π§ Appendix: OS-specific conventions π§
just so you know, this info isn't Nix-specific, it's just referenced above π
π§ Unix: XDG Base Directories
the XDG Base Directory Specification defines the standard locations for user-specific configuration, state, and cache files on Unix systems.
these are the environment variables involved:
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 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
copy GNU Hello and all of its dependencies over to a remote machine π
$ storePath="$(nix-build '<nixpkgs>' -I nixpkgs=channel:nixpkgs-unstable -A hello --no-out-link)"
$ nix-copy-closure --to alice@itchy.example.org "$storePath"
copying 5 paths...
copying path '/nix/store/h6q8sqsqfbd3252f9gixqn3z282wds7m-xgcc-13.2.0-libgcc' to 'ssh://alice@itchy.example.org'...
copying path '/nix/store/imnwvn96lw355giswsk36hx105j4wnpj-libunistring-1.1' to 'ssh://alice@itchy.example.org'...
copying path '/nix/store/85301indj7scg34spnfczkz72jgv8wa9-libidn2-2.3.7' to 'ssh://alice@itchy.example.org'...
copying path '/nix/store/ypwfsaljwhzw9iffiysxmxnhjj8v7np0-glibc-2.39-31' to 'ssh://alice@itchy.example.org'...
copying path '/nix/store/0dklv59zppdsqdvgf0qdvjgzcs5wbwxa-hello-2.12.1' to 'ssh://alice@itchy.example.org'...
Example
now copy GNU Hello from a remote machine using a known store path, and run it πββοΈπ¨
$ storePath="$(nix-instantiate --eval --raw '<nixpkgs>' -I nixpkgs=channel:nixpkgs-unstable -A hello.outPath)"
$ nix-copy-closure --from alice@itchy.example.org "$storePath"
$ "$storePath"/bin/hello
Hello, world!
and that's a wrap on the whole page, bestie πβ¨ nix-copy-closure(1) really said "hey girlypop, here's literally everything", and you read all of it. so proud of you π«Ά go copy some closures, you absolute icon π
π¦ 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