@@ -0,0 +1,63 @@
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+
5+let
6+ extlinux-conf-builder =
7+ import ../../system/boot/loader/generic-extlinux-compatible/extlinux-conf-builder.nix {
8+ inherit pkgs;
9+ };
10+in
11+{
12+ imports = [
13+ ../../profiles/minimal.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.kernelPackages = pkgs.linuxPackages_latest;
31+ boot.kernelParams = ["console=ttyS0,115200n8" "console=tty0"];
32+ boot.consoleLogLevel = 7;
33+
34+ # FIXME: this probably should be in installation-device.nix
35+ users.extraUsers.root.initialHashedPassword = "";
36+
37+ sdImage = {
38+ populateBootCommands = let
39+ # Contains a couple of fixes for booting a Linux kernel, will hopefully appear upstream soon.
40+ patchedUboot = pkgs.ubootRaspberryPi3_64bit.overrideAttrs (oldAttrs: {
41+ src = pkgs.fetchFromGitHub {
42+ owner = "dezgeg";
43+ repo = "u-boot";
44+ rev = "baab53ec244fe44def01948a0f10e67342d401e6";
45+ sha256 = "0r5j2pc42ws3w3im0a9c6bh01czz5kapqrqp0ik9ra823cw73lxr";
46+ };
47+ });
48+
49+ configTxt = pkgs.writeText "config.txt" ''
50+ kernel=u-boot-rpi3.bin
51+ arm_control=0x200
52+ enable_uart=1
53+ '';
54+ in ''
55+ for f in bootcode.bin fixup.dat start.elf; do
56+ cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/$f boot/
57+ done
58+ cp ${patchedUboot}/u-boot.bin boot/u-boot-rpi3.bin
59+ cp ${configTxt} boot/config.txt
60+ ${extlinux-conf-builder} -t 3 -c ${config.system.build.toplevel} -d ./boot
61+ '';
62+ };
63+}