Quick Nix Copy question

Following up another question, I’m looking to download everything in a MyApp.nix file which has the Expression i’m using for MyApp.

I’d like to copy all that into a directory on my usb drive as a Nix cache, and then go onto another machine to copy from that usb to the local store.

(i’m on Nix 2.26.2 with NixPkgs 24.05)

So far, I’m at:

nix copy --extra-experimental-features nix-command --extra-experimental-features flakes --to file:///usb -I nixpkgs=channel:nixos-24.05 nixpkgs#gcc

Which works fine

What I’d like to do is somehow feed MyApp.nix to the above command instead of nixpkgs#gcc and have it download everything indicated in that file.

How do I do that?

On the destination machine, I’m assuming I can simple do a:

nix copy --extra-experimental-features nix-command --extra-experimental-features flakes -all --from /usb

1 Like

Something like this should do the trick

# build (i have no idea how you build your MyApp.nix)
nix build --extra-experimental-features 'nix-command flakes' .#myapp

# copy the closure to the usb
nix copy --extra-experimental-features 'nix-command flakes' --to file:///usb $(readlink ./result)

# store closure path
readlink ./result > /usb/myapp-closure

# on target machine
nix copy --extra-experimental-features 'nix-command flakes' --from file:///usb $(cat /usb/myapp-closure)
1 Like