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

Raspberry Pi cross compilation branch #53065

Merged
merged 4 commits into from Jan 3, 2019

Conversation

matthewbauer
Copy link
Member

Motivation for this change

Work on cross compiling raspberry pi images.

Using this for my example configuration:

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

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

let
  extlinux-conf-builder =
    import ../../system/boot/loader/generic-extlinux-compatible/extlinux-conf-builder.nix {
      pkgs = pkgs.buildPackages;
    };
in

{
  imports = [
    <nixpkgs/nixos/modules/profiles/base.nix>
    <nixpkgs/nixos/modules/profiles/installation-device.nix>
    <nixpkgs/nixos/modules/installer/cd-dvd/sd-image.nix>

    # Custom sets up some things specific to the user.

    # Sets stuff like:
    # - timezone (time.timeZone)
    # - users (users.users.<user>)
    # - authorized ssh keys (users.users.<user>.openssh.authorizedKeys)
    # - wifi password (networking.wireless.networks)
    # - ddclient (services.ddclient)
    # - miniupnpc

    ./custom.nix
  ];

  sdImage = {
    populateBootCommands = let
      configTxt = pkgs.writeText "config.txt" ''
        # Prevent the firmware from smashing the framebuffer setup done by the mainline kernel
        # when attempting to show low-voltage or overtemperature warnings.
        avoid_warnings=1

        [pi0]
        kernel=u-boot-rpi0.bin

        [pi1]
        kernel=u-boot-rpi1.bin
      '';
      in ''
        (cd ${pkgs.raspberrypifw}/share/raspberrypi/boot && cp bootcode.bin fixup*.dat start*.elf $NIX_BUILD_TOP/boot/)
        cp ${pkgs.ubootRaspberryPiZero}/u-boot.bin boot/u-boot-rpi0.bin
        cp ${pkgs.ubootRaspberryPi}/u-boot.bin boot/u-boot-rpi1.bin
        cp ${configTxt} boot/config.txt
        ${extlinux-conf-builder} -t 3 -c ${config.system.build.toplevel} -d ./boot
      '';
  };

  boot.loader.grub.enable = false;
  boot.loader.generic-extlinux-compatible.enable = true;
  boot.consoleLogLevel = lib.mkDefault 7;
  boot.kernelPackages = pkgs.linuxPackages_rpi;
  boot.kernelParams = [
    "panic=1"
    "boot.panic_on_fail"
  ];

  # Setup cross compilation.
  nixpkgs = {
    overlays = [(self: super: {
      libnl = super.libnl.override { pythonSupport = false; };
      gobject-introspection = super.gobject-introspection.override {
        x11Support = false;
      };
      dbus = super.dbus.override { x11Support = false; };
    }) ];
    config = {};
    crossSystem = lib.systems.elaborate lib.systems.examples.raspberryPi;
    localSystem = { 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;

  # Disable some stuff that doesn’t cross compile.
  services.nscd.enable = false;
  services.udisks2.enable = false;
  boot.supportedFilesystems = lib.mkForce [ "vfat" ];
  environment.systemPackages = lib.mkForce [ ];
  security.polkit.enable = false;
  fonts.fontconfig.enable = false;
  programs.command-not-found.enable = false;
  programs.ssh.setXAuthLocation = false;
  security.pam.services.su.forwardXAuth = lib.mkForce false;

}

@nixos-discourse
Copy link

This pull request has been mentioned on Nix community. There might be relevant details there:

https://discourse.nixos.org/t/slides-from-my-35c3-cross-compile-workshop/1785/7

sd-image-raspberrypi, sd-image-aarch64, and
sd-image-armv7l-multiplatform can all be cross compiled now.
@matthewbauer matthewbauer merged commit 9b0e45b into NixOS:staging Jan 3, 2019
@matthewbauer matthewbauer deleted the rpi-cross-fixes branch February 22, 2019 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants