sdImage: make partition ID/UUID configurable

This commit is contained in:
Andrew Dunham 2018-07-06 20:59:19 -07:00 committed by Tuomas Tynkkynen
parent 99670bbb91
commit d7bfd04301
2 changed files with 24 additions and 3 deletions

View File

@ -5,6 +5,7 @@
{ pkgs
, storePaths
, volumeLabel
, uuid ? "44444444-4444-4444-8888-888888888888"
}:
let
@ -32,7 +33,7 @@ pkgs.stdenv.mkDerivation {
echo "Creating an EXT4 image of $bytes bytes (numInodes=$numInodes, numDataBlocks=$numDataBlocks)"
truncate -s $bytes $out
faketime -f "1970-01-01 00:00:01" mkfs.ext4 -L ${volumeLabel} -U 44444444-4444-4444-8888-888888888888 $out
faketime -f "1970-01-01 00:00:01" mkfs.ext4 -L ${volumeLabel} -U ${uuid} $out
# Populate the image contents by piping a bunch of commands to the `debugfs` tool from e2fsprogs.
# For example, to copy /nix/store/abcd...efg-coreutils-8.23/bin/sleep:

View File

@ -16,6 +16,8 @@ let
inherit pkgs;
inherit (config.sdImage) storePaths;
volumeLabel = "NIXOS_SD";
} // optionalAttrs (config.sdImage.rootPartitionUUID != null) {
uuid = config.sdImage.rootPartitionUUID;
};
in
{
@ -42,6 +44,24 @@ in
'';
};
bootPartitionID = mkOption {
type = types.string;
default = "0x2178694e";
description = ''
Volume ID for the /boot partition on the SD card. This value must be a
32-bit hexadecimal number.
'';
};
rootPartitionUUID = mkOption {
type = types.nullOr types.string;
default = null;
example = "14e19a7b-0ae0-484d-9d54-43bd6fdc20c7";
description = ''
UUID for the main NixOS partition on the SD card.
'';
};
bootSize = mkOption {
type = types.int;
default = 120;
@ -95,7 +115,7 @@ in
# type=b is 'W95 FAT32', type=83 is 'Linux'.
sfdisk $img <<EOF
label: dos
label-id: 0x2178694e
label-id: ${config.sdImage.bootPartitionID}
start=8M, size=$bootSizeBlocks, type=b, bootable
start=${toString (8 + config.sdImage.bootSize)}M, type=83
@ -108,7 +128,7 @@ in
# Create a FAT32 /boot partition of suitable size into bootpart.img
eval $(partx $img -o START,SECTORS --nr 1 --pairs)
truncate -s $((SECTORS * 512)) bootpart.img
faketime "1970-01-01 00:00:00" mkfs.vfat -i 0x2178694e -n NIXOS_BOOT bootpart.img
faketime "1970-01-01 00:00:00" mkfs.vfat -i ${config.sdImage.bootPartitionID} -n NIXOS_BOOT bootpart.img
# Populate the files intended for /boot
mkdir boot