!oNSIfazDqEcwhcOjSL:matrix.org

disko

367 Members
disko - declarative disk partitioning - https://github.com/nix-community/disko93 Servers

Load older messages


SenderMessageTime
19 May 2024
@matthewcroughan:defenestrate.itmatthewcroughan

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:defenestrate.itmatthewcroughan *

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:defenestrate.itmatthewcroughan 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:defenestrate.itmatthewcroughan U-boot requires the legacy bios bootable flag on the root partition where /boot/extlinux resides 11:30:00
@matthewcroughan:defenestrate.itmatthewcroughanbut u-boot doesn't support loading extlinux from bcachefs yet, so I need a little fat/ext4 partition containing it11:30:46
@matthewcroughan:defenestrate.itmatthewcroughansystemd-repart can't do bcachefs due to needing loopback though11:33:04
@matthewcroughan:defenestrate.itmatthewcroughanOh, 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:lassul.uslassulusI think compression is fine as a hook. But we need more documentation for that11:37:54
@matthewcroughan:defenestrate.itmatthewcroughan 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:defenestrate.itmatthewcroughanthe same way systemd-repart does11:38:43
@matthewcroughan:defenestrate.itmatthewcroughan Arguably, hardware-configuration.nix and associated stuff is the real pollution, and disko/repart fix that 11:39:20
@matthewcroughan:defenestrate.itmatthewcroughanFound https://github.com/nix-community/disko/pull/384 which sorta documents the compression you can apply with extraPostVM11:41:52
@matthewcroughan:defenestrate.itmatthewcroughan

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:defenestrate.itmatthewcroughanJust a comment from lassulus, so what is the variable to get the disk image?11:42:26
@matthewcroughan:defenestrate.itmatthewcroughan I don't see an example of doing it, is it just $out?} 11:42:36
@matthewcroughan:defenestrate.itmatthewcroughan * I don't see an example of doing it, is it just $out? 11:42:37
@matthewcroughan:defenestrate.itmatthewcroughan ah right it's $out/*.raw isn't it? 11:43:22
@lassulus:lassul.uslassulusYes11:43:41
@matthewcroughan:defenestrate.itmatthewcroughan 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:defenestrate.itmatthewcroughan * 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:defenestrate.itmatthewcroughanI 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" problem11:45:29
@lassulus:lassul.uslassulusThere are so many different compressions11:45:49
@matthewcroughan:defenestrate.itmatthewcroughanyeah systemd-repart in nixpkgs has a string option for this11:46:00
@matthewcroughan:defenestrate.itmatthewcroughanhttps://github.com/NixOS/nixpkgs/blob/master/nixos/modules/image/repart.nix#L108-L12311:46:22
@matthewcroughan:defenestrate.itmatthewcroughanjust an enum for xz or zstd11:46:28
@lassulus:lassul.uslassulusBut a script option is more powerful11:46:51
@matthewcroughan:defenestrate.itmatthewcroughanWell 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 them11:47:38
@matthewcroughan:defenestrate.itmatthewcroughanThough 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 exists11:48:13
@matthewcroughan:defenestrate.itmatthewcroughan 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:defenestrate.itmatthewcroughanAlthough I do agree it's difficult to decide what should and shouldn't be available, as this option might just annoy others11:50:08

Show newer messages


Back to Room ListRoom Version: 10