8

Currently I use:

find /nix/store/* -maxdepth 1 | xargs -L <N> nix-copy-closure --sign --gzip --use-substitutes --to <remote machine>

Where N is some reasonable number that will not make the line length too long for xargs.

Is there a more idiomatic method of doing this on two running machines?

edit:

Advantages of above method:

  • Does not copy closures that exist on both ends. This also means you can stop a transfer and pick up where you left off other then some hash checking overhead
  • --use-substitues This will make the remote machine download from binary caches first and then sending machine second. This is great in the common case of sending files from my laptop to a remove server where the remote server often has 100 times the bandwidth to nix's binary cache compared to my laptop
  • nix-copy-closure copies over ssh so the transfer is encrypted.
  • nix-copy-closure, to my limited knowledge, should not interfere with any other operations happening on the nix store.

Online man page for nix-copy-closure

2
  • For large nix stores the shell expansion /nix/store/* gives -bash: /run/current-system/sw/bin/find: Argument list too long. find /nix/store -maxdepth 1 doesn't have that problem.
    – nh2
    May 12 '18 at 9:55
  • Perhaps, it is a typo.
    – AleXoundOS
    May 1 '20 at 22:08
9

I prefer to use nix-serve to share packages between laptops

% nix-env -i nix-serve
% nix-serve -p 8080

more options how to share nix packages between machines described in nix manual

1
  • 1
    This looks like a good option. You can also specify a ssl key and cert on the command line. Though the --enable-ssl which "Enables ssl on all TCP ports" is marked as experimental.
    – Davorak
    May 27 '15 at 21:20
2

I prefer to use scp. Below command will copy everything recursively to your remote machine:

scp -r /nix/store/* your_user@host_name:/path/to/store/copy

If you want to preserve modification times, access times, and modes from the original file, use the -p flag.

To optimize scp performance and increase speed use blowfish as the chiper and enable compression like this:

scp -c blowfish -r -C /nix/store/* your_user@host_name:/path/to/store/copy
1
  • 1
    I think the nix store is normal mounted as read only to discourage write access by root, at least on nixos. I think I would have to login as root on both machines unmount and re mount the store as readable in order to use scp. Not clear to me there can be other negative consequences from temporarily mounting and un mounting the store; I am just not familiar enough with the services on nixos to know.
    – Davorak
    May 20 '15 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.