1# To build, use:
2# nix-build nixos -I nixos-config=nixos/modules/installer/cd-dvd/sd-image-aarch64.nix -A config.system.build.sdImage
3{ config, lib, pkgs, ... }:
4
5let
6 extlinux-conf-builder =
7 import ../../system/boot/loader/generic-extlinux-compatible/extlinux-conf-builder.nix {
8 inherit pkgs;
9 };
10in
11{
12 imports = [
13 ../../profiles/base.nix
14 ../../profiles/installation-device.nix
15 ./sd-image.nix
16 ];
17
18 assertions = lib.singleton {
19 assertion = pkgs.stdenv.system == "aarch64-linux";
20 message = "sd-image-aarch64.nix can be only built natively on Aarch64 / ARM64; " +
21 "it cannot be cross compiled";
22 };
23
24 # Needed by RPi firmware
25 nixpkgs.config.allowUnfree = true;
26
27 boot.loader.grub.enable = false;
28 boot.loader.generic-extlinux-compatible.enable = true;
29
30 boot.consoleLogLevel = lib.mkDefault 7;
31 boot.kernelPackages = pkgs.linuxPackages_latest;
32
33 # The serial ports listed here are:
34 # - ttyS0: for Tegra (Jetson TX1)
35 # - ttyAMA0: for QEMU's -machine virt
36 # Also increase the amount of CMA to ensure the virtual console on the RPi3 works.
37 boot.kernelParams = ["cma=32M" "console=ttyS0,115200n8" "console=ttyAMA0,115200n8" "console=tty0"];
38
39 # FIXME: this probably should be in installation-device.nix
40 users.extraUsers.root.initialHashedPassword = "";
41
42 sdImage = {
43 populateBootCommands = let
44 configTxt = pkgs.writeText "config.txt" ''
45 kernel=u-boot-rpi3.bin
46
47 # Boot in 64-bit mode.
48 arm_control=0x200
49
50 # U-Boot used to need this to work, regardless of whether UART is actually used or not.
51 # TODO: check when/if this can be removed.
52 enable_uart=1
53
54 # Prevent the firmware from smashing the framebuffer setup done by the mainline kernel
55 # when attempting to show low-voltage or overtemperature warnings.
56 avoid_warnings=1
57 '';
58 in ''
59 (cd ${pkgs.raspberrypifw}/share/raspberrypi/boot && cp bootcode.bin fixup*.dat start*.elf $NIX_BUILD_TOP/boot/)
60 cp ${pkgs.ubootRaspberryPi3_64bit}/u-boot.bin boot/u-boot-rpi3.bin
61 cp ${configTxt} boot/config.txt
62 ${extlinux-conf-builder} -t 3 -c ${config.system.build.toplevel} -d ./boot
63 '';
64 };
65}