Architecture mismatch with remote build

Relative Nix newbie here. I’m trying to write a flake that takes a directory of files in your config repo and copies them into the /etc directory on your NixOS install. This is working, however I’d like to add the ability to transfer over the permissions (mode) as well. The issue is that no matter what I try, I get an architecture mismatch error.

I’m deploying to a remote machine and using a remote build host:

nix run nixpkgs#nixos-rebuild -- switch --fast --flake .#default --target-host root@$target_host --build-host root@$build_host --show-trace

The code that’s having the issue looks like this:

let
  filePermissionsScript = pkgs.runCommandWith {
    name =  "file-permissions";
    runLocal = true; # Same result with or without this
    derivationArgs = {
       nativeBuildInputs = [ pkgs.coreutils ];
       system = builtins.currentSystem;
    };
  } ''
    ${pkgs.coreutils}/bin/stat -c "%a" ${file} > $out
    '';
  in {
     mode = builtins.readFile filePermissionsScript;
     ... more stuff ...

The error I receive when trying to use this flake in my config repo is:

… while calling the 'readFile' builtin
         at /nix/store/d80k5nxlicm8sxasjcyi7gnf13hwndw2-source/nixos-modules/service.nix:67:14:
           66|     in {
           67|       mode = builtins.readFile filePermissionsScript;
             |              ^
           68|       name = builtins.unsafeDiscardStringContext (builtins.substring (builtins.stringLength sourceDir + 1) (builtins.stringLength file) file); # Strip sourceDir prefix

       … while realising the context of path '/nix/store/79x8mvfm13cy06xgcblhn2nmsnm94p3m-file-permissions'

       error: a 'x86_64-linux' with features {} is required to build '/nix/store/gdkw59x4lm9id5jfi6xjbhsrxqhligiq-file-permissions.drv', but I am a 'aarch64-darwin' with features {apple-virt, benchmark, big-parallel, nixos-test}

I’m deploying from an M1 Mac, hence the Darwin architecture.

I would have expected that either this works, because we’re calling filePermissionsScript locally on my Mac, against the local file. Or I would expect it to work because we first copy the file over to the remote nix store, and then execute the script there.

Any help is greatly appreciated!