Nixpkgs: cross-compilers should be supported better/more available

Created on 14 Apr 2017  路  7Comments  路  Source: NixOS/nixpkgs

Currently there鈥檚 close to none support for crosscompilation from nixos. It is very inconvenient.

I feel like Nix has a lot of potential here. Adding cross-compilers could be as simple as:

let myCrossTargets =  ["x86_64-pc-windows-gnu" "mips-unknown-linux-gnu" ...] in
  pkgs = { 
    gcc.crossTargets = myCrossTargets;
    rustNightly.rustc.crossTargets = myCrossTargets;
    clang.crossTargets = myCrossTargets;
    etc etc
  };

especially painful are the gcc crosscompilation toolchains, so if nix supported this use-case, it would be hella awesome.

cross-compilation

Most helpful comment

@Ericson2314 My greatest problem with the two ways to get crosscompilers in nixos (expression above, AFAICT, is the legacy method) lies within the lack of examples, rather than documentation of the primitives.

It took me a long while to get the expression above going, and even then I could not make it work alongside the rust compiler. Getting a rust with both host libraries and target libraries into the expression above would strip the host libraries (no matter what I did), breaking them in the process and by extension breaking compilation of libraries that depend on build scripts.

I would gladly try the alternatives, but I do not want to spend hours fiddling with nix either.

All 7 comments

I don't think it's too bad, really. Some targets work a bit, even if it's not that well documented. In my experience it's often about finding patches to individual packages to make them cross-compile, and I think there's still very few nixpkgs users/contributors of cross-compiling stuff. We do CI of a few examples: http://hydra.nixos.org/jobset/nixpkgs/cross-trunk#tabs-jobs

@vcunat maybe you鈥檙e misunderstanding? I want cross compilers to be available, not cross-compiled packages or cross-compilation of packages themselves.

Well, the toolchain is the first thing you need for each cross-platform. When you have that, you just "evaluate all packages with it", though most packages won't compile without changing their expressions. I think all I've written applies to compilers as well.

So, turns out cross-compilers (C ones, at least) are pretty easy to make by doing something like this:

  pkgs = import <nixpkgs> {
    config = {
      packageOverrides = super: {
        gcc = super.gcc6;
      };
    };
    crossSystem = rec {
      config = "powerpc64-linux-gnu";
      bigEndian = true;
      arch = "powerpc64";
      float = "hard";
      withTLS = true;
      libc = "glibc";
      platform = {
        kernelMajor = "2.6";
        kernelArch = "powerpc";
        kernelHeadersBaseConfig = "pseries_defconfig";
        kernelBaseConfig = "pseries_defconfig";
        gcc = {
          cpu_64 = "power8";
          cpu_32 = "power8";
        };
      };
      openssl.system = "linux-generic32";
      inherit (platform) gcc;
    };
  };
in pkgs.stdenv.mkDerivation {
  name = "shell";
}

This could at least be documented better.

@nagisa I've been doing a ton of work on cross compilation lately. I've also tried to document things in a new cross compilation section of the manual. I would like rust to eventually leverage this (https://github.com/mozilla/nixpkgs-mozilla/issues/26 for example). Any feedback would be much appreciated.

I do agree that being able to get some tools without reevaluating all of nixpkgs would be nice, but not sure how to support both ideoms well without greatly complicating things. Turning targetPlatform into targetPlatforms might move things in the right direction.

@Ericson2314 My greatest problem with the two ways to get crosscompilers in nixos (expression above, AFAICT, is the legacy method) lies within the lack of examples, rather than documentation of the primitives.

It took me a long while to get the expression above going, and even then I could not make it work alongside the rust compiler. Getting a rust with both host libraries and target libraries into the expression above would strip the host libraries (no matter what I did), breaking them in the process and by extension breaking compilation of libraries that depend on build scripts.

I would gladly try the alternatives, but I do not want to spend hours fiddling with nix either.

The new pkgsCross short-hand should make this stuff easy enough to stumble upon. CC @matthewbauer

Was this page helpful?
0 / 5 - 0 ratings

Related issues

grahamc picture grahamc  路  3Comments

matthiasbeyer picture matthiasbeyer  路  3Comments

retrry picture retrry  路  3Comments

langston-barrett picture langston-barrett  路  3Comments

tomberek picture tomberek  路  3Comments