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/installation-device.nix
14 ./sd-image.nix
15 ];
16
17 assertions = lib.singleton {
18 assertion = pkgs.stdenv.system == "aarch64-linux";
19 message = "sd-image-aarch64.nix can be only built natively on Aarch64 / ARM64; " +
20 "it cannot be cross compiled";
21 };
22
23 # Needed by RPi firmware
24 nixpkgs.config.allowUnfree = true;
25
26 boot.loader.grub.enable = false;
27 boot.loader.generic-extlinux-compatible.enable = true;
28
29 boot.kernelPackages = pkgs.linuxPackages_latest;
30 boot.kernelParams = ["console=ttyS0,115200n8" "console=tty0"];
31 boot.consoleLogLevel = 7;
32
33 # FIXME: this probably should be in installation-device.nix
34 users.extraUsers.root.initialHashedPassword = "";
35
36 sdImage = {
37 populateBootCommands = let
38 # Contains a couple of fixes for booting a Linux kernel, will hopefully appear upstream soon.
39 patchedUboot = pkgs.ubootRaspberryPi3_64bit.overrideAttrs (oldAttrs: {
40 src = pkgs.fetchFromGitHub {
41 owner = "dezgeg";
42 repo = "u-boot";
43 rev = "baab53ec244fe44def01948a0f10e67342d401e6";
44 sha256 = "0r5j2pc42ws3w3im0a9c6bh01czz5kapqrqp0ik9ra823cw73lxr";
45 };
46 });
47
48 configTxt = pkgs.writeText "config.txt" ''
49 kernel=u-boot-rpi3.bin
50 arm_control=0x200
51 enable_uart=1
52 '';
53 in ''
54 (cd ${pkgs.raspberrypifw}/share/raspberrypi/boot && cp bootcode.bin fixup*.dat start*.elf $NIX_BUILD_TOP/boot/)
55 cp ${patchedUboot}/u-boot.bin boot/u-boot-rpi3.bin
56 cp ${configTxt} boot/config.txt
57 ${extlinux-conf-builder} -t 3 -c ${config.system.build.toplevel} -d ./boot
58 '';
59 };
60}