diff options
Diffstat (limited to 'nixpkgs/nixos/modules/installer/sd-card/sd-image.nix')
-rw-r--r-- | nixpkgs/nixos/modules/installer/sd-card/sd-image.nix | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/nixpkgs/nixos/modules/installer/sd-card/sd-image.nix b/nixpkgs/nixos/modules/installer/sd-card/sd-image.nix index c0335ea48759..ad9b803b1d1e 100644 --- a/nixpkgs/nixos/modules/installer/sd-card/sd-image.nix +++ b/nixpkgs/nixos/modules/installer/sd-card/sd-image.nix @@ -35,14 +35,14 @@ in options.sdImage = { imageName = mkOption { default = "${config.sdImage.imageBaseName}-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}.img"; - description = '' + description = lib.mdDoc '' Name of the generated image file. ''; }; imageBaseName = mkOption { default = "nixos-sd-image"; - description = '' + description = lib.mdDoc '' Prefix of the name of the generated image file. ''; }; @@ -50,7 +50,7 @@ in storePaths = mkOption { type = with types; listOf package; example = literalExpression "[ pkgs.stdenv ]"; - description = '' + description = lib.mdDoc '' Derivations to be included in the Nix store in the generated SD image. ''; }; @@ -58,7 +58,7 @@ in firmwarePartitionOffset = mkOption { type = types.int; default = 8; - description = '' + description = lib.mdDoc '' Gap in front of the /boot/firmware partition, in mebibytes (1024×1024 bytes). Can be increased to make more space for boards requiring to dd u-boot @@ -74,7 +74,7 @@ in firmwarePartitionID = mkOption { type = types.str; default = "0x2178694e"; - description = '' + description = lib.mdDoc '' Volume ID for the /boot/firmware partition on the SD card. This value must be a 32-bit hexadecimal number. ''; @@ -83,7 +83,7 @@ in firmwarePartitionName = mkOption { type = types.str; default = "FIRMWARE"; - description = '' + description = lib.mdDoc '' Name of the filesystem which holds the boot firmware. ''; }; @@ -92,7 +92,7 @@ in type = types.nullOr types.str; default = null; example = "14e19a7b-0ae0-484d-9d54-43bd6fdc20c7"; - description = '' + description = lib.mdDoc '' UUID for the filesystem on the main NixOS partition on the SD card. ''; }; @@ -101,14 +101,14 @@ in type = types.int; # As of 2019-08-18 the Raspberry pi firmware + u-boot takes ~18MiB default = 30; - description = '' + description = lib.mdDoc '' Size of the /boot/firmware partition, in megabytes. ''; }; populateFirmwareCommands = mkOption { example = literalExpression "'' cp \${pkgs.myBootLoader}/u-boot.bin firmware/ ''"; - description = '' + description = lib.mdDoc '' Shell commands to populate the ./firmware directory. All files in that directory are copied to the /boot/firmware partition on the SD image. @@ -117,7 +117,7 @@ in populateRootCommands = mkOption { example = literalExpression "''\${config.boot.loader.generic-extlinux-compatible.populateCmd} -c \${config.system.build.toplevel} -d ./files/boot''"; - description = '' + description = lib.mdDoc '' Shell commands to populate the ./files directory. All files in that directory are copied to the root (/) partition on the SD image. Use this to @@ -128,7 +128,7 @@ in postBuildCommands = mkOption { example = literalExpression "'' dd if=\${pkgs.myBootLoader}/SPL of=$img bs=1024 seek=1 conv=notrunc ''"; default = ""; - description = '' + description = lib.mdDoc '' Shell commands to run after the image is built. Can be used for boards requiring to dd u-boot SPL before actual partitions. ''; @@ -137,16 +137,16 @@ in compressImage = mkOption { type = types.bool; default = true; - description = '' + description = lib.mdDoc '' Whether the SD image should be compressed using - <command>zstd</command>. + {command}`zstd`. ''; }; expandOnBoot = mkOption { type = types.bool; default = true; - description = '' + description = lib.mdDoc '' Whether to configure the sd image to expand it's partition on boot. ''; }; @@ -224,14 +224,25 @@ in # Create a FAT32 /boot/firmware partition of suitable size into firmware_part.img eval $(partx $img -o START,SECTORS --nr 1 --pairs) truncate -s $((SECTORS * 512)) firmware_part.img - faketime "1970-01-01 00:00:00" mkfs.vfat -i ${config.sdImage.firmwarePartitionID} -n ${config.sdImage.firmwarePartitionName} firmware_part.img + + mkfs.vfat --invariant -i ${config.sdImage.firmwarePartitionID} -n ${config.sdImage.firmwarePartitionName} firmware_part.img # Populate the files intended for /boot/firmware mkdir firmware ${config.sdImage.populateFirmwareCommands} + find firmware -exec touch --date=2000-01-01 {} + # Copy the populated /boot/firmware into the SD image - (cd firmware; mcopy -psvm -i ../firmware_part.img ./* ::) + cd firmware + # Force a fixed order in mcopy for better determinism, and avoid file globbing + for d in $(find . -type d -mindepth 1 | sort); do + faketime "2000-01-01 00:00:00" mmd -i ../firmware_part.img "::/$d" + done + for f in $(find . -type f | sort); do + mcopy -pvm -i ../firmware_part.img "$f" "::/$f" + done + cd .. + # Verify the FAT partition before copying it. fsck.vfat -vn firmware_part.img dd conv=notrunc if=firmware_part.img of=$img seek=$START count=$SECTORS |