Is there any way to lazy cross-compile as described in this article Cross Compiling - NixOS Wiki
Simply doing the below gives error: a 'aarch64-linux' with features {} is required to build '/nix/store/l1313i4cx16d02gxay9p8956ncyxfxmy-master-0.0.0.drv', but I am a 'x86_64-linux' with features {benchmark, big-parallel, kvm, nixos-test}
, so I had to disable the feature.
#! Returns true if target is nix flake compatible.
#! <https://github.com/NixOS/nixpkgs/blob/b89a6066930868822e4c6a55f3d14ebf5b4fbd1f/lib/systems/flake-systems.nix>
isFlakeTarget = with zig2nix-lib; args': let
target-system = if isString args' then mkZigSystemFromString args' else args';
in any (s: (systems.elaborate s).config == (systems.parse.tripleFromSystem target-system)) systems.flakeExposed;
#! Returns crossPkgs from nixpkgs for target string or system.
#! This will always cross-compile the package.
crossPkgsForTarget = with zig2nix-lib; args': let
target-system = if isString args' then mkZigSystemFromString args' else args';
crossPkgs = import nixpkgs { localSystem = system; crossSystem = { config = systems.parse.tripleFromSystem target-system; }; };
in crossPkgs;
#! Returns pkgs from nixpkgs for target string or system.
#! This does not cross-compile and you'll get a error if package does not exist in binary cache.
#!
#! Currently just alias for crossPkgsForTarget due to:
#! error: a 'aarch64-linux' with features {} is required to build '...', but I am a 'x86_64-linux' with features {}
#! It seems like this trick does not work anymore.
binaryPkgsForTarget = with zig2nix-lib; args': let
target-system = if isString args' then mkZigSystemFromString args' else args';
binaryPkgs = import nixpkgs { localSystem = { config = systems.parse.tripleFromSystem target-system; }; };
in warn "binaryPkgsForTarget does not work currently" crossPkgsForTarget args'; # binaryPkgs;
#! Returns either binaryPkgs or crossPkgs depending if the target is flake target or not.
pkgsForTarget = with zig2nix-lib; args': let
target-system = if isString args' then mkZigSystemFromString args' else args';
in if isFlakeTarget args' then binaryPkgsForTarget args'
else (
warn "pkgsForTarget: cross-compiling for ${systems.parse.tripleFromSystem target-system}"
crossPkgsForTarget args'
);