Help with local binary cache

I’m trying to copy packages from cache.nixos.org to a local binary cache, and then from the cache to the local store on a different machine - something Nix is supposed to support. I’ve encountered many obstacles along the way - some I was able to work around, and some have me stuck. I’ve included my full battle log, in case someone can help me with any stage.

  • I start with cloning nixpkgs, so the versions always match:

    $ git clone -b master --depth 1 https://github.com/NixOS/nixpkgs
    Cloning into 'nixpkgs'...
    ...
    Updating files: 100% (34428/34428), done.
    
  • Then what should be the correct nix copy command:

    $ nix copy --from https://cache.nixos.org/ --to file://$PWD/cache ./nixpkgs#hello
    warning: error: unable to upload 
    'https://cache.nixos.org/nar/0r0c0cyw43fa6nrb5z6mdg0wr1nbc6x2v2bbpl6vs731d7h8nxrv.nar.xz': HTTP error 503
    <aborted after a long time trying to upload>
    

    I seem to have run into nix copy --from ... nixpkgs.hello tries to upload instead of download · Issue #2637 · NixOS/nix · GitHub - nix copy tries to evaluate the expression within the --from store.

  • I try the workaround suggested there(nix copy --from ... nixpkgs.hello tries to upload instead of download · Issue #2637 · NixOS/nix · GitHub):

    $ nix copy --from https://cache.nixos.org/ --to file://$PWD/cache ./nixpkgs#hello --eval-store ""
    don't know how to build these paths:
      /nix/store/xcj88diixazdl70bqsd2sn7yflm5dqz8-hello-2.12.1.drv
    error: path '/nix/store/xcj88diixazdl70bqsd2sn7yflm5dqz8-hello-2.12.1.drv' is not a valid store path
    

    No idea what to make of that.

  • I try just using the local store, using substitution:

    $ nix copy --to file://$PWD/cache ./nixpkgs#hello
    

    This exits successfully, and leaves the cache directory populated, so whilst going via the local store is not what I intended, I’ll take on as a working hypothesis that I have a working cache, and move forward for now.

On the remote machine:

$ nix copy --from file:///$PWD/cache/ --eval-store "" ./nixpkgs#hello
don't know how to build these paths:
   /nix/store/xcj88diixazdl70bqsd2sn7yflm5dqz8-hello-2.12.1.drv
error: path '/nix/store/xcj88diixazdl70bqsd2sn7yflm5dqz8-hello-2.12.1.drv' is not a valid store path

Same problem again.

I throw my hands up. Anyone have any suggestions?