nixfiles/hosts/raspberry/hardware.nix
2024-08-31 14:24:08 +01:00

111 lines
2.4 KiB
Nix

{
tree,
pkgs,
lib,
...
}: let
inherit (lib.modules) mkForce;
inherit (lib.lists) forEach foldl';
inherit (lib.attrsets) recursiveUpdate mapAttrsToList;
inherit (builtins) toFile concatStringsSep;
edk2 = pkgs.fetchzip {
url = "https://github.com/worproject/rpi5-uefi/releases/download/v0.3/RPi5_UEFI_Release_v0.3.zip";
hash = "sha256-bjEvq7KlEFANnFVL0LyexXEeoXj7rHGnwQpq09PhIb0=";
stripRoot = false;
};
fwFiles = let
piBootFw = "${pkgs.raspberrypifw}/share/raspberrypi/boot";
piBootFwFiles = foldl' recursiveUpdate {} (forEach [
"bootcode.bin"
"start.elf"
"fixup_cd.dat"
"fixup.dat"
"fixup_db.dat"
"fixup_x.dat"
"fixup4cd.dat"
"fixup4.dat"
"fixup4db.dat"
"fixup4x.dat"
"start_cd.elf"
"start_db.elf"
"start.elf"
"start_x.elf"
"start4cd.elf"
"start4db.elf"
"start4.elf"
"start4x.elf"
] (file: {
"${file}" = "${piBootFw}/${file}";
}));
in
{
"config.txt" = toFile "config.txt" ''
armstub=RPI_EFI.fd
device_tree_address=0x1f0000
device_tree_end=0x210000
# Makes GPU work?
dtoverlay=vc4-kms-v3d-pi5
# Force 32 bpp framebuffer allocation.
framebuffer_depth=32
# Disable compensation for displays with overscan.
disable_overscan=1
# Force maximum USB power regardless of the power supply.
usb_max_current_enable=1
# Force maximum CPU speed.
force_turbo=1
'';
# UEFI Files
"RPI_EFI.fd" = "${edk2}/RPI_EFI.fd";
"bcm2712-rpi-5-b.dtb" = "${edk2}/bcm2712-rpi-5-b.dtb";
}
// piBootFwFiles;
in {
imports = with tree; [
presets.nixos.encryptedDrive
];
boot = {
kernelPackages = pkgs.linuxPackages_rpi4;
supportedFilesystems = mkForce ["vfat"];
loader = {
systemd-boot = {
enable = true;
extraFiles = fwFiles;
};
efi.canTouchEfiVariables = false;
grub.enable = false;
generic-extlinux-compatible.enable = false;
};
initrd.availableKernelModules = [
"nvme"
"ehci_pci"
"xhci_pci"
"usb_storage"
"sd_mod"
"sdhci_pci"
];
};
system.build.firmware = pkgs.runCommand "firmware" {} ''
mkdir $out
${concatStringsSep "\n" (
mapAttrsToList (filename: path: ''
cp ${path} $out/${filename}
'')
fwFiles
)}
'';
}