{ pkgs }: let imageName = "orange"; firmwarePartition = { offset = 8; id = "0xfeed3425"; name = "FIRMWARE"; size = 512; }; rootfsImage = import ./rootfs.nix { inherit pkgs; }; configTxt = pkgs.writeText "config.txt" (builtins.readFile ./config.txt); populateFirmwareCommands = '' # Add config.txt cp ${configTxt} firmware/config.txt # Copy the firmware files cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bootcode.bin firmware/ cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/fixup*.dat firmware/ cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/start*.elf firmware/ # Add pi3 specific files cp ${pkgs.ubootRaspberryPi3_64bit}/u-boot.bin firmware/u-boot-rpi3.bin ''; in pkgs.stdenv.mkDerivation { name = imageName; nativeBuildInputs = with pkgs; [ dosfstools e2fsprogs libfaketime mtools util-linux zstd ]; buildCommand = '' mkdir -p $out/nix-support $out/sd-image export img=$out/sd-image/${imageName} echo "${pkgs.stdenv.buildPlatform.system}" > $out/nix-support/system echo "file sd-image $img.zst" >> $out/nix-support/hydra-build-products root_fs=${rootfsImage} # Gap in front of the first partition, in MiB gap=${toString firmwarePartition.offset} # Create the image file sized to fit /boot/firmware and /, plus slack for the gap. rootSizeBlocks=$(du -B 512 --apparent-size $root_fs | awk '{ print $1 }') firmwareSizeBlocks=$((${toString firmwarePartition.size} * 1024 * 1024 / 512)) imageSize=$((rootSizeBlocks * 512 + firmwareSizeBlocks * 512 + gap * 1024 * 1024)) truncate -s $imageSize $img # type=b is 'W95 FAT32', type=83 is 'Linux'. # The "bootable" partition is where u-boot will look file for the bootloader # information (dtbs, extlinux.conf file). sfdisk $img <