Skip to content

Instantly share code, notes, and snippets.

@cleverca22
Last active December 12, 2022 05:19
Show Gist options
  • Save cleverca22/bc86f34cff2acb85d30de6051fa2c339 to your computer and use it in GitHub Desktop.
Save cleverca22/bc86f34cff2acb85d30de6051fa2c339 to your computer and use it in GitHub Desktop.
nix copy
NIX_REMOTE=local?root=/mnt/img/ nix-env --profile /mnt/img/nix/var/nix/profiles/system --set -f '<nixpkgs/nixos>' -A system -I nixos-config=/mnt/img/etc/nixos/configuration.nix --option system aarch64-linux
2016-08-10 11:57:31< niksnut> shlevy: nix copy --to 'file:///tmp/cache?secret-key=/home/eelco/Misc/Keys/test.nixos.org/secret' ...
2016-08-10 12:06:09< shlevy> niksnut: + nix copy --to file:///run/user/1000/nix-test/binary-cache /run/user/1000/nix-test/store/lns3cz6s9sz25bpp4sl6iif02rzz1crz-dependencies
2017-03-06 12:35:18< niksnut> shlevy: nix copy --to s3://...
2017-03-06 12:37:09< niksnut> clever: yes, nix copy --to local?root=/mnt
2017-03-20 12:49:31< clever> niksnut: oh yeah, when using "nix copy --to local?root=/mnt" it complains about things not being signed, i had to pass a --option to entirely disable signatures
2017-04-13 10:41:52< copumpkin> `nix copy` also looks promising, hmm
2017-04-13 11:49:22< copumpkin> niksnut: does `nix copy` copy the entire closure or just the specific path requested? does it do work avoidance if the destination path is already there and valid in the destination DB?
2017-04-13 11:54:58< dtzWill> copumpkin: I'm not niksnut :P but looking at 'nix copy --help' there's an "-r" option to specify copying the entire closure or just the given path (although tbh I didn't realize copying a path without its deps was a useful/possible thing regardless), and pretty sure it only copies missing paths.  Source: experience. trying it again now with "nix copy --to file://$HOME/cache path".
2017-04-13 11:56:46< copumpkin> $ nix copy --to local?root=$PWD/foo $(which ls)
2017-04-13 20:09:45< copumpkin> shlevy: do you have a good grasp of `nix copy`? I'm trying to use it to copy from host to guest
2017-07-13 17:56:29< dtzWill> since AFAICT "nix copy" doesn't handle that quite right (and AFAICT "--all" on nix-copy is taken not from "--from" but from "--store" which is ... interesting.. if true)
2017-07-26 23:32:15< dtz> Might need --sign, or as trusted user.... Newer nix have"nix copy" that operates on store uris
2017-09-28 12:59:45-NixOS_GitHub:#nixos- nix/master 5421ad2 Eelco Dolstra: nix copy: make recursive by default
2017-10-18 15:59:50< clever> nix copy --to local?root=/mnt
2017-10-18 16:07:10< clever> but some things like "nix copy" want to talk to the daemon and local
2017-11-04 20:51:00< sphalerite> `nix copy --all --from ssh://green` complains "error: requested operation is not supported by store 'ssh://green'"
2017-11-07 23:25:38< hedning[m]> `nix copy` has a `--no-check-sigs` option, might work ^^
2017-11-14 01:58:01< clever> also, the new nix copy lets you do similar things
2017-11-14 01:59:39< clever> you could use the new nix copy for that
2017-11-14 02:00:07< clever> nix copy --to local?root=/mnt
2017-11-14 02:01:11< clever> just pop nixUnstable into line 9, and: nix copy --to local?root=/mnt/ ${paths}
2017-11-14 02:04:34< Lisanna> clever: sounds like nix copy is expecting a tmp filesystem
2017-11-14 02:07:19< Lisanna> nix copy --to local?root=$mountPoint ${paths}
2017-11-14 02:08:00< Lisanna> which evaluates to "nix copy --to local?root=/mnt /nix/store/<mypkg>"
2017-11-14 02:08:56< Lisanna> Yeah, I put echo guards around nix copy, and the error happens in nix copy
2017-11-14 02:30:29< clever> and that will make it a valid source for nix copy
2017-11-14 03:34:31< Lisanna> so nix-store --load-db; nix-store --verify --check-contents; nix copy --to "local?root=$mountPoint" ${paths}
2017-11-14 03:36:31< clever> ah yeah, there is a problem with nix copy, it expects things to be signed, even when using root
2017-11-14 03:39:20< Lisanna> nix copy --to "local?root=$mountPoint" --option binary-cache-public-keys "" ${paths}
2017-11-14 03:44:22< Lisanna> so nix copy --to "local?root=$mountPoint" --option signed-binary-caches "" ${paths}
2017-11-26 12:56:26< FRidh> pcarrier: nix copy -f . hello --to file:///path/to/cache     also supports --to ssh://server
2018-02-07 09:11:12< LnL> Lisanna: nix copy --from file:///tmp <paths>
2018-02-07 09:12:40< nahamu> Lisanna: is "nix copy" similar to https://nixos.org/nix/manual/#name-6 ?
2018-02-07 09:32:31< Lisanna> oh thank god... nix copy --to is smart enough to only copy missing things
2018-02-10 07:07:11< MichaelRaskin> kiloreux: nix copy --help
2018-02-24 08:22:04< obadz> nix copy --to ssh://laptop '(let pkgs = import <nixpkgs> {}; nixos = import <nixpkgs/nixos> { configuration = import <nixos-hosts/laptop>; }; in [ nixos.system pkgs.mainEnv ])'
2018-02-24 19:28:25< garbas> hey! anybody know how to specify a folder where to copy via ssh ... "nix copy --to username@server ./result"
2018-02-24 19:30:49< clever> garbas: `nix copy --to local?root=/mnt` sorta
2018-03-03 20:17:51< tnks> I did a "nix copy-sigs -s https://cache.nixos.org --all" and it did something, but didn't seem to help with all paths.
2018-03-04 01:06:41< tnks> Mic92: I can do a `nix copy --to`, but not a `nix copy --from`
2018-03-04 14:42:23< clever> [root@system76:/nix/var/nix/db]# time nix copy-sigs --all -s https://cache.nixos.org
#!/bin/sh
X=example
NIX_REMOTE=local?root=/home/clever/rootfs/ NIX_CONF_DIR=/home/$X/etc/nix NIX_LOG_DIR=/home/$X/nix/var/log/nix NIX_STORE=/home/$X/nix/store NIX_STATE_DIR=/home/$X/nix/var nix-build -E 'with import <nixpkgs> {}; nix.override { storeDir = "/home/'$X'/nix/store"; stateDir = "/home/'$X'/nix/var"; confDir = "/home/'$X'/etc"; }'
# creates a nix store at /home/clever/rootfs/home/example/nix/store that expects to be copied to /home/example/nix/store
nix copy --to ssh://root@target?remote-store=local?root=/mnt /nix/store/hash-nixos

NIX_REMOTE=local?root=/home/clever/iohk/daedalus/store1/ nix-collect-garbage --max-freed 1

deletes at least 1 byte of garbage from the given store

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment