Skip to content

make-disk-image: add useVirtualDevices option #1008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JuneStepp
Copy link

@JuneStepp JuneStepp commented Apr 2, 2025

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 = {
            ...
          };
        };
      };
    };
  };
}

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.

1 participant