How do I cross-compile a flake?

Ah, okay. Sorry if I was a bit terse. I use DXVK on Darwin, and my Linux machines are not suitable for gaming, so my ability to test on Linux is pretty limited. I wasn’t certain whether there might have been something wrong with the derivation in nixpkgs. I see now that it was a timing issue. Thanks for the clarification.

It’s possible to cross-build in a flake without using an overlay by manually setting crossSystem to the target and localSystem to the host system. It’s not exactly pretty or obvious though.

Unless I misunderstand, and the issue is cross-building another flake’s package and not just cross-building within a flake. Flake can be written to support it, but that may not be ideal.

(Edit: Revised the example to do implement that.)

{
  inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11";

  outputs = inputs@{ self, nixpkgs, ... }:
    let
      lib = nixpkgs.lib;

      darwin = [ "x86_64-darwin" "aarch64-darwin" ];
      linux = [ "x86_64-linux" "aarch64-linux" ];
      allSystems = darwin ++ linux;

      forEachSystem = systems: f: lib.genAttrs systems (system: f system);
      forAllSystems = forEachSystem allSystems;
    in
    {
      packages = forAllSystems (system:
        let
          pkgs = import nixpkgs { inherit system; };
        in
        {
          inherit (pkgs) hello;
          cross = forEachSystem (lib.filter (sys: sys != system) allSystems) (targetSystem:
            let
              crossPkgs = import nixpkgs { localSystem = system; crossSystem = targetSystem; };
            in
            {
              inherit (crossPkgs) hello;
            }
          );
        }
      );
    };
}
3 Likes