From 4e139026b506e2339c6ce224e2f7ad1e4bb4fa4b Mon Sep 17 00:00:00 2001 From: Jared Baur Date: Fri, 26 Jan 2024 22:26:46 -0800 Subject: [PATCH 1/2] nixos/repart: add option for configuring sector size This option is helpful for situations when the target host disk's sector size differs from that of the build host. --- nixos/modules/image/repart-image.nix | 2 ++ nixos/modules/image/repart.nix | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/nixos/modules/image/repart-image.nix b/nixos/modules/image/repart-image.nix index a12b4fb14fb1..7ac47ee32ff4 100644 --- a/nixos/modules/image/repart-image.nix +++ b/nixos/modules/image/repart-image.nix @@ -32,6 +32,7 @@ , split , seed , definitionsDirectory +, sectorSize }: let @@ -94,6 +95,7 @@ runCommand imageFileBasename --definitions="$amendedRepartDefinitions" \ --split="${lib.boolToString split}" \ --json=pretty \ + ${lib.optionalString (sectorSize != null) "--sector-size=${toString sectorSize}"} \ ${imageFileBasename}.raw \ | tee repart-output.json diff --git a/nixos/modules/image/repart.nix b/nixos/modules/image/repart.nix index ed584d9bf997..6a933f0d83cc 100644 --- a/nixos/modules/image/repart.nix +++ b/nixos/modules/image/repart.nix @@ -135,6 +135,16 @@ in ''; }; + sectorSize = lib.mkOption { + type = with lib.types; nullOr int; + default = 512; + example = lib.literalExpression "4096"; + description = lib.mdDoc '' + The sector size of the disk image produced by systemd-repart. This + value must be a power of 2 between 512 and 4096. + ''; + }; + package = lib.mkPackageOption pkgs "systemd-repart" { # We use buildPackages so that repart images are built with the build # platform's systemd, allowing for cross-compiled systems to work. @@ -232,7 +242,7 @@ in in pkgs.callPackage ./repart-image.nix { systemd = cfg.package; - inherit (cfg) imageFileBasename compression split seed; + inherit (cfg) imageFileBasename compression split seed sectorSize; inherit fileSystems definitionsDirectory partitions; }; From 0bf5f3be2512b2770bb8c4f45a7b7b1956909300 Mon Sep 17 00:00:00 2001 From: Jared Baur Date: Fri, 26 Jan 2024 22:27:50 -0800 Subject: [PATCH 2/2] appliance-repart-image: fix OVMF not detecting disk With the update of systemd to v255, the repart tool switched to use 4K sector sizes by default. This change sets the appliance-repart-image test to use a sector size of 512B to fit in with the existing NixOS VM test infrastructure using qemu disks with 512B sector sizes. --- nixos/tests/appliance-repart-image.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nixos/tests/appliance-repart-image.nix b/nixos/tests/appliance-repart-image.nix index b18968d3b963..861369b9f3ca 100644 --- a/nixos/tests/appliance-repart-image.nix +++ b/nixos/tests/appliance-repart-image.nix @@ -40,6 +40,8 @@ in image.repart = { name = "appliance-gpt-image"; + # OVMF does not work with the default repart sector size of 4096 + sectorSize = 512; partitions = { "esp" = { contents =