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

NixOS remote builder with cross compilation #60101

Open
anna328p opened this issue Apr 23, 2019 · 8 comments
Open

NixOS remote builder with cross compilation #60101

anna328p opened this issue Apr 23, 2019 · 8 comments
Labels
6.topic: cross-compilation Building packages on a different sort platform than than they will be run on 9.needs: documentation

Comments

@anna328p
Copy link
Member

Issue description

Is there an established method of using a remote builder with a cross compiler?

I am attempting to run NixOS on a Raspberry Pi using the armv7 architecture, but there is very little software built for it in Hydra so much of the configuration has to be compiled. This compilation process has now been running for three days.

Is there a way to run a builder daemon on my x86_64 system to cross compile to ARM more quickly?

@matthewbauer
Copy link
Member

Yeah you can have a NixOS config that is cross compiled. The trick is to set localSystem = { system = "x86_64-linux"; }; so that rebuilds still happen on your x86_64 machine. Something like this should work:

{ pkgs, lib, config, ... }:

# Build with:
#
# nix build '((import <nixpkgs/nixos/lib/eval-config.nix> { modules = [ ./configuration.nix ]; }).config.system.build.sdImage)'

{
  imports = [
    <nixpkgs/nixos/modules/installer/cd-dvd/sd-image-raspberrypi.nix>
  ];

  boot.loader.raspberryPi.enable = true;
  boot.loader.grub.enable = false;
  boot.kernelPackages = pkgs.linuxPackages_rpi;

  # Setup cross compilation.
  nixpkgs = {
    crossSystem = lib.systems.elaborate lib.systems.examples.raspberryPi;
    localSystem = { system = "x86_64-linux"; };
  };

  nix.distributedBuilds = true;
  nix.buildMachines = [ {
    hostName = "linux64.example.org";
    sshUser = "buildfarm";
    sshKey = "/root/.ssh/id_buildfarm";
    system = "x86_64-linux";
  } ];

  # Enable tools for remote installation.
  services.openssh.enable = true;
  networking.wireless.enable = true;
  security.sudo.enable = true;
  hardware.enableRedistributableFirmware = true;

  # Setup headless mode.
  systemd.enableEmergencyMode = false;
  documentation.enable = false;
  services.nixosManual.showManual = lib.mkForce false;

}

You need to copy it to the installation afterwards and setup the ssh keys for remote buildings. This means that every time you run nixos-rebuild you will build on your x86_64 machine. Unfortunately, you won't be able to build natively because Nix doesn't recognize that x86_64 -> armv7l compilation is the same thing as armv7l -> armv7l compilation.

@FRidh
Copy link
Member

FRidh commented Apr 25, 2019

Maybe it's still too early for it but otherwise I think it would be good to add a section on cross-compiling NixOS to the NixOS manual.

@FRidh FRidh added 9.needs: documentation 6.topic: cross-compilation Building packages on a different sort platform than than they will be run on labels Apr 25, 2019
@matthewbauer matthewbauer added this to the 19.09 milestone May 27, 2019
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/remote-cross-compiled-builds-for-macos-darwin-from-nixos-remote/5963/1

@stale

This comment has been minimized.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 17, 2020
@Atemu
Copy link
Member

Atemu commented Aug 18, 2020

Still important to me.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 18, 2020
@anna328p
Copy link
Member Author

for reference, I ended up moving to the Raspberry Pi 4 platform and using aarch64 as both the build and host architecture. I also needed to add extra-platforms = aarch64-linux arm-linux to /etc/nix/nix.conf. this meant that nix fetched prebuilt binaries from Hydra and I did not have to cross-compile anything.

@Fuseteam
Copy link
Contributor

Fuseteam commented Nov 29, 2020

this sounds useful for armv7 phones aswell, i'm looking into using nix-pkgs on ubuntu-touch phones

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: cross-compilation Building packages on a different sort platform than than they will be run on 9.needs: documentation
Projects
None yet
Development

No branches or pull requests

8 participants
@matthewbauer @veprbl @FRidh @anna328p @Fuseteam @Atemu @nixos-discourse and others