1# To build, use:
2# nix-build nixos -I nixos-config=nixos/modules/installer/sd-card/sd-image-raspberrypi.nix -A config.system.build.sdImage
3{ config, lib, pkgs, ... }:
4
5{
6 imports = [
7 ../../profiles/base.nix
8 ./sd-image.nix
9 ];
10
11 boot.loader.grub.enable = false;
12 boot.loader.generic-extlinux-compatible.enable = true;
13
14 boot.consoleLogLevel = lib.mkDefault 7;
15 boot.kernelPackages = pkgs.linuxKernel.packages.linux_rpi1;
16
17 sdImage = {
18 populateFirmwareCommands = let
19 configTxt = pkgs.writeText "config.txt" ''
20 # Prevent the firmware from smashing the framebuffer setup done by the mainline kernel
21 # when attempting to show low-voltage or overtemperature warnings.
22 avoid_warnings=1
23
24 [pi0]
25 kernel=u-boot-rpi0.bin
26
27 [pi1]
28 kernel=u-boot-rpi1.bin
29 '';
30 in ''
31 (cd ${pkgs.raspberrypifw}/share/raspberrypi/boot && cp bootcode.bin fixup*.dat start*.elf $NIX_BUILD_TOP/firmware/)
32 cp ${pkgs.ubootRaspberryPiZero}/u-boot.bin firmware/u-boot-rpi0.bin
33 cp ${pkgs.ubootRaspberryPi}/u-boot.bin firmware/u-boot-rpi1.bin
34 cp ${configTxt} firmware/config.txt
35 '';
36 populateRootCommands = ''
37 mkdir -p ./files/boot
38 ${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot
39 '';
40 };
41}