{ config, lib, pkgs, ... }: { imports = [ ./configuration.nix ]; nixpkgs.overlays = [(import ./u-boot.nix)]; sdImage.populateRootCommands = '' mkdir -p ./files/boot ${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot mkdir -p files/etc/nixos cp -r ${pkgs.nix-gitignore.gitignoreSource [] ./.}/* ./files/etc/nixos/ ''; system.build.sdImage = with lib; let rootfsImage = pkgs.callPackage ./make-btrfs-fs.nix ({ inherit (config.sdImage) storePaths; compressImage = true; populateImageCommands = config.sdImage.populateRootCommands; volumeLabel = "bold-emmc"; } // optionalAttrs (config.sdImage.rootPartitionUUID != null) { uuid = config.sdImage.rootPartitionUUID; }); in pkgs.callPackage ({ stdenv, dosfstools, e2fsprogs, mtools, libfaketime, utillinux, bzip2, zstd }: stdenv.mkDerivation { name = config.sdImage.imageName; nativeBuildInputs = [ dosfstools e2fsprogs mtools libfaketime utillinux bzip2 zstd ]; inherit (config.sdImage) compressImage; diskUUID = "A8ABB0FA-2FD7-4FB8-ABB0-2EEB7CD66AFA"; loadUUID = "534078AF-3BB4-EC43-B6C7-828FB9A788C6"; bootUUID = "95D89D52-CA00-42D6-883F-50F5720EF37E"; rootUUID = "0340EA1D-C827-8048-B631-0C60D4478796"; buildCommand = '' mkdir -p $out/nix-support $out/sd-image export img=${config.sdImage.imageName} echo "${pkgs.stdenv.buildPlatform.system}" > $out/nix-support/system echo "Decompressing rootfs image" zstd -d --no-progress "${rootfsImage}" -o ./root-fs.img # Create the image file sized to fit /boot/firmware and /, plus slack for the gap. rootSizeBlocks=$(du -B 512 --apparent-size ./root-fs.img | awk '{ print $1 }') # rootfs will be at offset 0x8000, so we'll need to account for that. # And add an additional 20mb slack at the end. imageSize=$((0x8000 + rootSizeBlocks * 512 + 20 * 1024 * 1024)) truncate -s $imageSize $img sfdisk --no-reread --no-tell-kernel $img <