Skip to content

make-disk-image: add useVirtualDevices option#1008

Open
JuneStepp wants to merge 1 commit into
nix-community:masterfrom
JuneStepp:virtual-devices-option
Open

make-disk-image: add useVirtualDevices option#1008
JuneStepp wants to merge 1 commit into
nix-community:masterfrom
JuneStepp:virtual-devices-option

Conversation

@JuneStepp

@JuneStepp JuneStepp commented Apr 2, 2025

Copy link
Copy Markdown
Member

I've been using Disko to both configure filesystems on my phone and create the initial images that are flashed. The only problem was that the installed config would have its device names overwritten. This PR adds an option to chose if the virtual/cleaned device names should be installed or not. They're still always used during partitioning.

For those curious, here's an example phone Disko config:

expand me
# This config is NOT meant to be used with the Disko CLI. It should only be used with
# the Disko image builder. It represents the boot and root images that will be
# created with Disko image builder and flashed to the phone. NixOS is then able to find
# the partitions using /dev/disk/by-label based on this config.
{
  disko.devices.disk = {
    boot = let
      label = "nixos-boot";
    in {
      type = "disk";
      device = "/dev/disk/by-label/${label}";
      imageName = label;
      # vfat can't be auto-expanded by NixOS, so the initial image size must be
      # the final desired size.
      imageSize = "2G";
      content = {
        type = "filesystem";
        format = "vfat";
        mountpoint = "/boot";
        mountOptions = [
          # See https://github.com/nix-community/disko/issues/527
          "umask=0077"
          # Continuous Discard/trim For SSDs. This partition is small and not written
          # to a ton, so I doubt performance will be an issue.
          "discard"
        ];
        extraArgs = [
          "-n"
          label
          # Sector size.
          "-S"
          "4096"
        ];
      };
    };
    root = let
      label = "nixos-root";
    in {
      type = "disk";
      device = "/dev/disk/by-label/${label}";
      imageName = label;
      imageSize = "5G";
      content = {
        type = "luks";
        name = "crypt";
        settings = {
          # Enable discard/TRIM support. fstrim shouldn't be needed, b/c BTRFS
          # discard=async is default.
          # See https://wiki.archlinux.org/title/Dm-crypt/Specialties#Discard/TRIM_support_for_solid_state_drives_(SSD)
          allowDiscards = true;
          # Improve SSD performance.
          # See https://wiki.archlinux.org/title/Dm-crypt/Specialties#Disable_workqueue_for_increased_solid_state_drive_(SSD)_performance
          bypassWorkqueues = true;
        };
        extraFormatArgs = [
          "--label"
          label
          "--sector-size"
          "4096"
        ];
        # Just for initial encryption in the VM.
        passwordFile = "/tmp/nixos-root.key";
        content = {
          type = "btrfs";
          extraArgs = [
            "--sectorsize"
            "4096"
            "--force" # Force overrite existing partition
          ];
          subvolumes = {
            ...
          };
        };
      };
    };
  };
}

Comment thread module.nix
default = "raw";
};

useVirtualDevices = lib.mkOption {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still quite don't understand why this is needed after partitioning. Are we not using partition labels in any case?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also boot.loader.grub.devices.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mic92 Thoughts?

@JuneStepp JuneStepp requested a review from Mic92 May 3, 2025 01:36
@JuneStepp

Copy link
Copy Markdown
Member Author

@Enzime Are you perhaps able to look at this or know who can?

@JuneStepp JuneStepp force-pushed the virtual-devices-option branch 3 times, most recently from 939da32 to 6834fb0 Compare May 6, 2026 03:07
@JuneStepp

Copy link
Copy Markdown
Member Author

I'd still really love to get this merged. I see you've been active @Lassulus, do you mind taking a look?

@JuneStepp JuneStepp force-pushed the virtual-devices-option branch from 6834fb0 to 7eeff12 Compare May 16, 2026 19:35
@JuneStepp JuneStepp force-pushed the virtual-devices-option branch from 7eeff12 to 10f31ba Compare June 14, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants