Cross Compilation of "BuildEnv" packages?

Hello

First of all, I’m quite new to Nix, my lurning curve is long…

I want to use Nix to deploy a “BuildEnv” package on some no-internet machines. For this:

  • I use an x86_64 machine (with internet access) to fetch/build
  • I cache (nix copy to a local folder) and get some NAR+narinfo files
  • I then transfer the NAR+narinfo files towards the no-internet machine
  • the no-internet machine is configured to use a local substitute folder (substituters=file:///) containing the NAR+narinfo files.

I have been doing this approach for x86_64 machine and that has worked well. Now I also need this for an armv7l Raspberry Pi, and here come the problems…

Method1: CrossCompilation: I setup a flake with this kind of code:

    outputs = { self, nixpkgs_23_05, ... }:
    let
        mypackages_23_05 = nixpkgs_23_05.legacyPackages.x86_64-linux;
        raspi_nixpkgs_23_05 = mypackages_23_05.pkgsCross.armv7l-hf-multiplatform;
        raspi_pythonenv_23_05 = raspi_nixpkgs_23_05.python311.withPackages (ps: [ ps.lxml ]);  
    in {
        RASPI_Workspace = raspi_nixpkgs_23_05.buildEnv {
            name = "RASPI_Workspace";
            paths = [
                raspi_pythonenv_23_05
                raspi_nixpkgs_23_05.tree
            ];
        };
    };
}

This successfully builds on my online x86_64 machine and I get a /nix/store/-RASPI_Workspace folder.
When I try to install this flake on the RaspberryPi, it needs additional derivation to be built:

/nix/store/hs1wlpvjvd1i9c7mzvqcvk80m4jiwa9s-builder.pl.drv
/nix/store/d8qqw16pc9q4i4h2bj6aqflxnr1d11si-python3-armv7l-unknown-linux-gnueabihf-3.11.3-env.drv

which fail with the error:

error: a 'x86_64-linux' with features {} is required to build '/nix/store/hs1wlpvjvd1i9c7mzvqcvk80m4jiwa9s-builder.pl.drv', but I am a 'armv7l-linux'

and indeed the derivation contains:

    "name": "builder.pl",
    "outputs": {
      "out": {
        "path": "/nix/store/xwh19wdraabqqnccf8320mc6hhhl5qqx-builder.pl"
      }
    },
    "system": "x86_64-linux"

Questions: Any clue on how I could workaround this ?
Why does Nix need to build anything while the build output (RASPI_Workspace nar) is already available via local substituter ?

Method2: Nix on emulated armv7l on my x86_64 online machine.
For that, I tweak the nix-daemon.service to have

ExecStart=/usr/bin/qemu-arm -cpu cortex-a7 /nix/store/<hash>-nix-2.18.1-armv7l-unknown-linux-gnueabihf/bin/nix-daemon --daemon

and update the flake to directly handle armv7 system:

    outputs = { self, nixpkgs_23_05, ... }:
    let
        raspi_nixpkgs_23_05 = nixpkgs_23_05.legacyPackages.armv7l-linux;
        raspi_pythonenv_23_05 = raspi_nixpkgs_23_05.python311.withPackages (ps: [ ps.lxml ]);  
    in {
        RASPI_Workspace = raspi_nixpkgs_23_05.buildEnv {
            name = "RASPI_Workspace";
            paths = [
                raspi_pythonenv_23_05
                raspi_nixpkgs_23_05.tree
            ];
        };
    };
}

When doing so, I can run some Nix builds commands and build some few packages (ex: hello package), but there are failures when building the full RASPI_Workspace (error during the build of bison).

error: builder for '/nix/store/c69w0ikq7bsjqm99qfxv9nf4xai8w551-bison-3.8.2.drv' failed with exit code 2;
       last 10 log lines:
       >    To: <bug-bison@gnu.org>
       >    Subject: [GNU Bison 3.8.2] testsuite: 2 64 288 289 290 291 292 314 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 failed
       >
       > You may investigate any problem if you feel able to do so, in which
       > case the test suite provides a good starting point.  Its output may
       > be found below `tests/testsuite.dir'.
       >
       > make[1]: *** [Makefile:13927: installcheck-local] Error 1
       > make[1]: Leaving directory '/tmp/nix-build-bison-3.8.2.drv-0/bison-3.8.2'
       > make: *** [Makefile:10377: installcheck-recursive] Error 1
       For full logs, run 'nix log /nix/store/c69w0ikq7bsjqm99qfxv9nf4xai8w551-bison-3.8.2.drv' 

Do you know why when doing this approach, the build process doesn’t pull anything from substituters but builds everything from sources ?

Thanks for your time if you have read this, and please feel free to ask for any additional detail.
Also if this whole approach is wrong, please don’t hesitate to tell me

rbl