Switches to full nixos config.

WHY was I rewriting this from scratch??
This commit is contained in:
Bailey 2023-04-19 20:28:26 -04:00
parent 7bf87946d2
commit 597f83b324
4 changed files with 21 additions and 125 deletions

View file

@ -1,16 +0,0 @@
[pi02]
kernel=u-boot-rpi3.bin
core_freq=250
[all]
# Boot in 64-bit mode.
arm_64bit=1
# U-Boot needs this to work, regardless of whether UART is actually used or not.
# Look in arch/arm/mach-bcm283x/Kconfig in the U-Boot tree to see if this is still
# a requirement in the future.
enable_uart=1
# Prevent the firmware from smashing the framebuffer setup done by the mainline kernel
# when attempting to show low-voltage or overtemperature warnings.
avoid_warnings=1

View file

@ -17,17 +17,14 @@
{
apps.default = {
type = "app";
program = "${self.outputs.packages.${system}.vmscript}/bin/vmscript";
program = self.outputs.packages.${system}.vmscript + "/bin/vmscript";
};
packages = {
default = import ./sd-card.nix { inherit pkgs crossPkgs; };
uncompressed = import ./sd-card.nix { inherit pkgs crossPkgs; compress = false; };
vmscript = pkgs.writeScriptBin "vmscript" ''
packages.vmscript = pkgs.writeScriptBin "vmscript" ''
#!${pkgs.runtimeShell} -e
img=./sd-card.img
cp -b ${self.outputs.packages.${system}.uncompressed}/sd-card.img $img
cp -b ${self.outputs.image}/sd-image/orange.img $img
chmod 640 $img
truncate -s %2G $img
${pkgs.qemu}/bin/qemu-system-aarch64 \
-machine raspi3b \
-kernel "${crossPkgs.ubootRaspberryPi3_64bit}/u-boot.bin" \
@ -39,8 +36,22 @@
-serial null \
-serial mon:stdio
'';
}) // {
nixosConfigurations.orange = nixpkgs.lib.nixosSystem {
modules = [
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
{
boot.kernelParams = [ "console=ttyS1,115200n8" ];
networking.hostName = "orange";
system.stateVersion = "23.05";
nixpkgs.hostPlatform.system = "aarch64-linux";
sdImage = {
imageName = "orange.img";
compressImage = false;
};
}
];
};
image = self.outputs.nixosConfigurations.orange.config.system.build.sdImage;
};
});
}

View file

@ -1,12 +0,0 @@
{ pkgs }:
pkgs.stdenv.mkDerivation {
name = "orange-rootfs.img.zstd";
nativeBuildInputs = with pkgs; [ zstd ];
buildCommand = ''
truncate -s 512M ./rootfs.img
zstd -T$NIX_BUILD_CORES ./rootfs.img -o $out
'';
}

View file

@ -1,87 +0,0 @@
{ pkgs, crossPkgs, compress ? true}:
let
fwPart = {
offset = 8;
id = "0xfeed3425";
name = "FIRMWARE";
size = 512;
};
rootfsImage = import ./rootfs.nix { inherit pkgs; };
configTxt = pkgs.writeText "config.txt" (builtins.readFile ./config.txt);
populateFirmwareCommands = ''
# Add config.txt
cp ${configTxt} firmware/config.txt
# Copy the firmware files
cp ${crossPkgs.raspberrypifw}/share/raspberrypi/boot/bootcode.bin firmware/
cp ${crossPkgs.raspberrypifw}/share/raspberrypi/boot/fixup*.dat firmware/
cp ${crossPkgs.raspberrypifw}/share/raspberrypi/boot/start*.elf firmware/
# Add pi3 specific files
cp ${crossPkgs.ubootRaspberryPi3_64bit}/u-boot.bin firmware/u-boot-rpi3.bin
'';
in
pkgs.stdenv.mkDerivation {
name = "orange";
nativeBuildInputs = with pkgs; [ dosfstools e2fsprogs libfaketime mtools util-linux zstd ];
buildCommand = ''
mkdir $out
img=$out/sd-card.img
root_fs=./rootfs.img
zstd -d --no-progress "${rootfsImage}" -o $root_fs
# Create the image file sized to fit /boot/firmware and /, plus slack for the gap.
rootSizeBlocks=$(du -B 512 --apparent-size $root_fs | awk '{ print $1 }')
firmwareSizeBlocks=$((${toString fwPart.size} * 1024 * 1024 / 512))
imageSize=$((rootSizeBlocks * 512 + firmwareSizeBlocks * 512))
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: ${fwPart.id}
start=${toString fwPart.offset}M, size=${toString (fwPart.size - fwPart.offset)}M, type=b
start=${toString fwPart.size}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 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
mkfs.vfat --invariant -i ${toString fwPart.size} -n ${fwPart.name} firmware_part.img
# Populate the files intended for /boot/firmware
mkdir firmware
${populateFirmwareCommands}
find firmware -exec touch --date=2000-01-01 {} +
# Copy the populated /boot/firmware into the SD image
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
${pkgs.lib.optionalString compress ''
zstd -T$NIX_BUILD_CORES --rm $img
''}
'';
}