From 7e7d6b01f727d3763bd3736e3f0301e1ef251bd0 Mon Sep 17 00:00:00 2001 From: arcnmx Date: Thu, 5 Sep 2024 18:56:30 -0700 Subject: [PATCH] feat(sakuya): system.build.sdImage --- systems/sakuya/nixos.nix | 44 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/systems/sakuya/nixos.nix b/systems/sakuya/nixos.nix index 89df99af..cecb8ba4 100644 --- a/systems/sakuya/nixos.nix +++ b/systems/sakuya/nixos.nix @@ -1,11 +1,15 @@ { + pkgs, config, + modulesPath, meta, ... }: { imports = let inherit (meta) nixos; in [ + (modulesPath + "/installer/sd-card/sd-image.nix") + nixos.base nixos.sops nixos.tailscale ]; @@ -13,9 +17,47 @@ grub.enable = false; generic-extlinux-compatible.enable = true; }; + sdImage = let + # TODO: boot0 requires additional BSL processing applied to the uboot bin: + # https://github.com/longsleep/build-pine64-image/tree/master/u-boot-postprocess + uboot = pkgs.ubootPine64; + # Arch Linux ARM has already done this for us... + ubootPrepackagedARM = pkgs.fetchurl { + url = "http://os.archlinuxarm.org/os/allwinner/boot/pine64/u-boot-sunxi-with-spl.bin"; + sha256 = "sha256-qT5M93p/t7eW6lqZq4dC8z8BkYcQOkTgiN+jZatObuo="; + }; + ubootProcessed = ubootPrepackagedARM; + in { + postBuildCommands = '' + dd if=${ubootProcessed} of=$img bs=8k seek=1 + ''; + # taken from sd-image-aarch64.nix + populateFirmwareCommands = let + configTxt = pkgs.writeText "config.txt" '' + [all] + # Boot in 64-bit mode. + arm_64bit=1 + + # U-Boot needs this to work, regardless of whether UART is actually used or not. + # Look in arch/arm/mach-bcm283x/Kconfig in the U-Boot tree to see if this is still + # a requirement in the future. + enable_uart=1 + + # Prevent the firmware from smashing the framebuffer setup done by the mainline kernel + # when attempting to show low-voltage or overtemperature warnings. + avoid_warnings=1 + ''; + in '' + cp ${configTxt} firmware/config.txt + ''; + populateRootCommands = '' + mkdir -p ./files/boot + ${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot + ''; + }; fileSystems."/" = { - device = "/dev/disk/by-uuid/44444444-4444-4444-8888-888888888888"; + device = "/dev/disk/by-label/NIXOS_SD"; fsType = "ext4"; };