Problem using store from existing host for new install

For bandwidth reasons I’m trying to use an existing host with a nearly identical setup to install a new host. However even after finding a lot of existing store content the system wants to build a lot of packages from source:

boot-host> nixos-install -v --option require-sigs false --option trusted-substituters ssh-ng://me@other-host --option substituters ssh-ng://me@other-host --flake .#new-host

copying channel...
building the flake in git+file:///root/nixos?ref=refs%2fheads%2fmain&rev=abcdef...

these 476 derivations will be built:
  /nix/store/c81xzgfi1a5nlj6g2fkz9b1m79f2w6hf-binutils-2.40.drv
  /nix/store/5fqb4cy0srbzw1lfmny30x66fmh6jmpg-binutils-wrapper-2.40.drv
  /nix/store/q072lsl54bjjlgsj06w7fb431cz2ckci-xgcc-12.2.0.drv
  ...

Checking the store on the other host shows that files are there:

other-host> cd /nix/store
other-host> nix-store --query q072lsl54bjjlgsj06w7fb431cz2ckci-xgcc-12.2.0.drv
/nix/store/108m570wl346n4g5789cl6j06cy3224f-xgcc-12.2.0-info
/nix/store/62ywnzqgdjhl5v5ccb3fkrd8daqa49s8-xgcc-12.2.0-lib
/nix/store/7rkzy3l3m05wqlld8624d348aakrij17-xgcc-12.2.0-checksum
/nix/store/dxxvdwqnh3040znk31gll520si8qcvai-xgcc-12.2.0
/nix/store/jd99cyc0251p0i5y69w8mqjcai8mcq7h-xgcc-12.2.0-libgcc
/nix/store/z647vyl1d2mhqcpbd9nwvjl1f2yf2m77-xgcc-12.2.0-man

Adding multiple -v to nixos-install didn’t reveal the reason why the packages are rebuild.

Is there some way to make nixos-install take the existing packages and just put them in the new system?

Thank you!

are you sure you’re actually using the same revision of nixpkgs? If the nixpkgs versions are too different, the packages will be diverged, even if the version numbers are the same.

It’s also weird that it’s building them from source and not getting them from cache.nixos.org, unless you’re explicitly disabling that.

I get confused with these options and feel like I never even have them quite right on my system (and use a nix wrapper script that explicitly sets them) but OP probably wants extra-trusted-subtituters and extra-substituters to augment cache.nixos.org.

oh, yea I hadn’t even seen that they probably accidentally disabled the cache by using --trusted-substituters

Thanks for your responses. As written in my post I didn’t want to have cache.nixos.org to join in because I thought, but maybe that wasn’t the case, that “cloning” an a system with the same git-stored config would not require much stuff from the Internet.

What worked at the end was copying over all files from /nix/store with rsync -avzpHt --ignore-existing. After that the compilation process was skipped, the installer finished and the system was useable. But I guess that left me with an nondeterministic /nix/store.

In future you could try out nixos-anywhere.