mirror of
https://github.com/nix-community/raspberry-pi-nix.git
synced 2025-11-25 11:49:36 +01:00
nix: format treewide
This commit is contained in:
parent
150128c843
commit
2abf8951ef
8 changed files with 493 additions and 506 deletions
|
|
@ -13,57 +13,53 @@
|
|||
# table, so the partition table id is a 1-indexed hex
|
||||
# number. So, we drop the hex prefix and stick on a "02" to
|
||||
# refer to the root partition.
|
||||
"root=PARTUUID=${lib.strings.removePrefix "0x" config.sdImage.firmwarePartitionID}-02"
|
||||
"root=PARTUUID=${
|
||||
lib.strings.removePrefix "0x" config.sdImage.firmwarePartitionID
|
||||
}-02"
|
||||
"rootfstype=ext4"
|
||||
"fsck.repair=yes"
|
||||
"rootwait"
|
||||
];
|
||||
|
||||
sdImage =
|
||||
let
|
||||
kernel-params = pkgs.writeTextFile {
|
||||
name = "cmdline.txt";
|
||||
text = ''
|
||||
${lib.strings.concatStringsSep " " config.boot.kernelParams}
|
||||
'';
|
||||
};
|
||||
cfg = config.raspberry-pi-nix;
|
||||
version = cfg.kernel-version;
|
||||
board = cfg.board;
|
||||
kernel = "${config.system.build.kernel}/${config.system.boot.loader.kernelFile}";
|
||||
initrd = "${config.system.build.initialRamdisk}/${config.system.boot.loader.initrdFile}";
|
||||
populate-kernel =
|
||||
if cfg.uboot.enable
|
||||
then ''
|
||||
cp ${cfg.uboot.package}/u-boot.bin firmware/u-boot-rpi-arm64.bin
|
||||
''
|
||||
else ''
|
||||
cp "${kernel}" firmware/kernel.img
|
||||
cp "${initrd}" firmware/initrd
|
||||
cp "${kernel-params}" firmware/cmdline.txt
|
||||
'';
|
||||
in
|
||||
{
|
||||
populateFirmwareCommands = ''
|
||||
${populate-kernel}
|
||||
cp -r ${pkgs.raspberrypifw}/share/raspberrypi/boot/{start*.elf,*.dtb,bootcode.bin,fixup*.dat,overlays} firmware
|
||||
cp ${config.hardware.raspberry-pi.config-output} firmware/config.txt
|
||||
sdImage = let
|
||||
kernel-params = pkgs.writeTextFile {
|
||||
name = "cmdline.txt";
|
||||
text = ''
|
||||
${lib.strings.concatStringsSep " " config.boot.kernelParams}
|
||||
'';
|
||||
populateRootCommands =
|
||||
if cfg.uboot.enable
|
||||
then ''
|
||||
mkdir -p ./files/boot
|
||||
${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot
|
||||
''
|
||||
else ''
|
||||
mkdir -p ./files/sbin
|
||||
content="$(
|
||||
echo "#!${pkgs.bash}/bin/bash"
|
||||
echo "exec ${config.system.build.toplevel}/init"
|
||||
)"
|
||||
echo "$content" > ./files/sbin/init
|
||||
chmod 744 ./files/sbin/init
|
||||
'';
|
||||
};
|
||||
cfg = config.raspberry-pi-nix;
|
||||
version = cfg.kernel-version;
|
||||
board = cfg.board;
|
||||
kernel =
|
||||
"${config.system.build.kernel}/${config.system.boot.loader.kernelFile}";
|
||||
initrd =
|
||||
"${config.system.build.initialRamdisk}/${config.system.boot.loader.initrdFile}";
|
||||
populate-kernel = if cfg.uboot.enable then ''
|
||||
cp ${cfg.uboot.package}/u-boot.bin firmware/u-boot-rpi-arm64.bin
|
||||
'' else ''
|
||||
cp "${kernel}" firmware/kernel.img
|
||||
cp "${initrd}" firmware/initrd
|
||||
cp "${kernel-params}" firmware/cmdline.txt
|
||||
'';
|
||||
in {
|
||||
populateFirmwareCommands = ''
|
||||
${populate-kernel}
|
||||
cp -r ${pkgs.raspberrypifw}/share/raspberrypi/boot/{start*.elf,*.dtb,bootcode.bin,fixup*.dat,overlays} firmware
|
||||
cp ${config.hardware.raspberry-pi.config-output} firmware/config.txt
|
||||
'';
|
||||
populateRootCommands = if cfg.uboot.enable then ''
|
||||
mkdir -p ./files/boot
|
||||
${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot
|
||||
'' else ''
|
||||
mkdir -p ./files/sbin
|
||||
content="$(
|
||||
echo "#!${pkgs.bash}/bin/bash"
|
||||
echo "exec ${config.system.build.toplevel}/init"
|
||||
)"
|
||||
echo "$content" > ./files/sbin/init
|
||||
chmod 744 ./files/sbin/init
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,8 +30,7 @@ let
|
|||
} // optionalAttrs (config.sdImage.rootPartitionUUID != null) {
|
||||
uuid = config.sdImage.rootPartitionUUID;
|
||||
});
|
||||
in
|
||||
{
|
||||
in {
|
||||
imports = [ ];
|
||||
|
||||
options.sdImage = {
|
||||
|
|
@ -153,7 +152,8 @@ in
|
|||
config = {
|
||||
fileSystems = {
|
||||
"/boot/firmware" = {
|
||||
device = "/dev/disk/by-label/${config.raspberry-pi-nix.firmware-partition-label}";
|
||||
device =
|
||||
"/dev/disk/by-label/${config.raspberry-pi-nix.firmware-partition-label}";
|
||||
fsType = "vfat";
|
||||
};
|
||||
"/" = {
|
||||
|
|
@ -164,81 +164,80 @@ in
|
|||
|
||||
sdImage.storePaths = [ config.system.build.toplevel ];
|
||||
|
||||
system.build.sdImage = pkgs.callPackage
|
||||
({ stdenv, dosfstools, e2fsprogs, mtools, libfaketime, util-linux, zstd }:
|
||||
stdenv.mkDerivation {
|
||||
name = config.sdImage.imageName;
|
||||
system.build.sdImage = pkgs.callPackage ({ stdenv, dosfstools, e2fsprogs
|
||||
, mtools, libfaketime, util-linux, zstd, }:
|
||||
stdenv.mkDerivation {
|
||||
name = config.sdImage.imageName;
|
||||
|
||||
nativeBuildInputs =
|
||||
[ dosfstools e2fsprogs mtools libfaketime util-linux zstd ];
|
||||
nativeBuildInputs =
|
||||
[ dosfstools e2fsprogs mtools libfaketime util-linux zstd ];
|
||||
|
||||
inherit (config.sdImage) compressImage;
|
||||
inherit (config.sdImage) compressImage;
|
||||
|
||||
buildCommand = ''
|
||||
mkdir -p $out/nix-support $out/sd-image
|
||||
export img=$out/sd-image/${config.sdImage.imageName}
|
||||
buildCommand = ''
|
||||
mkdir -p $out/nix-support $out/sd-image
|
||||
export img=$out/sd-image/${config.sdImage.imageName}
|
||||
|
||||
echo "${pkgs.stdenv.buildPlatform.system}" > $out/nix-support/system
|
||||
if test -n "$compressImage"; then
|
||||
echo "file sd-image $img.zst" >> $out/nix-support/hydra-build-products
|
||||
else
|
||||
echo "file sd-image $img" >> $out/nix-support/hydra-build-products
|
||||
fi
|
||||
echo "${pkgs.stdenv.buildPlatform.system}" > $out/nix-support/system
|
||||
if test -n "$compressImage"; then
|
||||
echo "file sd-image $img.zst" >> $out/nix-support/hydra-build-products
|
||||
else
|
||||
echo "file sd-image $img" >> $out/nix-support/hydra-build-products
|
||||
fi
|
||||
|
||||
echo "Decompressing rootfs image"
|
||||
zstd -d --no-progress "${rootfsImage}" -o ./root-fs.img
|
||||
echo "Decompressing rootfs image"
|
||||
zstd -d --no-progress "${rootfsImage}" -o ./root-fs.img
|
||||
|
||||
# Gap in front of the first partition, in MiB
|
||||
gap=${toString config.sdImage.firmwarePartitionOffset}
|
||||
# Gap in front of the first partition, in MiB
|
||||
gap=${toString config.sdImage.firmwarePartitionOffset}
|
||||
|
||||
# Create the image file sized to fit /boot/firmware and /, plus slack for the gap.
|
||||
rootSizeBlocks=$(du -B 512 --apparent-size ./root-fs.img | awk '{ print $1 }')
|
||||
firmwareSizeBlocks=$((${
|
||||
toString config.sdImage.firmwareSize
|
||||
} * 1024 * 1024 / 512))
|
||||
imageSize=$((rootSizeBlocks * 512 + firmwareSizeBlocks * 512 + gap * 1024 * 1024))
|
||||
truncate -s $imageSize $img
|
||||
# Create the image file sized to fit /boot/firmware and /, plus slack for the gap.
|
||||
rootSizeBlocks=$(du -B 512 --apparent-size ./root-fs.img | awk '{ print $1 }')
|
||||
firmwareSizeBlocks=$((${
|
||||
toString config.sdImage.firmwareSize
|
||||
} * 1024 * 1024 / 512))
|
||||
imageSize=$((rootSizeBlocks * 512 + firmwareSizeBlocks * 512 + gap * 1024 * 1024))
|
||||
truncate -s $imageSize $img
|
||||
|
||||
# type=b is 'W95 FAT32', type=83 is 'Linux'.
|
||||
# The "bootable" partition is where u-boot will look file for the bootloader
|
||||
# information (dtbs, extlinux.conf file).
|
||||
sfdisk $img <<EOF
|
||||
label: dos
|
||||
label-id: ${config.sdImage.firmwarePartitionID}
|
||||
# type=b is 'W95 FAT32', type=83 is 'Linux'.
|
||||
# The "bootable" partition is where u-boot will look file for the bootloader
|
||||
# information (dtbs, extlinux.conf file).
|
||||
sfdisk $img <<EOF
|
||||
label: dos
|
||||
label-id: ${config.sdImage.firmwarePartitionID}
|
||||
|
||||
start=''${gap}M, size=$firmwareSizeBlocks, type=b
|
||||
start=$((gap + ${
|
||||
toString config.sdImage.firmwareSize
|
||||
}))M, type=83, bootable
|
||||
EOF
|
||||
start=''${gap}M, size=$firmwareSizeBlocks, type=b
|
||||
start=$((gap + ${
|
||||
toString config.sdImage.firmwareSize
|
||||
}))M, type=83, bootable
|
||||
EOF
|
||||
|
||||
# Copy the rootfs into the SD image
|
||||
eval $(partx $img -o START,SECTORS --nr 2 --pairs)
|
||||
dd conv=notrunc if=./root-fs.img of=$img seek=$START count=$SECTORS
|
||||
# Copy the rootfs into the SD image
|
||||
eval $(partx $img -o START,SECTORS --nr 2 --pairs)
|
||||
dd conv=notrunc if=./root-fs.img of=$img seek=$START count=$SECTORS
|
||||
|
||||
# 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.raspberry-pi-nix.firmware-partition-label} firmware_part.img
|
||||
# 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.raspberry-pi-nix.firmware-partition-label} firmware_part.img
|
||||
|
||||
# Populate the files intended for /boot/firmware
|
||||
mkdir firmware
|
||||
${config.sdImage.populateFirmwareCommands}
|
||||
# Populate the files intended for /boot/firmware
|
||||
mkdir firmware
|
||||
${config.sdImage.populateFirmwareCommands}
|
||||
|
||||
# Copy the populated /boot/firmware into the SD image
|
||||
(cd firmware; mcopy -psvm -i ../firmware_part.img ./* ::)
|
||||
# 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
|
||||
# Copy the populated /boot/firmware into the SD image
|
||||
(cd firmware; mcopy -psvm -i ../firmware_part.img ./* ::)
|
||||
# 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
|
||||
|
||||
${config.sdImage.postBuildCommands}
|
||||
${config.sdImage.postBuildCommands}
|
||||
|
||||
if test -n "$compressImage"; then
|
||||
zstd -T$NIX_BUILD_CORES --rm $img
|
||||
fi
|
||||
'';
|
||||
})
|
||||
{ };
|
||||
if test -n "$compressImage"; then
|
||||
zstd -T$NIX_BUILD_CORES --rm $img
|
||||
fi
|
||||
'';
|
||||
}) { };
|
||||
|
||||
boot.postBootCommands = lib.mkIf config.sdImage.expandOnBoot ''
|
||||
# On the first boot do some maintenance tasks
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue