Cross Compilation with nix-shell and cmake

#1

I try to cross-compile a cmake project with nix-shell.

This is my shell.nix

with import <nixpkgs> {
  crossSystem = {
    config = "aarch64-unknown-linux-gnu";
  };
};
mkShell {
  nativeBuildInputs = [ cmake ];
  buildInputs = [  ];
}

I thought this would give me a cmake executable for my build machine, but it compiles cmake for aarch64. When i try to rund cmake in the shell, I get the following error:

bash: /nix/store/xiizh0j9c2ynnw7njk3w4zi2109brbs3-cmake-3.13.4-aarch64-unknown-linux-gnu/bin/c
make: cannot execute binary file: Exec format error                                          

What am I doing wrong? Thank you for your help.

0 Likes

#2

The cmake from that shell.nix seems to run fine on x86 for me. Check PATH?

0 Likes

#3

You need to get it from buildPackages. Like this:

with import <nixpkgs> {
  crossSystem = {
    config = "aarch64-unknown-linux-gnu";
  };
};
mkShell {
  nativeBuildInputs = with buildPackages; [ cmake ];
  buildInputs = [  ];
}
0 Likes

#4

Thank you, that helped

0 Likes