Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cross compilers to haskell.nix flake devShell #868

Open
facundominguez opened this issue Oct 6, 2020 · 7 comments
Open

Add cross compilers to haskell.nix flake devShell #868

facundominguez opened this issue Oct 6, 2020 · 7 comments
Labels
preserved Keep stale bot away

Comments

@facundominguez
Copy link

facundominguez commented Oct 6, 2020

I'm trying to get a shell with a cross-compiler and having some difficulties.

The documentation on cross-compilation says how to build a project with either stack or cabal. I'm aiming to build with bazel, though, and I'm only interested in getting the build tools.

I found my way to get a native compiler in a shell for a dummy cabal project. However, haskell.nix has resisted all my attempts to get the shell with a cross-compiler for aarch64. My nix code is not very succinct either, which prods me to ask for an example from a more knowledgeable person.

Thanks in advance.

@hamishmack
Copy link
Collaborator

Do the same a you would for a non cross compiling shell, but instead of using haskell-nix use pkgsCross.aarch64-multiplatform.haskell-nix. For instance to get a shell to cross compile the hello package from hackage:

$ cat shell.nix 
{ haskellNix ? import (builtins.fetchTarball "https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz") {}
, pkgs ? import haskellNix.sources.nixpkgs haskellNix.nixpkgsArgs
}: (pkgs.pkgsCross.aarch64-multiplatform.haskell-nix.hackage-project {name = "hello"; version = "1.0.0.2"; compiler-nix-name = "ghc8102"; }).hsPkgs.shellFor {}

$ nix-shell
trace: Using latest index state for hello!
trace: Using index-state: 2020-10-12T00:00:00Z for hello
trace: Shell for hello
trace: Shell for hello

$ aarch64-unknown-linux-gnu-ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.10.2

@facundominguez
Copy link
Author

Thanks @hamishmack! That quite fits the bill.

@facundominguez
Copy link
Author

I'm trying to build with TH and this shell is missing the iserv-proxy and remote-iserv that would be necessary. I'll share here if I can figure out how to get those.

@facundominguez
Copy link
Author

Here's my best attempt so far:

let crossPkgs = pkgs.pkgsCross.aarch64-multiplatform;
    haskellNix = import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/b406bb1d5bed581f651ae18a5d3ed07f47ace2b9.tar.gz) {};
    pkgs = import haskellNix.sources.nixpkgs haskellNix.nixpkgsArgs;
in
pkgs.mkShell {
  buildInputs = 
    [ pkgs.buildPackages.ghc-extra-packages.ghc8102.iserv-proxy.components.exes.iserv-proxy
      crossPkgs.ghc-extra-packages.ghc8102.remote-iserv.components.exes.remote-iserv
      crossPkgs.buildPackages.haskell-nix.compiler.ghc8102
      pkgs.buildPackages.qemu
    ];
} 

@stale
Copy link

stale bot commented Sep 28, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added wontfix and removed wontfix labels Sep 28, 2022
@hamishmack
Copy link
Collaborator

We recently added basic ghc devShells so we could use them in GitHub actions to test building projects without haskell.nix.

haskell.nix/flake.nix

Lines 147 to 154 in a306656

} // __mapAttrs (compiler-nix-name: compiler:
mkShell {
buildInputs = [
compiler
haskell-nix.cabal-install.${compiler-nix-name}
];
}
) (

It would be really nice to add cross compilation including aarch64 to those.

@facundominguez did the above code work in the end? Did you have to tell ghc where to look for iserv or did it find? If not then I suspect we might need some of the code from https://github.com/input-output-hk/haskell.nix/blob/master/overlays/linux-cross.nix

@hamishmack hamishmack changed the title How to get a shell with a cross-compiler? Add cross compilers to haskell.nix flake devShell Sep 30, 2022
@hamishmack hamishmack added the preserved Keep stale bot away label Sep 30, 2022
@facundominguez
Copy link
Author

@facundominguez did the above code work in the end?

It worked well enough. Instead of using remote-iserv we moved to using ghc-iserv directly.
Here is the exact configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preserved Keep stale bot away
Projects
None yet
Development

No branches or pull requests

2 participants