| 19 May 2024 |
matthewcroughan | This is pretty close to working
{ pkgs, ... }:
let
configTxt = pkgs.writeText "config.txt" ''
[pi4]
kernel=u-boot-rpi4.bin
enable_gic=1
# Otherwise the resolution will be weird in most cases, compared to
# what the pi3 firmware does by default.
disable_overscan=1
# Supported in newer board revisions
arm_boost=1
[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1
[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
{
disko.devices = {
disk = {
disk1 = {
imageSize = "10G";
type = "disk";
device = "/dev/mmcblk0";
postCreateHook = ''
lsblk
sgdisk -A 2:set:2 /dev/vdb
'';
content = {
type = "gpt";
partitions = {
firmware = {
size = "30M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/firmware";
postMountHook = toString (pkgs.writeScript "postMountHook.sh" ''
(cd ${pkgs.raspberrypifw}/share/raspberrypi/boot && cp bootcode.bin fixup*.dat start*.elf *.dtb /mnt/firmware/)
cp ${pkgs.ubootRaspberryPi4_64bit}/u-boot.bin /mnt/firmware/u-boot-rpi4.bin
cp ${configTxt} /mnt/firmware/config.txt
'');
};
};
root = {
name = "root";
size = "100%";
content = {
type = "filesystem";
format = "bcachefs";
mountpoint = "/";
};
};
};
};
};
};
};
}
| 11:29:10 |
matthewcroughan | * This is pretty close to working
{ pkgs, ... }:
let
configTxt = pkgs.writeText "config.txt" ''
[pi4]
kernel=u-boot-rpi4.bin
enable_gic=1
# Otherwise the resolution will be weird in most cases, compared to
# what the pi3 firmware does by default.
disable_overscan=1
# Supported in newer board revisions
arm_boost=1
[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1
[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
{
disko.devices = {
disk = {
disk1 = {
imageSize = "10G";
type = "disk";
device = "/dev/mmcblk0";
postCreateHook = ''
lsblk
sgdisk -A 2:set:2 /dev/vdb
'';
content = {
type = "gpt";
partitions = {
firmware = {
size = "30M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/firmware";
postMountHook = toString (pkgs.writeScript "postMountHook.sh" ''
(cd ${pkgs.raspberrypifw}/share/raspberrypi/boot && cp bootcode.bin fixup*.dat start*.elf *.dtb /mnt/firmware/)
cp ${pkgs.ubootRaspberryPi4_64bit}/u-boot.bin /mnt/firmware/u-boot-rpi4.bin
cp ${configTxt} /mnt/firmware/config.txt
'');
};
};
root = {
name = "root";
size = "100%";
content = {
type = "filesystem";
format = "bcachefs";
mountpoint = "/";
};
};
};
};
};
};
};
}
| 11:29:15 |
matthewcroughan | Note sgdisk -A 2:set:2 /dev/vdb because of Pi/U-Boot interactions when using GPT only without a PMBR | 11:29:41 |
matthewcroughan | U-boot requires the legacy bios bootable flag on the root partition where /boot/extlinux resides | 11:30:00 |
matthewcroughan | but u-boot doesn't support loading extlinux from bcachefs yet, so I need a little fat/ext4 partition containing it | 11:30:46 |
matthewcroughan | systemd-repart can't do bcachefs due to needing loopback though | 11:33:04 |
matthewcroughan | Oh, in addition to compression not being a module option, there's also image resizing, which would be a really nice to have, though maybe it's not in disko's domain, I am not sure about it | 11:37:37 |
lassulus | I think compression is fine as a hook. But we need more documentation for that | 11:37:54 |
matthewcroughan | Disko already "pollutes?" the NixOS Configuration with the automatic filesystems options, so maybe it should also handle disk resizing if enabled as a module option | 11:38:39 |
matthewcroughan | the same way systemd-repart does | 11:38:43 |
matthewcroughan | Arguably, hardware-configuration.nix and associated stuff is the real pollution, and disko/repart fix that | 11:39:20 |
matthewcroughan | Found https://github.com/nix-community/disko/pull/384 which sorta documents the compression you can apply with extraPostVM | 11:41:52 |
matthewcroughan |
usually the extraPostVM is used to compress the image. so not sure we would need to pass it in this case
| 11:42:16 |
matthewcroughan | Just a comment from lassulus, so what is the variable to get the disk image? | 11:42:26 |
matthewcroughan | I don't see an example of doing it, is it just $out?} | 11:42:36 |
matthewcroughan | * I don't see an example of doing it, is it just $out? | 11:42:37 |
matthewcroughan | ah right it's $out/*.raw isn't it? | 11:43:22 |
lassulus | Yes | 11:43:41 |
matthewcroughan | You wouldn't like to have a compressImage = true which just does this for the user on a per-disk basis/ | 11:44:55 |
matthewcroughan | * You wouldn't like to have a compressImage = true which just does this for the user on a per-disk basis? | 11:44:56 |
matthewcroughan | I suppose that wouldn't really be in line with rfc42.. making an option for everything is bad, but this is pure nix and not a "we should use the upstream configuration" problem | 11:45:29 |
lassulus | There are so many different compressions | 11:45:49 |
matthewcroughan | yeah systemd-repart in nixpkgs has a string option for this | 11:46:00 |
matthewcroughan | https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/image/repart.nix#L108-L123 | 11:46:22 |
matthewcroughan | just an enum for xz or zstd | 11:46:28 |
lassulus | But a script option is more powerful | 11:46:51 |
matthewcroughan | Well yeah, I guess.. you're copying the mkDerivation pattern, but there are still tons of options you can set inside of mkDerivation, I'm constantly learning about them | 11:47:38 |
matthewcroughan | Though they're not set in the module system, they're just vars interpreted by the stdenv bash scripts, which may have been a mistake, hence why drv-parts exists | 11:48:13 |
matthewcroughan | the module option compressImage would just set up the extraPostVM. When you think about what people really want to do with a disk image builder, this is definitely nice to just have be there by default | 11:49:44 |
matthewcroughan | Although I do agree it's difficult to decide what should and shouldn't be available, as this option might just annoy others | 11:50:08 |