From a1b4cadb531bc5777ac5910a42b53bca12d35c22 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Wed, 24 May 2023 09:33:32 -0400 Subject: [PATCH 01/97] populate firmware partition via systemd service Only copy files from modified packages. --- README.md | 15 ++++--- rpi/default.nix | 117 +++++++++++++++++++++++++++++++++++------------- 2 files changed, 93 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 3e30cc2..2924949 100644 --- a/README.md +++ b/README.md @@ -87,8 +87,8 @@ the aarch64 installation media from nixpkgs: There is a firmware partition that contains necessary firmware, u-boot, and config.txt. Then there is another partition (labeled `NIXOS_SD`) that contains everything else. The firmware and `config.txt` file are -managed by NixOS modules defined in this package. Additionally, NixOS -system activation will update the firmware and `config.txt` in the +managed by NixOS modules defined in this package. Additionally, a +systemd service will update the firmware and `config.txt` in the firmware partition __in place__. Linux kernels are stored in the `NIXOS_SD` partition and will be booted by u-boot in the firmware partition. @@ -96,7 +96,8 @@ partition. ## `config.txt` generation As noted, the `config.txt` file is generated by the NixOS -configuration and automatically updated on system activation. +configuration and automatically updated on when the nix configuration +is modified. The relevant nixos option is `hardware.raspberry-pi.config`. Configuration is partitioned into @@ -254,8 +255,8 @@ device tree configuration is controlled via the [config.txt file](https://www.raspberrypi.com/documentation/computers/config_txt.html). Additionally, the firmware, device trees, and overlays from the -`raspberrypifw` package populate the firmware partition on system -activation. This package is kept up to date by the overlay applied by -this package, so you don't need configure this. However, if you want -to use different firmware you can override that package to do so. +`raspberrypifw` package populate the firmware partition. This package +is kept up to date by the overlay applied by this package, so you +don't need configure this. However, if you want to use different +firmware you can override that package to do so. diff --git a/rpi/default.nix b/rpi/default.nix index 27ce29f..671369d 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -4,43 +4,96 @@ { imports = [ ../sd-image ./config.nix ./i2c.nix ]; - # On activation install u-boot, Raspberry Pi firmware, and our - # generated config.txt - system.activationScripts.raspberrypi = { - text = '' - shopt -s nullglob + systemd.services = { + "raspberry-pi-firmware-migrate" = { + description = "update the firmware partition"; + wantedBy = [ "multi-user.target" ]; + serviceConfig = let firmware-path = "/boot/firmware"; + in { + Type = "oneshot"; + MountImages = + "/dev/disk/by-label/${config.sdImage.firmwarePartitionName}:${firmware-path}"; + StateDirectory = "raspberrypi-firmware"; + ExecStart = pkgs.writeShellScript "migrate-rpi-firmware" '' + shopt -s nullglob - TARGET_FIRMWARE_DIR="/boot/firmware" - TARGET_OVERLAYS_DIR="$TARGET_FIRMWARE_DIR/overlays" - TMPFILE="$TARGET_FIRMWARE_DIR/tmp" - UBOOT="${pkgs.uboot_rpi_arm64}/u-boot.bin" - SRC_FIRMWARE_DIR="${pkgs.raspberrypifw}/share/raspberrypi/boot" - STARTFILES=("$SRC_FIRMWARE_DIR"/start*.elf) - DTBS=("$SRC_FIRMWARE_DIR"/*.dtb) - BOOTCODE="$SRC_FIRMWARE_DIR/bootcode.bin" - FIXUPS=("$SRC_FIRMWARE_DIR"/fixup*.dat) - SRC_OVERLAYS_DIR="$SRC_FIRMWARE_DIR/overlays" - SRC_OVERLAYS=("$SRC_OVERLAYS_DIR"/*) - CONFIG="${config.hardware.raspberry-pi.config-output}" + TARGET_FIRMWARE_DIR="${firmware-path}" + TARGET_OVERLAYS_DIR="$TARGET_FIRMWARE_DIR/overlays" + TMPFILE="$TARGET_FIRMWARE_DIR/tmp" + UBOOT="${pkgs.uboot_rpi_arm64}/u-boot.bin" + SRC_FIRMWARE_DIR="${pkgs.raspberrypifw}/share/raspberrypi/boot" + STARTFILES=("$SRC_FIRMWARE_DIR"/start*.elf) + DTBS=("$SRC_FIRMWARE_DIR"/*.dtb) + BOOTCODE="$SRC_FIRMWARE_DIR/bootcode.bin" + FIXUPS=("$SRC_FIRMWARE_DIR"/fixup*.dat) + SRC_OVERLAYS_DIR="$SRC_FIRMWARE_DIR/overlays" + SRC_OVERLAYS=("$SRC_OVERLAYS_DIR"/*) + CONFIG="${config.hardware.raspberry-pi.config-output}" - cp "$UBOOT" "$TMPFILE" - mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/u-boot-rpi-arm64.bin" + migrate_uboot() { + echo "migrating uboot" + touch "$STATE_DIRECTORY/uboot-migration-in-progress" + cp "$UBOOT" "$TMPFILE" + mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/u-boot-rpi-arm64.bin" + echo "${ + builtins.toString pkgs.uboot_rpi_arm64 + }" > "$STATE_DIRECTORY/uboot-version" + rm "$STATE_DIRECTORY/uboot-migration-in-progress" + } - cp "$CONFIG" "$TMPFILE" - mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/config.txt" + migrate_config() { + echo "migrating config.txt" + touch "$STATE_DIRECTORY/config-migration-in-progress" + cp "$CONFIG" "$TMPFILE" + mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/config.txt" + echo "${config.hardware.raspberry-pi.config-output}" > "$STATE_DIRECTORY/config-version" + rm "$STATE_DIRECTORY/config-migration-in-progress" + } - for SRC in "''${STARTFILES[@]}" "''${DTBS[@]}" "$BOOTCODE" "''${FIXUPS[@]}" - do - cp "$SRC" "$TMPFILE" - mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/$(basename "$SRC")" - done + migrate_firmware() { + echo "migrating raspberrypi firmware" + touch "$STATE_DIRECTORY/firmware-migration-in-progress" + for SRC in "''${STARTFILES[@]}" "''${DTBS[@]}" "$BOOTCODE" "''${FIXUPS[@]}" + do + cp "$SRC" "$TMPFILE" + mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/$(basename "$SRC")" + done - for SRC in "''${SRC_OVERLAYS[@]}" - do - cp "$SRC" "$TMPFILE" - mv -T "$TMPFILE" "$TARGET_OVERLAYS_DIR/$(basename "$SRC")" - done - ''; + if [[ ! -d "$TARGET_OVERLAYS_DIR" ]]; then + mkdir "$TARGET_OVERLAYS_DIR" + fi + + for SRC in "''${SRC_OVERLAYS[@]}" + do + cp "$SRC" "$TMPFILE" + mv -T "$TMPFILE" "$TARGET_OVERLAYS_DIR/$(basename "$SRC")" + done + echo "${ + builtins.toString pkgs.raspberrypifw + }" > "$STATE_DIRECTORY/firmware-version" + rm "$STATE_DIRECTORY/firmware-migration-in-progress" + } + + if [[ -f "$STATE_DIRECTORY/uboot-migration-in-progress" || ! -f "$STATE_DIRECTORY/uboot-version" || $(< "$STATE_DIRECTORY/uboot-version") != ${ + builtins.toString pkgs.uboot_rpi_arm64 + } ]]; then + migrate_uboot + fi + + if [[ -f "$STATE_DIRECTORY/config-migration-in-progress" || ! -f "$STATE_DIRECTORY/config-version" || $(< "$STATE_DIRECTORY/config-version") != ${ + builtins.toString config.hardware.raspberry-pi.config-output + } ]]; then + migrate_config + fi + + if [[ -f "$STATE_DIRECTORY/firmware-migration-in-progress" || ! -f "$STATE_DIRECTORY/firmware-version" || $(< "$STATE_DIRECTORY/firmware-version") != ${ + builtins.toString pkgs.raspberrypifw + } ]]; then + migrate_firmware + fi + ''; + }; + }; }; # Default config.txt on Raspberry Pi OS: From 4d207117b71a638e22861a9cd8ff3f9c3b47fa18 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Wed, 24 May 2023 21:28:20 -0400 Subject: [PATCH 02/97] add example link to readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 2924949..536cbf1 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,10 @@ and `rpi/config.nix`. The other modules are mostly wrappers that set ## Example +See [the example +repo](https://github.com/tstat/raspberry-pi-nix-example) for a +complete example. + ```nix { description = "raspberry-pi-nix example"; From 561355cba6ac18835e265d6ecaddadb59feaf8c2 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Tue, 30 May 2023 17:55:28 -0400 Subject: [PATCH 03/97] add cache to example --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 536cbf1..686af80 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,12 @@ complete example. ```nix { description = "raspberry-pi-nix example"; + nixConfig = { + extra-substituters = [ "https://raspberry-pi-nix.cachix.org" ]; + extra-trusted-public-keys = [ + "raspberry-pi-nix.cachix.org-1:WmV2rdSangxW0rZjY/tBvBDSaNFQ3DyEQsVw8EvHn9o=" + ]; + }; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11"; raspberry-pi-nix.url = "github:tstat/raspberry-pi-nix"; From 43258812a1b8c3dc1ae791e93ffbdbc27f2e0a7e Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Sat, 10 Jun 2023 07:22:03 -0400 Subject: [PATCH 04/97] update flake inputs --- flake.lock | 55 +++++++++++++++------------------------------ flake.nix | 10 ++++----- overlay/default.nix | 23 ++++++++++++------- 3 files changed, 38 insertions(+), 50 deletions(-) diff --git a/flake.lock b/flake.lock index d248256..06af588 100644 --- a/flake.lock +++ b/flake.lock @@ -3,16 +3,16 @@ "libcamera-apps-src": { "flake": false, "locked": { - "lastModified": 1674645888, - "narHash": "sha256-UBTDHN0lMj02enB8im4Q+f/MCm/G2mFPP3pLImrZc5A=", + "lastModified": 1677660281, + "narHash": "sha256-A6UriYk8bHRL6wp6ehXOnUnbJH2/mNDkxwGemD/UYpw=", "owner": "raspberrypi", "repo": "libcamera-apps", - "rev": "9f08463997b82c4bf60e12c4ea43577959a8ae15", + "rev": "54a781dffdd101954dcfa6acd0bd80006f67da83", "type": "github" }, "original": { "owner": "raspberrypi", - "ref": "v1.1.1", + "ref": "v1.1.2", "repo": "libcamera-apps", "type": "github" } @@ -22,9 +22,8 @@ "libcamera-apps-src": "libcamera-apps-src", "rpi-bluez-firmware-src": "rpi-bluez-firmware-src", "rpi-firmware-nonfree-src": "rpi-firmware-nonfree-src", - "rpi-firmware-stable-src": "rpi-firmware-stable-src", - "rpi-linux-5_15-src": "rpi-linux-5_15-src", - "rpi-linux-5_15_87-src": "rpi-linux-5_15_87-src", + "rpi-firmware-src": "rpi-firmware-src", + "rpi-linux-6_1-src": "rpi-linux-6_1-src", "u-boot-src": "u-boot-src" } }, @@ -47,11 +46,11 @@ "rpi-firmware-nonfree-src": { "flake": false, "locked": { - "lastModified": 1674638139, - "narHash": "sha256-54JKmwypD7PRQdd7k6IcF7wL8ifMavEM0UwZwmA24O4=", + "lastModified": 1683107406, + "narHash": "sha256-9UgB8f2AaxG7S5Px46jOP9wUeO1VXKB0uJiPWh32oDI=", "owner": "RPi-Distro", "repo": "firmware-nonfree", - "rev": "7f29411baead874b859eda53efdc2472345ea454", + "rev": "2b465a10b04555b7f45b3acb85959c594922a3ce", "type": "github" }, "original": { @@ -60,57 +59,39 @@ "type": "github" } }, - "rpi-firmware-stable-src": { + "rpi-firmware-src": { "flake": false, "locked": { - "lastModified": 1673003776, - "narHash": "sha256-tdaH+zZwmILNFBge2gMqtzj/1Hydj9cxhPvhw+7jTrU=", + "lastModified": 1686136390, + "narHash": "sha256-Uq1yIp8zgexz2hwgAxEtmo9paytel4VPof5VMys01UM=", "owner": "raspberrypi", "repo": "firmware", - "rev": "78852e166b4cf3ebb31d051e996d54792f0994b0", + "rev": "13fbbc4f5ea698353486915986de8b48f18018f6", "type": "github" }, "original": { "owner": "raspberrypi", - "ref": "stable", "repo": "firmware", "type": "github" } }, - "rpi-linux-5_15-src": { + "rpi-linux-6_1-src": { "flake": false, "locked": { - "lastModified": 1675874870, - "narHash": "sha256-oy+VgoB4IdFZjGwkx88dDSpwWZj2D5t3PyXPIwDsY1Q=", + "lastModified": 1686133523, + "narHash": "sha256-r5L3hqk0wlefqkgO8jH4mupeUkbx9cSjHskLOxQQdZw=", "owner": "raspberrypi", "repo": "linux", - "rev": "14b35093ca68bf2c81bbc90aace5007142b40b40", + "rev": "bb63dc31e48948bc2649357758c7a152210109c4", "type": "github" }, "original": { "owner": "raspberrypi", - "ref": "rpi-5.15.y", + "ref": "rpi-6.1.y", "repo": "linux", "type": "github" } }, - "rpi-linux-5_15_87-src": { - "flake": false, - "locked": { - "lastModified": 1673628667, - "narHash": "sha256-hNLVfhalmRhhRfvu2mR/qDmmGl//Ic1eqR7N1HFj2CY=", - "owner": "raspberrypi", - "repo": "linux", - "rev": "da4c8e0ffe7a868b989211045657d600be3046a1", - "type": "github" - }, - "original": { - "owner": "raspberrypi", - "repo": "linux", - "rev": "da4c8e0ffe7a868b989211045657d600be3046a1", - "type": "github" - } - }, "u-boot-src": { "flake": false, "locked": { diff --git a/flake.nix b/flake.nix index c91be2c..5aad7fe 100644 --- a/flake.nix +++ b/flake.nix @@ -6,13 +6,13 @@ flake = false; url = "https://ftp.denx.de/pub/u-boot/u-boot-2023.01.tar.bz2"; }; - rpi-linux-5_15-src = { + rpi-linux-6_1-src = { flake = false; - url = "github:raspberrypi/linux/rpi-5.15.y"; + url = "github:raspberrypi/linux/rpi-6.1.y"; }; - rpi-firmware-stable-src = { + rpi-firmware-src = { flake = false; - url = "github:raspberrypi/firmware/stable"; + url = "github:raspberrypi/firmware"; }; rpi-firmware-nonfree-src = { flake = false; @@ -24,7 +24,7 @@ }; libcamera-apps-src = { flake = false; - url = "github:raspberrypi/libcamera-apps/v1.1.1"; + url = "github:raspberrypi/libcamera-apps/v1.1.2"; }; }; diff --git a/overlay/default.nix b/overlay/default.nix index a72eae3..8a7d1f3 100644 --- a/overlay/default.nix +++ b/overlay/default.nix @@ -1,9 +1,14 @@ -{ u-boot-src, rpi-linux-5_15-src, rpi-firmware-stable-src -, rpi-firmware-nonfree-src, rpi-bluez-firmware-src, libcamera-apps-src }: +{ u-boot-src +, rpi-linux-6_1-src +, rpi-firmware-src +, rpi-firmware-nonfree-src +, rpi-bluez-firmware-src +, libcamera-apps-src +}: final: prev: let # The version to stick at `pkgs.rpi-kernels.latest' - latest = "v5_15_92"; + latest = "v6_1_32"; # Helpers for building the `pkgs.rpi-kernels' map. rpi-kernel = { kernel, version, fw, wireless-fw, argsOverride ? null }: @@ -18,7 +23,8 @@ let new-fw = prev.raspberrypifw.overrideAttrs (oldfw: { src = fw; }); new-wireless-fw = final.callPackage wireless-fw { }; version-slug = builtins.replaceStrings [ "." ] [ "_" ] version; - in { + in + { "v${version-slug}" = { kernel = new-kernel; firmware = new-fw; @@ -26,7 +32,8 @@ let }; }; rpi-kernels = builtins.foldl' (b: a: b // rpi-kernel a) { }; -in { +in +{ # disable firmware compression so that brcm firmware can be found at # the path expected by raspberry pi firmware/device tree @@ -69,9 +76,9 @@ in { # # For example: `pkgs.rpi-kernels.v5_15_87.kernel' rpi-kernels = rpi-kernels [{ - version = "5.15.92"; - kernel = rpi-linux-5_15-src; - fw = rpi-firmware-stable-src; + version = "6.1.32"; + kernel = rpi-linux-6_1-src; + fw = rpi-firmware-src; wireless-fw = import ./raspberrypi-wireless-firmware.nix { bluez-firmware = rpi-bluez-firmware-src; firmware-nonfree = rpi-firmware-nonfree-src; From 7c6fa52715ce3042f2c76a649a8d6e52d0a8b646 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 12 Jun 2023 09:53:24 -0400 Subject: [PATCH 05/97] set linux and firmware to latest release tag disable KUNIT in kernel config --- flake.lock | 15 ++-- flake.nix | 4 +- overlay/default.nix | 13 +-- overlay/libcamera-apps.nix | 2 +- rpi/default.nix | 159 +++++++++++++++++++------------------ 5 files changed, 98 insertions(+), 95 deletions(-) diff --git a/flake.lock b/flake.lock index 06af588..406d9d4 100644 --- a/flake.lock +++ b/flake.lock @@ -62,15 +62,16 @@ "rpi-firmware-src": { "flake": false, "locked": { - "lastModified": 1686136390, - "narHash": "sha256-Uq1yIp8zgexz2hwgAxEtmo9paytel4VPof5VMys01UM=", + "lastModified": 1680694337, + "narHash": "sha256-UtUd1MbsrDFxd/1C3eOAMDKPZMx+kSMFYOJP+Kc6IU8=", "owner": "raspberrypi", "repo": "firmware", - "rev": "13fbbc4f5ea698353486915986de8b48f18018f6", + "rev": "055e044d5359ded1aacc5a17a8e35365373d0b8b", "type": "github" }, "original": { "owner": "raspberrypi", + "ref": "stable", "repo": "firmware", "type": "github" } @@ -78,16 +79,16 @@ "rpi-linux-6_1-src": { "flake": false, "locked": { - "lastModified": 1686133523, - "narHash": "sha256-r5L3hqk0wlefqkgO8jH4mupeUkbx9cSjHskLOxQQdZw=", + "lastModified": 1680464256, + "narHash": "sha256-ILwecHZ1BN6GhZAUB6/UwiN/rZ8gHndKON6DUhidtxI=", "owner": "raspberrypi", "repo": "linux", - "rev": "bb63dc31e48948bc2649357758c7a152210109c4", + "rev": "0afb5e98488aed7017b9bf321b575d0177feb7ed", "type": "github" }, "original": { "owner": "raspberrypi", - "ref": "rpi-6.1.y", + "ref": "1.20230405", "repo": "linux", "type": "github" } diff --git a/flake.nix b/flake.nix index 5aad7fe..51e26dc 100644 --- a/flake.nix +++ b/flake.nix @@ -8,11 +8,11 @@ }; rpi-linux-6_1-src = { flake = false; - url = "github:raspberrypi/linux/rpi-6.1.y"; + url = "github:raspberrypi/linux/1.20230405"; }; rpi-firmware-src = { flake = false; - url = "github:raspberrypi/firmware"; + url = "github:raspberrypi/firmware/1.20230405"; }; rpi-firmware-nonfree-src = { flake = false; diff --git a/overlay/default.nix b/overlay/default.nix index 8a7d1f3..ff62828 100644 --- a/overlay/default.nix +++ b/overlay/default.nix @@ -8,7 +8,7 @@ final: prev: let # The version to stick at `pkgs.rpi-kernels.latest' - latest = "v6_1_32"; + latest = "v6_1_21"; # Helpers for building the `pkgs.rpi-kernels' map. rpi-kernel = { kernel, version, fw, wireless-fw, argsOverride ? null }: @@ -35,10 +35,6 @@ let in { - # disable firmware compression so that brcm firmware can be found at - # the path expected by raspberry pi firmware/device tree - compressFirmwareXz = x: x; - # A recent known working version of libcamera-apps libcamera-apps = final.callPackage ./libcamera-apps.nix { inherit libcamera-apps-src; }; @@ -76,13 +72,18 @@ in # # For example: `pkgs.rpi-kernels.v5_15_87.kernel' rpi-kernels = rpi-kernels [{ - version = "6.1.32"; + version = "6.1.21"; kernel = rpi-linux-6_1-src; fw = rpi-firmware-src; wireless-fw = import ./raspberrypi-wireless-firmware.nix { bluez-firmware = rpi-bluez-firmware-src; firmware-nonfree = rpi-firmware-nonfree-src; }; + argsOverride = { + structuredExtraConfig = with prev.lib.kernel; { + KUNIT = no; + }; + }; }] // { latest = final.rpi-kernels."${latest}"; }; diff --git a/overlay/libcamera-apps.nix b/overlay/libcamera-apps.nix index 139a641..04e29b8 100644 --- a/overlay/libcamera-apps.nix +++ b/overlay/libcamera-apps.nix @@ -3,7 +3,7 @@ stdenv.mkDerivation rec { pname = "libcamera-apps"; - version = "v1.1.0"; + version = "v1.1.2"; src = libcamera-apps-src; diff --git a/rpi/default.nix b/rpi/default.nix index 671369d..98a82c5 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -8,91 +8,92 @@ "raspberry-pi-firmware-migrate" = { description = "update the firmware partition"; wantedBy = [ "multi-user.target" ]; - serviceConfig = let firmware-path = "/boot/firmware"; - in { - Type = "oneshot"; - MountImages = - "/dev/disk/by-label/${config.sdImage.firmwarePartitionName}:${firmware-path}"; - StateDirectory = "raspberrypi-firmware"; - ExecStart = pkgs.writeShellScript "migrate-rpi-firmware" '' - shopt -s nullglob + serviceConfig = + let firmware-path = "/boot/firmware"; + in { + Type = "oneshot"; + MountImages = + "/dev/disk/by-label/${config.sdImage.firmwarePartitionName}:${firmware-path}"; + StateDirectory = "raspberrypi-firmware"; + ExecStart = pkgs.writeShellScript "migrate-rpi-firmware" '' + shopt -s nullglob - TARGET_FIRMWARE_DIR="${firmware-path}" - TARGET_OVERLAYS_DIR="$TARGET_FIRMWARE_DIR/overlays" - TMPFILE="$TARGET_FIRMWARE_DIR/tmp" - UBOOT="${pkgs.uboot_rpi_arm64}/u-boot.bin" - SRC_FIRMWARE_DIR="${pkgs.raspberrypifw}/share/raspberrypi/boot" - STARTFILES=("$SRC_FIRMWARE_DIR"/start*.elf) - DTBS=("$SRC_FIRMWARE_DIR"/*.dtb) - BOOTCODE="$SRC_FIRMWARE_DIR/bootcode.bin" - FIXUPS=("$SRC_FIRMWARE_DIR"/fixup*.dat) - SRC_OVERLAYS_DIR="$SRC_FIRMWARE_DIR/overlays" - SRC_OVERLAYS=("$SRC_OVERLAYS_DIR"/*) - CONFIG="${config.hardware.raspberry-pi.config-output}" + TARGET_FIRMWARE_DIR="${firmware-path}" + TARGET_OVERLAYS_DIR="$TARGET_FIRMWARE_DIR/overlays" + TMPFILE="$TARGET_FIRMWARE_DIR/tmp" + UBOOT="${pkgs.uboot_rpi_arm64}/u-boot.bin" + SRC_FIRMWARE_DIR="${pkgs.raspberrypifw}/share/raspberrypi/boot" + STARTFILES=("$SRC_FIRMWARE_DIR"/start*.elf) + DTBS=("$SRC_FIRMWARE_DIR"/*.dtb) + BOOTCODE="$SRC_FIRMWARE_DIR/bootcode.bin" + FIXUPS=("$SRC_FIRMWARE_DIR"/fixup*.dat) + SRC_OVERLAYS_DIR="$SRC_FIRMWARE_DIR/overlays" + SRC_OVERLAYS=("$SRC_OVERLAYS_DIR"/*) + CONFIG="${config.hardware.raspberry-pi.config-output}" - migrate_uboot() { - echo "migrating uboot" - touch "$STATE_DIRECTORY/uboot-migration-in-progress" - cp "$UBOOT" "$TMPFILE" - mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/u-boot-rpi-arm64.bin" - echo "${ + migrate_uboot() { + echo "migrating uboot" + touch "$STATE_DIRECTORY/uboot-migration-in-progress" + cp "$UBOOT" "$TMPFILE" + mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/u-boot-rpi-arm64.bin" + echo "${ + builtins.toString pkgs.uboot_rpi_arm64 + }" > "$STATE_DIRECTORY/uboot-version" + rm "$STATE_DIRECTORY/uboot-migration-in-progress" + } + + migrate_config() { + echo "migrating config.txt" + touch "$STATE_DIRECTORY/config-migration-in-progress" + cp "$CONFIG" "$TMPFILE" + mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/config.txt" + echo "${config.hardware.raspberry-pi.config-output}" > "$STATE_DIRECTORY/config-version" + rm "$STATE_DIRECTORY/config-migration-in-progress" + } + + migrate_firmware() { + echo "migrating raspberrypi firmware" + touch "$STATE_DIRECTORY/firmware-migration-in-progress" + for SRC in "''${STARTFILES[@]}" "''${DTBS[@]}" "$BOOTCODE" "''${FIXUPS[@]}" + do + cp "$SRC" "$TMPFILE" + mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/$(basename "$SRC")" + done + + if [[ ! -d "$TARGET_OVERLAYS_DIR" ]]; then + mkdir "$TARGET_OVERLAYS_DIR" + fi + + for SRC in "''${SRC_OVERLAYS[@]}" + do + cp "$SRC" "$TMPFILE" + mv -T "$TMPFILE" "$TARGET_OVERLAYS_DIR/$(basename "$SRC")" + done + echo "${ + builtins.toString pkgs.raspberrypifw + }" > "$STATE_DIRECTORY/firmware-version" + rm "$STATE_DIRECTORY/firmware-migration-in-progress" + } + + if [[ -f "$STATE_DIRECTORY/uboot-migration-in-progress" || ! -f "$STATE_DIRECTORY/uboot-version" || $(< "$STATE_DIRECTORY/uboot-version") != ${ builtins.toString pkgs.uboot_rpi_arm64 - }" > "$STATE_DIRECTORY/uboot-version" - rm "$STATE_DIRECTORY/uboot-migration-in-progress" - } - - migrate_config() { - echo "migrating config.txt" - touch "$STATE_DIRECTORY/config-migration-in-progress" - cp "$CONFIG" "$TMPFILE" - mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/config.txt" - echo "${config.hardware.raspberry-pi.config-output}" > "$STATE_DIRECTORY/config-version" - rm "$STATE_DIRECTORY/config-migration-in-progress" - } - - migrate_firmware() { - echo "migrating raspberrypi firmware" - touch "$STATE_DIRECTORY/firmware-migration-in-progress" - for SRC in "''${STARTFILES[@]}" "''${DTBS[@]}" "$BOOTCODE" "''${FIXUPS[@]}" - do - cp "$SRC" "$TMPFILE" - mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/$(basename "$SRC")" - done - - if [[ ! -d "$TARGET_OVERLAYS_DIR" ]]; then - mkdir "$TARGET_OVERLAYS_DIR" + } ]]; then + migrate_uboot fi - for SRC in "''${SRC_OVERLAYS[@]}" - do - cp "$SRC" "$TMPFILE" - mv -T "$TMPFILE" "$TARGET_OVERLAYS_DIR/$(basename "$SRC")" - done - echo "${ + if [[ -f "$STATE_DIRECTORY/config-migration-in-progress" || ! -f "$STATE_DIRECTORY/config-version" || $(< "$STATE_DIRECTORY/config-version") != ${ + builtins.toString config.hardware.raspberry-pi.config-output + } ]]; then + migrate_config + fi + + if [[ -f "$STATE_DIRECTORY/firmware-migration-in-progress" || ! -f "$STATE_DIRECTORY/firmware-version" || $(< "$STATE_DIRECTORY/firmware-version") != ${ builtins.toString pkgs.raspberrypifw - }" > "$STATE_DIRECTORY/firmware-version" - rm "$STATE_DIRECTORY/firmware-migration-in-progress" - } - - if [[ -f "$STATE_DIRECTORY/uboot-migration-in-progress" || ! -f "$STATE_DIRECTORY/uboot-version" || $(< "$STATE_DIRECTORY/uboot-version") != ${ - builtins.toString pkgs.uboot_rpi_arm64 - } ]]; then - migrate_uboot - fi - - if [[ -f "$STATE_DIRECTORY/config-migration-in-progress" || ! -f "$STATE_DIRECTORY/config-version" || $(< "$STATE_DIRECTORY/config-version") != ${ - builtins.toString config.hardware.raspberry-pi.config-output - } ]]; then - migrate_config - fi - - if [[ -f "$STATE_DIRECTORY/firmware-migration-in-progress" || ! -f "$STATE_DIRECTORY/firmware-version" || $(< "$STATE_DIRECTORY/firmware-version") != ${ - builtins.toString pkgs.raspberrypifw - } ]]; then - migrate_firmware - fi - ''; - }; + } ]]; then + migrate_firmware + fi + ''; + }; }; }; From 92e2a3b15f4eec6ef18eb7e0b2addc98f71757b0 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 12 Jun 2023 10:44:29 -0400 Subject: [PATCH 06/97] add docs for KUNIT setting --- overlay/default.nix | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/overlay/default.nix b/overlay/default.nix index ff62828..a686855 100644 --- a/overlay/default.nix +++ b/overlay/default.nix @@ -81,6 +81,23 @@ in }; argsOverride = { structuredExtraConfig = with prev.lib.kernel; { + # The perl script to generate kernel options sets unspecified + # parameters to `m` if possible [1]. This results in the + # unspecified config option KUNIT [2] getting set to `m` which + # causes DRM_VC4_KUNIT_TEST [3] to get set to `y`. + # + # This vc4 unit test fails on boot due to a null pointer + # exception with the existing config. I'm not sure why, but in + # any case, the DRM_VC4_KUNIT_TEST config option itself states + # that it is only useful for kernel developers working on the + # vc4 driver. So, I feel no need to deviate from the standard + # rpi kernel and attempt to successfully enable this test and + # other unit tests because the nixos perl script has this + # sloppy "default to m" behavior. So, I set KUNIT to `n`. + # + # [1] https://github.com/NixOS/nixpkgs/blob/85bcb95aa83be667e562e781e9d186c57a07d757/pkgs/os-specific/linux/kernel/generate-config.pl#L1-L10 + # [2] https://github.com/raspberrypi/linux/blob/1.20230405/lib/kunit/Kconfig#L5-L14 + # [3] https://github.com/raspberrypi/linux/blob/bb63dc31e48948bc2649357758c7a152210109c4/drivers/gpu/drm/vc4/Kconfig#L38-L52 KUNIT = no; }; }; From 4e4ed46f15803502fb980e0672fabad3779d6394 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Fri, 16 Jun 2023 09:35:17 -0400 Subject: [PATCH 07/97] removed this too eagerly compressing the firmware still breaks my zero-2-w --- overlay/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/overlay/default.nix b/overlay/default.nix index a686855..ae44d43 100644 --- a/overlay/default.nix +++ b/overlay/default.nix @@ -34,6 +34,9 @@ let rpi-kernels = builtins.foldl' (b: a: b // rpi-kernel a) { }; in { + # disable firmware compression so that brcm firmware can be found at + # the path expected by raspberry pi firmware/device tree + compressFirmwareXz = x: x; # A recent known working version of libcamera-apps libcamera-apps = From 5f94c31db1d2c734523a98ae2b490891a6dc3ac7 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Fri, 16 Jun 2023 09:36:35 -0400 Subject: [PATCH 08/97] enable uart console for kernel serial0 is symlinked to ttyAMA0 on rpi's distro, but I don't know exactly what is supposed to create that, and it isn't happening here. Something to look into, but this works for now. --- sd-image/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sd-image/default.nix b/sd-image/default.nix index 2804d06..5ee8e7a 100644 --- a/sd-image/default.nix +++ b/sd-image/default.nix @@ -10,7 +10,7 @@ boot.consoleLogLevel = lib.mkDefault 7; # https://github.com/raspberrypi/firmware/issues/1539#issuecomment-784498108 - boot.kernelParams = [ "console=serial0,115200n8" "console=tty1" ]; + boot.kernelParams = [ "console=ttyAMA0,115200n8" "console=tty1" ]; sdImage = { populateFirmwareCommands = '' From 434b3367ac69ec42c088c6253b58ed4cb96aedce Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 19 Jun 2023 12:10:20 -0400 Subject: [PATCH 09/97] bump u-boot --- flake.lock | 8 ++++---- flake.nix | 2 +- overlay/default.nix | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index 406d9d4..cb91b20 100644 --- a/flake.lock +++ b/flake.lock @@ -71,7 +71,7 @@ }, "original": { "owner": "raspberrypi", - "ref": "stable", + "ref": "1.20230405", "repo": "firmware", "type": "github" } @@ -96,13 +96,13 @@ "u-boot-src": { "flake": false, "locked": { - "narHash": "sha256-30fe8klLHRsEtEQ1VpYh4S+AflG5yCQYWlGmpWyFL8w=", + "narHash": "sha256-k4CgiG6rOdgex+YxMRXqyJF7NFqAN9R+UKc3Y/+7jV0=", "type": "tarball", - "url": "https://ftp.denx.de/pub/u-boot/u-boot-2023.01.tar.bz2" + "url": "https://ftp.denx.de/pub/u-boot/u-boot-2023.04.tar.bz2" }, "original": { "type": "tarball", - "url": "https://ftp.denx.de/pub/u-boot/u-boot-2023.01.tar.bz2" + "url": "https://ftp.denx.de/pub/u-boot/u-boot-2023.04.tar.bz2" } } }, diff --git a/flake.nix b/flake.nix index 51e26dc..e5a3c84 100644 --- a/flake.nix +++ b/flake.nix @@ -4,7 +4,7 @@ inputs = { u-boot-src = { flake = false; - url = "https://ftp.denx.de/pub/u-boot/u-boot-2023.01.tar.bz2"; + url = "https://ftp.denx.de/pub/u-boot/u-boot-2023.04.tar.bz2"; }; rpi-linux-6_1-src = { flake = false; diff --git a/overlay/default.nix b/overlay/default.nix index ae44d43..e44ca50 100644 --- a/overlay/default.nix +++ b/overlay/default.nix @@ -47,7 +47,7 @@ in defconfig = "rpi_arm64_defconfig"; extraMeta.platforms = [ "aarch64-linux" ]; filesToInstall = [ "u-boot.bin" ]; - version = "2023.01"; + version = "2023.04"; src = u-boot-src; # In raspberry pi sbcs the firmware manipulates the device tree in # a variety of ways before handing it off to the linux kernel. [1] From 23faa56e6c06d8af413cfc6e45c4c05e484131d1 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 19 Jun 2023 14:11:11 -0400 Subject: [PATCH 10/97] Revert "bump u-boot" This reverts commit 434b3367ac69ec42c088c6253b58ed4cb96aedce. --- flake.lock | 8 ++++---- flake.nix | 2 +- overlay/default.nix | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index cb91b20..406d9d4 100644 --- a/flake.lock +++ b/flake.lock @@ -71,7 +71,7 @@ }, "original": { "owner": "raspberrypi", - "ref": "1.20230405", + "ref": "stable", "repo": "firmware", "type": "github" } @@ -96,13 +96,13 @@ "u-boot-src": { "flake": false, "locked": { - "narHash": "sha256-k4CgiG6rOdgex+YxMRXqyJF7NFqAN9R+UKc3Y/+7jV0=", + "narHash": "sha256-30fe8klLHRsEtEQ1VpYh4S+AflG5yCQYWlGmpWyFL8w=", "type": "tarball", - "url": "https://ftp.denx.de/pub/u-boot/u-boot-2023.04.tar.bz2" + "url": "https://ftp.denx.de/pub/u-boot/u-boot-2023.01.tar.bz2" }, "original": { "type": "tarball", - "url": "https://ftp.denx.de/pub/u-boot/u-boot-2023.04.tar.bz2" + "url": "https://ftp.denx.de/pub/u-boot/u-boot-2023.01.tar.bz2" } } }, diff --git a/flake.nix b/flake.nix index e5a3c84..51e26dc 100644 --- a/flake.nix +++ b/flake.nix @@ -4,7 +4,7 @@ inputs = { u-boot-src = { flake = false; - url = "https://ftp.denx.de/pub/u-boot/u-boot-2023.04.tar.bz2"; + url = "https://ftp.denx.de/pub/u-boot/u-boot-2023.01.tar.bz2"; }; rpi-linux-6_1-src = { flake = false; diff --git a/overlay/default.nix b/overlay/default.nix index e44ca50..ae44d43 100644 --- a/overlay/default.nix +++ b/overlay/default.nix @@ -47,7 +47,7 @@ in defconfig = "rpi_arm64_defconfig"; extraMeta.platforms = [ "aarch64-linux" ]; filesToInstall = [ "u-boot.bin" ]; - version = "2023.04"; + version = "2023.01"; src = u-boot-src; # In raspberry pi sbcs the firmware manipulates the device tree in # a variety of ways before handing it off to the linux kernel. [1] From 6e0da6783012ec425421bfdc8c15a29690a196a8 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Fri, 23 Jun 2023 20:00:03 -0400 Subject: [PATCH 11/97] add option to turn off migration service --- rpi/default.nix | 363 +++++++++++++++++++++++++----------------------- 1 file changed, 189 insertions(+), 174 deletions(-) diff --git a/rpi/default.nix b/rpi/default.nix index 98a82c5..32957f1 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -4,188 +4,203 @@ { imports = [ ../sd-image ./config.nix ./i2c.nix ]; - systemd.services = { - "raspberry-pi-firmware-migrate" = { - description = "update the firmware partition"; - wantedBy = [ "multi-user.target" ]; - serviceConfig = - let firmware-path = "/boot/firmware"; - in { - Type = "oneshot"; - MountImages = - "/dev/disk/by-label/${config.sdImage.firmwarePartitionName}:${firmware-path}"; - StateDirectory = "raspberrypi-firmware"; - ExecStart = pkgs.writeShellScript "migrate-rpi-firmware" '' - shopt -s nullglob - - TARGET_FIRMWARE_DIR="${firmware-path}" - TARGET_OVERLAYS_DIR="$TARGET_FIRMWARE_DIR/overlays" - TMPFILE="$TARGET_FIRMWARE_DIR/tmp" - UBOOT="${pkgs.uboot_rpi_arm64}/u-boot.bin" - SRC_FIRMWARE_DIR="${pkgs.raspberrypifw}/share/raspberrypi/boot" - STARTFILES=("$SRC_FIRMWARE_DIR"/start*.elf) - DTBS=("$SRC_FIRMWARE_DIR"/*.dtb) - BOOTCODE="$SRC_FIRMWARE_DIR/bootcode.bin" - FIXUPS=("$SRC_FIRMWARE_DIR"/fixup*.dat) - SRC_OVERLAYS_DIR="$SRC_FIRMWARE_DIR/overlays" - SRC_OVERLAYS=("$SRC_OVERLAYS_DIR"/*) - CONFIG="${config.hardware.raspberry-pi.config-output}" - - migrate_uboot() { - echo "migrating uboot" - touch "$STATE_DIRECTORY/uboot-migration-in-progress" - cp "$UBOOT" "$TMPFILE" - mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/u-boot-rpi-arm64.bin" - echo "${ - builtins.toString pkgs.uboot_rpi_arm64 - }" > "$STATE_DIRECTORY/uboot-version" - rm "$STATE_DIRECTORY/uboot-migration-in-progress" - } - - migrate_config() { - echo "migrating config.txt" - touch "$STATE_DIRECTORY/config-migration-in-progress" - cp "$CONFIG" "$TMPFILE" - mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/config.txt" - echo "${config.hardware.raspberry-pi.config-output}" > "$STATE_DIRECTORY/config-version" - rm "$STATE_DIRECTORY/config-migration-in-progress" - } - - migrate_firmware() { - echo "migrating raspberrypi firmware" - touch "$STATE_DIRECTORY/firmware-migration-in-progress" - for SRC in "''${STARTFILES[@]}" "''${DTBS[@]}" "$BOOTCODE" "''${FIXUPS[@]}" - do - cp "$SRC" "$TMPFILE" - mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/$(basename "$SRC")" - done - - if [[ ! -d "$TARGET_OVERLAYS_DIR" ]]; then - mkdir "$TARGET_OVERLAYS_DIR" - fi - - for SRC in "''${SRC_OVERLAYS[@]}" - do - cp "$SRC" "$TMPFILE" - mv -T "$TMPFILE" "$TARGET_OVERLAYS_DIR/$(basename "$SRC")" - done - echo "${ - builtins.toString pkgs.raspberrypifw - }" > "$STATE_DIRECTORY/firmware-version" - rm "$STATE_DIRECTORY/firmware-migration-in-progress" - } - - if [[ -f "$STATE_DIRECTORY/uboot-migration-in-progress" || ! -f "$STATE_DIRECTORY/uboot-version" || $(< "$STATE_DIRECTORY/uboot-version") != ${ - builtins.toString pkgs.uboot_rpi_arm64 - } ]]; then - migrate_uboot - fi - - if [[ -f "$STATE_DIRECTORY/config-migration-in-progress" || ! -f "$STATE_DIRECTORY/config-version" || $(< "$STATE_DIRECTORY/config-version") != ${ - builtins.toString config.hardware.raspberry-pi.config-output - } ]]; then - migrate_config - fi - - if [[ -f "$STATE_DIRECTORY/firmware-migration-in-progress" || ! -f "$STATE_DIRECTORY/firmware-version" || $(< "$STATE_DIRECTORY/firmware-version") != ${ - builtins.toString pkgs.raspberrypifw - } ]]; then - migrate_firmware - fi - ''; - }; - }; - }; - - # Default config.txt on Raspberry Pi OS: - # https://github.com/RPi-Distro/pi-gen/blob/master/stage1/00-boot-files/files/config.txt - hardware.raspberry-pi.config = { - cm4 = { - options = { - otg_mode = { - enable = lib.mkDefault true; - value = lib.mkDefault true; - }; - }; - }; - pi4 = { - options = { - arm_boost = { - enable = lib.mkDefault true; - value = lib.mkDefault true; - }; - }; - }; - all = { - options = { - # The firmware will start our u-boot binary rather than a - # linux kernel. - kernel = { - enable = true; - value = "u-boot-rpi-arm64.bin"; - }; - arm_64bit = { - enable = true; - value = true; - }; - enable_uart = { - enable = true; - value = true; - }; - avoid_warnings = { - enable = lib.mkDefault true; - value = lib.mkDefault true; - }; - camera_auto_detect = { - enable = lib.mkDefault true; - value = lib.mkDefault true; - }; - display_auto_detect = { - enable = lib.mkDefault true; - value = lib.mkDefault true; - }; - disable_overscan = { - enable = lib.mkDefault true; - value = lib.mkDefault true; - }; - }; - dt-overlays = { - vc4-kms-v3d = { - enable = lib.mkDefault true; - params = { }; + options = with lib; { + raspberry-pi-nix = { + firmware-migration-service = { + enable = mkOption { + default = true; + type = types.bool; }; }; }; }; - nixpkgs = { overlays = [ overlay ]; }; - boot = { - initrd.availableKernelModules = [ - "usbhid" - "usb_storage" - "vc4" - "pcie_brcmstb" # required for the pcie bus to work - "reset-raspberrypi" # required for vl805 firmware to load - ]; - kernelPackages = pkgs.linuxPackagesFor (pkgs.rpi-kernels.latest.kernel); + config = { + systemd.services = { + "raspberry-pi-firmware-migrate" = + lib.mkIf config.raspberry-pi-nix.firmware-migration-service.enable { + description = "update the firmware partition"; + wantedBy = [ "multi-user.target" ]; + serviceConfig = + let firmware-path = "/boot/firmware"; + in { + Type = "oneshot"; + MountImages = + "/dev/disk/by-label/${config.sdImage.firmwarePartitionName}:${firmware-path}"; + StateDirectory = "raspberrypi-firmware"; + ExecStart = pkgs.writeShellScript "migrate-rpi-firmware" '' + shopt -s nullglob - loader = { - grub.enable = lib.mkDefault false; - generic-extlinux-compatible = { - enable = lib.mkDefault true; - # We want to use the device tree provided by firmware, so don't - # add FDTDIR to the extlinux conf file. - useGenerationDeviceTree = false; + TARGET_FIRMWARE_DIR="${firmware-path}" + TARGET_OVERLAYS_DIR="$TARGET_FIRMWARE_DIR/overlays" + TMPFILE="$TARGET_FIRMWARE_DIR/tmp" + UBOOT="${pkgs.uboot_rpi_arm64}/u-boot.bin" + SRC_FIRMWARE_DIR="${pkgs.raspberrypifw}/share/raspberrypi/boot" + STARTFILES=("$SRC_FIRMWARE_DIR"/start*.elf) + DTBS=("$SRC_FIRMWARE_DIR"/*.dtb) + BOOTCODE="$SRC_FIRMWARE_DIR/bootcode.bin" + FIXUPS=("$SRC_FIRMWARE_DIR"/fixup*.dat) + SRC_OVERLAYS_DIR="$SRC_FIRMWARE_DIR/overlays" + SRC_OVERLAYS=("$SRC_OVERLAYS_DIR"/*) + CONFIG="${config.hardware.raspberry-pi.config-output}" + + migrate_uboot() { + echo "migrating uboot" + touch "$STATE_DIRECTORY/uboot-migration-in-progress" + cp "$UBOOT" "$TMPFILE" + mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/u-boot-rpi-arm64.bin" + echo "${ + builtins.toString pkgs.uboot_rpi_arm64 + }" > "$STATE_DIRECTORY/uboot-version" + rm "$STATE_DIRECTORY/uboot-migration-in-progress" + } + + migrate_config() { + echo "migrating config.txt" + touch "$STATE_DIRECTORY/config-migration-in-progress" + cp "$CONFIG" "$TMPFILE" + mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/config.txt" + echo "${config.hardware.raspberry-pi.config-output}" > "$STATE_DIRECTORY/config-version" + rm "$STATE_DIRECTORY/config-migration-in-progress" + } + + migrate_firmware() { + echo "migrating raspberrypi firmware" + touch "$STATE_DIRECTORY/firmware-migration-in-progress" + for SRC in "''${STARTFILES[@]}" "''${DTBS[@]}" "$BOOTCODE" "''${FIXUPS[@]}" + do + cp "$SRC" "$TMPFILE" + mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/$(basename "$SRC")" + done + + if [[ ! -d "$TARGET_OVERLAYS_DIR" ]]; then + mkdir "$TARGET_OVERLAYS_DIR" + fi + + for SRC in "''${SRC_OVERLAYS[@]}" + do + cp "$SRC" "$TMPFILE" + mv -T "$TMPFILE" "$TARGET_OVERLAYS_DIR/$(basename "$SRC")" + done + echo "${ + builtins.toString pkgs.raspberrypifw + }" > "$STATE_DIRECTORY/firmware-version" + rm "$STATE_DIRECTORY/firmware-migration-in-progress" + } + + if [[ -f "$STATE_DIRECTORY/uboot-migration-in-progress" || ! -f "$STATE_DIRECTORY/uboot-version" || $(< "$STATE_DIRECTORY/uboot-version") != ${ + builtins.toString pkgs.uboot_rpi_arm64 + } ]]; then + migrate_uboot + fi + + if [[ -f "$STATE_DIRECTORY/config-migration-in-progress" || ! -f "$STATE_DIRECTORY/config-version" || $(< "$STATE_DIRECTORY/config-version") != ${ + builtins.toString config.hardware.raspberry-pi.config-output + } ]]; then + migrate_config + fi + + if [[ -f "$STATE_DIRECTORY/firmware-migration-in-progress" || ! -f "$STATE_DIRECTORY/firmware-version" || $(< "$STATE_DIRECTORY/firmware-version") != ${ + builtins.toString pkgs.raspberrypifw + } ]]; then + migrate_firmware + fi + ''; + }; + }; + }; + + # Default config.txt on Raspberry Pi OS: + # https://github.com/RPi-Distro/pi-gen/blob/master/stage1/00-boot-files/files/config.txt + hardware.raspberry-pi.config = { + cm4 = { + options = { + otg_mode = { + enable = lib.mkDefault true; + value = lib.mkDefault true; + }; + }; + }; + pi4 = { + options = { + arm_boost = { + enable = lib.mkDefault true; + value = lib.mkDefault true; + }; + }; + }; + all = { + options = { + # The firmware will start our u-boot binary rather than a + # linux kernel. + kernel = { + enable = true; + value = "u-boot-rpi-arm64.bin"; + }; + arm_64bit = { + enable = true; + value = true; + }; + enable_uart = { + enable = true; + value = true; + }; + avoid_warnings = { + enable = lib.mkDefault true; + value = lib.mkDefault true; + }; + camera_auto_detect = { + enable = lib.mkDefault true; + value = lib.mkDefault true; + }; + display_auto_detect = { + enable = lib.mkDefault true; + value = lib.mkDefault true; + }; + disable_overscan = { + enable = lib.mkDefault true; + value = lib.mkDefault true; + }; + }; + dt-overlays = { + vc4-kms-v3d = { + enable = lib.mkDefault true; + params = { }; + }; + }; }; }; - }; - hardware.enableRedistributableFirmware = true; - services = { - udev.extraRules = '' - SUBSYSTEM=="dma_heap", GROUP="video", MODE="0660" - KERNEL=="gpiomem", GROUP="gpio", MODE="0660" - KERNEL=="gpiochip*", GROUP="gpio", MODE="0660" - ''; + nixpkgs = { overlays = [ overlay ]; }; + boot = { + initrd.availableKernelModules = [ + "usbhid" + "usb_storage" + "vc4" + "pcie_brcmstb" # required for the pcie bus to work + "reset-raspberrypi" # required for vl805 firmware to load + ]; + kernelPackages = pkgs.linuxPackagesFor (pkgs.rpi-kernels.latest.kernel); + + loader = { + grub.enable = lib.mkDefault false; + generic-extlinux-compatible = { + enable = lib.mkDefault true; + # We want to use the device tree provided by firmware, so don't + # add FDTDIR to the extlinux conf file. + useGenerationDeviceTree = false; + }; + }; + }; + hardware.enableRedistributableFirmware = true; + + services = { + udev.extraRules = '' + SUBSYSTEM=="dma_heap", GROUP="video", MODE="0660" + KERNEL=="gpiomem", GROUP="gpio", MODE="0660" + KERNEL=="gpiochip*", GROUP="gpio", MODE="0660" + ''; + }; }; + } From 24f5b92db86a01f5bda2e117726f5a0e39b0ec97 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 12 Jun 2023 20:03:02 -0400 Subject: [PATCH 12/97] add hardware.raspberrypi.config-generated option outputs the generated config as text --- rpi/config.nix | 218 ++++++++++++++++++++++++++----------------------- 1 file changed, 118 insertions(+), 100 deletions(-) diff --git a/rpi/config.nix b/rpi/config.nix index 1226520..125cb13 100644 --- a/rpi/config.nix +++ b/rpi/config.nix @@ -1,126 +1,144 @@ { lib, config, pkgs, ... }: let cfg = config.hardware.raspberry-pi; - render-raspberrypi-config = let - render-options = opts: - lib.strings.concatStringsSep "\n" (render-dt-kvs opts); - render-dt-param = x: "dtparam=" + x; - render-dt-kv = k: v: - if isNull v.value then - k - else - let vstr = toString v.value; in "${k}=${vstr}"; - render-dt-kvs = x: - lib.attrsets.mapAttrsToList render-dt-kv - (lib.filterAttrs (k: v: v.enable) x); - render-dt-overlay = { overlay, args }: - "dtoverlay=" + overlay + "\n" - + lib.strings.concatMapStringsSep "\n" render-dt-param args + "\n" - + "dtoverlay="; - render-base-dt-params = params: - lib.strings.concatMapStringsSep "\n" render-dt-param - (render-dt-kvs params); - render-dt-overlays = overlays: - lib.strings.concatMapStringsSep "\n" render-dt-overlay - (lib.attrsets.mapAttrsToList (k: v: { - overlay = k; - args = render-dt-kvs v.params; - }) (lib.filterAttrs (k: v: v.enable) overlays)); - render-config-section = k: - { options, base-dt-params, dt-overlays }: - let - all-config = lib.concatStringsSep "\n" (lib.filter (x: x != "") [ - (render-options options) - (render-base-dt-params base-dt-params) - (render-dt-overlays dt-overlays) - ]); - in '' - [${k}] - ${all-config} - ''; - in conf: - lib.strings.concatStringsSep "\n" - (lib.attrsets.mapAttrsToList render-config-section conf); -in { + render-raspberrypi-config = + let + render-options = opts: + lib.strings.concatStringsSep "\n" (render-dt-kvs opts); + render-dt-param = x: "dtparam=" + x; + render-dt-kv = k: v: + if isNull v.value then + k + else + let vstr = toString v.value; in "${k}=${vstr}"; + render-dt-kvs = x: + lib.attrsets.mapAttrsToList render-dt-kv + (lib.filterAttrs (k: v: v.enable) x); + render-dt-overlay = { overlay, args }: + "dtoverlay=" + overlay + "\n" + + lib.strings.concatMapStringsSep "\n" render-dt-param args + "\n" + + "dtoverlay="; + render-base-dt-params = params: + lib.strings.concatMapStringsSep "\n" render-dt-param + (render-dt-kvs params); + render-dt-overlays = overlays: + lib.strings.concatMapStringsSep "\n" render-dt-overlay + (lib.attrsets.mapAttrsToList + (k: v: { + overlay = k; + args = render-dt-kvs v.params; + }) + (lib.filterAttrs (k: v: v.enable) overlays)); + render-config-section = k: + { options, base-dt-params, dt-overlays }: + let + all-config = lib.concatStringsSep "\n" (lib.filter (x: x != "") [ + (render-options options) + (render-base-dt-params base-dt-params) + (render-dt-overlays dt-overlays) + ]); + in + '' + [${k}] + ${all-config} + ''; + in + conf: + lib.strings.concatStringsSep "\n" + (lib.attrsets.mapAttrsToList render-config-section conf); +in +{ options = { hardware.raspberry-pi = { - config = let - rpi-config-param = { - options = { - enable = lib.mkEnableOption "attr"; - value = - lib.mkOption { type = with lib.types; oneOf [ int str bool ]; }; - }; - }; - dt-param = { - options = { - enable = lib.mkEnableOption "attr"; - value = lib.mkOption { - type = with lib.types; nullOr (oneOf [ int str bool ]); - default = null; + config = + let + rpi-config-param = { + options = { + enable = lib.mkEnableOption "attr"; + value = + lib.mkOption { type = with lib.types; oneOf [ int str bool ]; }; }; }; - }; - dt-overlay = { - options = { - enable = lib.mkEnableOption "overlay"; - params = lib.mkOption { - type = with lib.types; attrsOf (submodule dt-param); - }; - }; - }; - raspberry-pi-config-options = { - options = { - options = lib.mkOption { - type = with lib.types; attrsOf (submodule rpi-config-param); - default = { }; - example = { - enable_gic = { - enable = true; - value = true; - }; - arm_boost = { - enable = true; - value = true; - }; + dt-param = { + options = { + enable = lib.mkEnableOption "attr"; + value = lib.mkOption { + type = with lib.types; nullOr (oneOf [ int str bool ]); + default = null; }; }; - base-dt-params = lib.mkOption { - type = with lib.types; attrsOf (submodule rpi-config-param); - default = { }; - example = { - i2c = { - enable = true; - value = "on"; - }; - audio = { - enable = true; - value = "on"; - }; + }; + dt-overlay = { + options = { + enable = lib.mkEnableOption "overlay"; + params = lib.mkOption { + type = with lib.types; attrsOf (submodule dt-param); }; - description = "parameters to pass to the base dtb"; - }; - dt-overlays = lib.mkOption { - type = with lib.types; attrsOf (submodule dt-overlay); - default = { }; - example = { vc4-kms-v3d = { cma-256 = { enable = true; }; }; }; - description = "dtb overlays to apply"; }; }; + raspberry-pi-config-options = { + options = { + options = lib.mkOption { + type = with lib.types; attrsOf (submodule rpi-config-param); + default = { }; + example = { + enable_gic = { + enable = true; + value = true; + }; + arm_boost = { + enable = true; + value = true; + }; + }; + }; + base-dt-params = lib.mkOption { + type = with lib.types; attrsOf (submodule rpi-config-param); + default = { }; + example = { + i2c = { + enable = true; + value = "on"; + }; + audio = { + enable = true; + value = "on"; + }; + }; + description = "parameters to pass to the base dtb"; + }; + dt-overlays = lib.mkOption { + type = with lib.types; attrsOf (submodule dt-overlay); + default = { }; + example = { vc4-kms-v3d = { cma-256 = { enable = true; }; }; }; + description = "dtb overlays to apply"; + }; + }; + }; + in + lib.mkOption { + type = with lib.types; attrsOf (submodule raspberry-pi-config-options); }; - in lib.mkOption { - type = with lib.types; attrsOf (submodule raspberry-pi-config-options); + + config-generated = lib.mkOption { + type = lib.types.str; + description = "the config text generated by raspberrypi.hardware.config"; + readOnly = true; }; + config-output = lib.mkOption { type = lib.types.package; default = pkgs.writeTextFile { name = "config.txt"; text = '' # This is a generated file. Do not edit! - ${render-raspberrypi-config cfg.config} + ${cfg.config-generated} ''; }; }; }; }; + config = { + hardware.raspberry-pi.config-generated = render-raspberrypi-config cfg.config; + }; } From 9f536c07d1e9e007a61668c52cdfacea1f5ab349 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 3 Jul 2023 21:45:03 -0400 Subject: [PATCH 13/97] Revert "enable uart console for kernel" This reverts commit 5f94c31db1d2c734523a98ae2b490891a6dc3ac7. fixes #6 ttyAMA0 controls uart0, which can be used for bluetooth. If it is used for bluetooth then we don't want to write a bunch of garbage to it. --- sd-image/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sd-image/default.nix b/sd-image/default.nix index 5ee8e7a..2804d06 100644 --- a/sd-image/default.nix +++ b/sd-image/default.nix @@ -10,7 +10,7 @@ boot.consoleLogLevel = lib.mkDefault 7; # https://github.com/raspberrypi/firmware/issues/1539#issuecomment-784498108 - boot.kernelParams = [ "console=ttyAMA0,115200n8" "console=tty1" ]; + boot.kernelParams = [ "console=serial0,115200n8" "console=tty1" ]; sdImage = { populateFirmwareCommands = '' From 409f6368c679b5902ec21f7d7d7721fa03d3e21e Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Thu, 14 Sep 2023 09:10:55 -0400 Subject: [PATCH 14/97] add license --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ec11e22 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Travis Staton + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 9c8a4fc486dbc6f16630255b2e08f19f9886b5a8 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Thu, 11 Jan 2024 10:08:33 -0500 Subject: [PATCH 15/97] bump kernel, firmware, and libcamera/libcamera-apps --- flake.nix | 18 +++++++--- overlay/default.nix | 24 ++++++++++++-- overlay/libcamera-apps.nix | 40 ++++++++++++++++------- overlay/raspberrypi-wireless-firmware.nix | 2 +- 4 files changed, 64 insertions(+), 20 deletions(-) diff --git a/flake.nix b/flake.nix index 51e26dc..8a9fa7e 100644 --- a/flake.nix +++ b/flake.nix @@ -8,23 +8,31 @@ }; rpi-linux-6_1-src = { flake = false; - url = "github:raspberrypi/linux/1.20230405"; + url = "github:raspberrypi/linux/stable_20231123"; }; rpi-firmware-src = { flake = false; - url = "github:raspberrypi/firmware/1.20230405"; + url = "github:raspberrypi/firmware/7e6decce72fdff51923e9203db46716835ae889a"; }; rpi-firmware-nonfree-src = { flake = false; - url = "github:RPi-Distro/firmware-nonfree"; + url = "github:RPi-Distro/firmware-nonfree/88aa085bfa1a4650e1ccd88896f8343c22a24055"; }; rpi-bluez-firmware-src = { flake = false; - url = "github:RPi-Distro/bluez-firmware"; + url = "github:RPi-Distro/bluez-firmware/d9d4741caba7314d6500f588b1eaa5ab387a4ff5"; }; libcamera-apps-src = { flake = false; - url = "github:raspberrypi/libcamera-apps/v1.1.2"; + url = "github:raspberrypi/libcamera-apps/v1.4.1"; + }; + libcamera-src = { + flake = false; + url = "github:raspberrypi/libcamera/563cd78e1c9858769f7e4cc2628e2515836fd6e7"; # v0.1.0+rpt20231122 + }; + libpisp-src = { + flake = false; + url = "github:raspberrypi/libpisp/v1.0.3"; }; }; diff --git a/overlay/default.nix b/overlay/default.nix index ae44d43..ea9b0aa 100644 --- a/overlay/default.nix +++ b/overlay/default.nix @@ -4,11 +4,13 @@ , rpi-firmware-nonfree-src , rpi-bluez-firmware-src , libcamera-apps-src +, libcamera-src +, libpisp-src }: final: prev: let # The version to stick at `pkgs.rpi-kernels.latest' - latest = "v6_1_21"; + latest = "v6_1_63"; # Helpers for building the `pkgs.rpi-kernels' map. rpi-kernel = { kernel, version, fw, wireless-fw, argsOverride ? null }: @@ -42,6 +44,24 @@ in libcamera-apps = final.callPackage ./libcamera-apps.nix { inherit libcamera-apps-src; }; + libpisp = final.stdenv.mkDerivation { + name = "libpisp"; + version = "1.0.3"; + src = libpisp-src; + nativeBuildInputs = with final; [ pkg-config meson ninja ]; + buildInputs = with final; [ nlohmann_json boost ]; + # Meson is no longer able to pick up Boost automatically. + # https://github.com/NixOS/nixpkgs/issues/86131 + BOOST_INCLUDEDIR = "${prev.lib.getDev final.boost}/include"; + BOOST_LIBRARYDIR = "${prev.lib.getLib final.boost}/lib"; + }; + + libcamera = prev.libcamera.overrideAttrs (old: { + version = "0.1.0"; + src = libcamera-src; + buildInputs = old.buildInputs ++ (with final; [ libpisp ]); + }); + # provide generic rpi arm64 u-boot uboot_rpi_arm64 = prev.buildUBoot rec { defconfig = "rpi_arm64_defconfig"; @@ -75,7 +95,7 @@ in # # For example: `pkgs.rpi-kernels.v5_15_87.kernel' rpi-kernels = rpi-kernels [{ - version = "6.1.21"; + version = "6.1.63"; kernel = rpi-linux-6_1-src; fw = rpi-firmware-src; wireless-fw = import ./raspberrypi-wireless-firmware.nix { diff --git a/overlay/libcamera-apps.nix b/overlay/libcamera-apps.nix index 04e29b8..df92f34 100644 --- a/overlay/libcamera-apps.nix +++ b/overlay/libcamera-apps.nix @@ -1,22 +1,38 @@ -{ libcamera-apps-src, lib, stdenv, fetchFromGitHub, fetchpatch, cmake -, pkg-config, libjpeg, libtiff, libpng, libcamera, libepoxy, boost, libexif }: +{ libcamera-apps-src +, lib +, stdenv +, fetchFromGitHub +, fetchpatch +, meson +, pkg-config +, libjpeg +, libtiff +, libpng +, libcamera +, libepoxy +, boost +, libexif +, ninja +}: stdenv.mkDerivation rec { pname = "libcamera-apps"; - version = "v1.1.2"; + version = "v1.4.1"; src = libcamera-apps-src; - nativeBuildInputs = [ cmake pkg-config ]; - buildInputs = [ libjpeg libtiff libcamera libepoxy boost libexif libpng ]; - cmakeFlags = [ - "-DENABLE_QT=0" - "-DENABLE_OPENCV=0" - "-DENABLE_TFLITE=0" - "-DENABLE_X11=1" - "-DENABLE_DRM=1" - (if (stdenv.hostPlatform.isAarch64) then "-DARM64=ON" else "-DARM64=OFF") + nativeBuildInputs = [ meson pkg-config ]; + buildInputs = [ libjpeg libtiff libcamera libepoxy boost libexif libpng ninja ]; + mesonFlags = [ + "-Denable_qt=false" + "-Denable_opencv=false" + "-Denable_tflite=false" + "-Denable_drm=true" ]; + # Meson is no longer able to pick up Boost automatically. + # https://github.com/NixOS/nixpkgs/issues/86131 + BOOST_INCLUDEDIR = "${lib.getDev boost}/include"; + BOOST_LIBRARYDIR = "${lib.getLib boost}/lib"; meta = with lib; { description = "Userland tools interfacing with Raspberry Pi cameras"; diff --git a/overlay/raspberrypi-wireless-firmware.nix b/overlay/raspberrypi-wireless-firmware.nix index 904cbcf..c4cf5db 100644 --- a/overlay/raspberrypi-wireless-firmware.nix +++ b/overlay/raspberrypi-wireless-firmware.nix @@ -3,7 +3,7 @@ stdenvNoCC.mkDerivation { pname = "raspberrypi-wireless-firmware"; - version = "2023-01-19"; + version = "2023-11-15"; srcs = [ ]; From efdc6f68166306a0d1c4af2ede52f53ec243f229 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Tue, 23 Jan 2024 14:36:12 -0500 Subject: [PATCH 16/97] update bluetooth firmware path --- overlay/raspberrypi-wireless-firmware.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/overlay/raspberrypi-wireless-firmware.nix b/overlay/raspberrypi-wireless-firmware.nix index c4cf5db..4e8217a 100644 --- a/overlay/raspberrypi-wireless-firmware.nix +++ b/overlay/raspberrypi-wireless-firmware.nix @@ -23,7 +23,7 @@ stdenvNoCC.mkDerivation { cp -rv "${firmware-nonfree}/debian/config/brcm80211/." "$out/lib/firmware/" # Bluetooth firmware - cp -rv "${bluez-firmware}/broadcom/." "$out/lib/firmware/brcm" + cp -rv "${bluez-firmware}/debian/firmware/broadcom/." "$out/lib/firmware/brcm" # brcmfmac43455-stdio.bin is a symlink to ../cypress/cyfmac43455-stdio.bin that doesn't exist # See https://github.com/RPi-Distro/firmware-nonfree/issues/26 From fac66459b1a9a561b1a31933425949735770a2be Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Tue, 23 Jan 2024 14:36:53 -0500 Subject: [PATCH 17/97] update u-boot --- flake.nix | 2 +- overlay/default.nix | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index 8a9fa7e..0e952e5 100644 --- a/flake.nix +++ b/flake.nix @@ -4,7 +4,7 @@ inputs = { u-boot-src = { flake = false; - url = "https://ftp.denx.de/pub/u-boot/u-boot-2023.01.tar.bz2"; + url = "https://ftp.denx.de/pub/u-boot/u-boot-2024.01.tar.bz2"; }; rpi-linux-6_1-src = { flake = false; diff --git a/overlay/default.nix b/overlay/default.nix index ea9b0aa..8b39495 100644 --- a/overlay/default.nix +++ b/overlay/default.nix @@ -67,7 +67,9 @@ in defconfig = "rpi_arm64_defconfig"; extraMeta.platforms = [ "aarch64-linux" ]; filesToInstall = [ "u-boot.bin" ]; - version = "2023.01"; + version = "2024.01"; + patches = [ ]; + makeFlags = [ ]; src = u-boot-src; # In raspberry pi sbcs the firmware manipulates the device tree in # a variety of ways before handing it off to the linux kernel. [1] @@ -79,10 +81,10 @@ in # firmware and attempt to mimic it. # # 1. https://forums.raspberrypi.com/viewtopic.php?t=329799#p1974233 - extraConfig = '' - CONFIG_OF_HAS_PRIOR_STAGE=y - CONFIG_OF_BOARD=y - ''; + # extraConfig = '' + # CONFIG_OF_HAS_PRIOR_STAGE=y + # CONFIG_OF_BOARD=y + # ''; }; # default to latest firmware From 2e2c5b13fb90487a3fa90754ff9c11b0339938f8 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Tue, 23 Jan 2024 14:50:39 -0500 Subject: [PATCH 18/97] Fix libcamera build --- overlay/default.nix | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/overlay/default.nix b/overlay/default.nix index 8b39495..caaad0d 100644 --- a/overlay/default.nix +++ b/overlay/default.nix @@ -60,6 +60,7 @@ in version = "0.1.0"; src = libcamera-src; buildInputs = old.buildInputs ++ (with final; [ libpisp ]); + patches = [ ]; }); # provide generic rpi arm64 u-boot @@ -81,10 +82,6 @@ in # firmware and attempt to mimic it. # # 1. https://forums.raspberrypi.com/viewtopic.php?t=329799#p1974233 - # extraConfig = '' - # CONFIG_OF_HAS_PRIOR_STAGE=y - # CONFIG_OF_BOARD=y - # ''; }; # default to latest firmware From 9c35dd99cfd2e45898e3c4417b7269e7efe8262d Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Tue, 23 Jan 2024 22:00:36 -0500 Subject: [PATCH 19/97] move libcamera stuff into a separate overlay --- flake.nix | 10 +++++-- {overlay => overlays}/default.nix | 27 +---------------- {overlay => overlays}/libcamera-apps.nix | 0 overlays/libcamera.nix | 30 +++++++++++++++++++ .../raspberrypi-wireless-firmware.nix | 0 rpi/default.nix | 14 +++++++-- 6 files changed, 51 insertions(+), 30 deletions(-) rename {overlay => overlays}/default.nix (82%) rename {overlay => overlays}/libcamera-apps.nix (100%) create mode 100644 overlays/libcamera.nix rename {overlay => overlays}/raspberrypi-wireless-firmware.nix (100%) diff --git a/flake.nix b/flake.nix index 0e952e5..e20abc5 100644 --- a/flake.nix +++ b/flake.nix @@ -37,7 +37,13 @@ }; outputs = srcs@{ self, ... }: { - overlay = import ./overlay (builtins.removeAttrs srcs [ "self" ]); - nixosModules.raspberry-pi = import ./rpi { overlay = self.overlay; }; + overlays = { + core = import ./overlays (builtins.removeAttrs srcs [ "self" ]); + libcamera = import ./overlays/libcamera.nix (builtins.removeAttrs srcs [ "self" ]); + }; + nixosModules.raspberry-pi = import ./rpi { + core-overlay = self.overlays.core; + libcamera-overlay = self.overlays.libcamera; + }; }; } diff --git a/overlay/default.nix b/overlays/default.nix similarity index 82% rename from overlay/default.nix rename to overlays/default.nix index caaad0d..5585e2e 100644 --- a/overlay/default.nix +++ b/overlays/default.nix @@ -3,9 +3,7 @@ , rpi-firmware-src , rpi-firmware-nonfree-src , rpi-bluez-firmware-src -, libcamera-apps-src -, libcamera-src -, libpisp-src +, ... }: final: prev: let @@ -40,29 +38,6 @@ in # the path expected by raspberry pi firmware/device tree compressFirmwareXz = x: x; - # A recent known working version of libcamera-apps - libcamera-apps = - final.callPackage ./libcamera-apps.nix { inherit libcamera-apps-src; }; - - libpisp = final.stdenv.mkDerivation { - name = "libpisp"; - version = "1.0.3"; - src = libpisp-src; - nativeBuildInputs = with final; [ pkg-config meson ninja ]; - buildInputs = with final; [ nlohmann_json boost ]; - # Meson is no longer able to pick up Boost automatically. - # https://github.com/NixOS/nixpkgs/issues/86131 - BOOST_INCLUDEDIR = "${prev.lib.getDev final.boost}/include"; - BOOST_LIBRARYDIR = "${prev.lib.getLib final.boost}/lib"; - }; - - libcamera = prev.libcamera.overrideAttrs (old: { - version = "0.1.0"; - src = libcamera-src; - buildInputs = old.buildInputs ++ (with final; [ libpisp ]); - patches = [ ]; - }); - # provide generic rpi arm64 u-boot uboot_rpi_arm64 = prev.buildUBoot rec { defconfig = "rpi_arm64_defconfig"; diff --git a/overlay/libcamera-apps.nix b/overlays/libcamera-apps.nix similarity index 100% rename from overlay/libcamera-apps.nix rename to overlays/libcamera-apps.nix diff --git a/overlays/libcamera.nix b/overlays/libcamera.nix new file mode 100644 index 0000000..4869ed0 --- /dev/null +++ b/overlays/libcamera.nix @@ -0,0 +1,30 @@ +{ libcamera-apps-src +, libcamera-src +, libpisp-src +, ... +}: +final: prev: +{ + # A recent known working version of libcamera-apps + libcamera-apps = + final.callPackage ./libcamera-apps.nix { inherit libcamera-apps-src; }; + + libpisp = final.stdenv.mkDerivation { + name = "libpisp"; + version = "1.0.3"; + src = libpisp-src; + nativeBuildInputs = with final; [ pkg-config meson ninja ]; + buildInputs = with final; [ nlohmann_json boost ]; + # Meson is no longer able to pick up Boost automatically. + # https://github.com/NixOS/nixpkgs/issues/86131 + BOOST_INCLUDEDIR = "${prev.lib.getDev final.boost}/include"; + BOOST_LIBRARYDIR = "${prev.lib.getLib final.boost}/lib"; + }; + + libcamera = prev.libcamera.overrideAttrs (old: { + version = "0.1.0"; + src = libcamera-src; + buildInputs = old.buildInputs ++ (with final; [ libpisp ]); + patches = [ ]; + }); +} diff --git a/overlay/raspberrypi-wireless-firmware.nix b/overlays/raspberrypi-wireless-firmware.nix similarity index 100% rename from overlay/raspberrypi-wireless-firmware.nix rename to overlays/raspberrypi-wireless-firmware.nix diff --git a/rpi/default.nix b/rpi/default.nix index 32957f1..6ed0563 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -1,4 +1,4 @@ -{ overlay }: +{ core-overlay, libcamera-overlay }: { lib, pkgs, config, ... }: { @@ -12,6 +12,12 @@ type = types.bool; }; }; + libcamera-overlay = { + enable = mkOption { + default = true; + type = types.bool; + }; + }; }; }; @@ -171,7 +177,11 @@ }; }; - nixpkgs = { overlays = [ overlay ]; }; + nixpkgs = { + overlays = [ core-overlay ] + ++ (if config.raspberry-pi-nix.libcamera-overlay.enable + then [ libcamera-overlay ] else [ ]); + }; boot = { initrd.availableKernelModules = [ "usbhid" From 42b98aecd6211542df69ef34b8ef813f314d374f Mon Sep 17 00:00:00 2001 From: Ben Hall Date: Tue, 20 Feb 2024 15:08:02 -0500 Subject: [PATCH 20/97] adding cachix usage blurb to readme --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 686af80..73353c4 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,12 @@ complete example. }; } ``` +## cachix usage and your `nix.conf` +As seen above, cachix is being used to store a linux kernel build. To use this, be sure to add your user and `root` to the trusted-users list in your `nix.conf` file (when using the nix package manager on a non-nixos distro) to be able to pull from this project's cachix. The `root` user must also be still in this list as well importantly. + +``` +trusted-users = root +``` ## Building an sd-card image From 7f3e7cca31088b61a2023b527f341a3d90f63273 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Thu, 22 Feb 2024 10:13:12 -0500 Subject: [PATCH 21/97] docs --- README.md | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 73353c4..5c9a551 100644 --- a/README.md +++ b/README.md @@ -78,8 +78,27 @@ complete example. }; } ``` -## cachix usage and your `nix.conf` -As seen above, cachix is being used to store a linux kernel build. To use this, be sure to add your user and `root` to the trusted-users list in your `nix.conf` file (when using the nix package manager on a non-nixos distro) to be able to pull from this project's cachix. The `root` user must also be still in this list as well importantly. + +## Using the provided cache to avoid compiling linux +This repo uses the raspberry pi linux kernel fork, and compiling linux +takes a while. I do push my kernel builds to a cachix cache that you +may use to avoid compiling linux yourself. The cache can be found +at https://raspberry-pi-nix.cachix.org, and you can follow the +instructions there to use this cache. + +You don't need the cachix binary to use the cachix cache though, you +just need to add the relevant +[`substituters`](https://nixos.org/manual/nix/stable/command-ref/conf-file.html?highlight=nix.conf#conf-substituters) +and +[`trusted-public-keys`](https://nixos.org/manual/nix/stable/command-ref/conf-file.html?highlight=nix.conf#conf-trusted-public-keys) +settings settings to your `nix.conf`. You can do this directly by +modifying your `/etc/nix/nix.conf`, or in the flake definition. In the +above example flake these `nix.conf` settings are added by the +`nixConfig` attribute ([doc +link](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html?highlight=flake#flake-format)), +note that this will only work if the user running `nix build` is in +[`trusted-users`](https://nixos.org/manual/nix/stable/command-ref/conf-file.html?highlight=nix.conf#conf-trusted-users) +or the substituter is in [`trusted-substituters`](https://nixos.org/manual/nix/stable/command-ref/conf-file.html?highlight=nix.conf#conf-trusted-substituters). ``` trusted-users = root From b1ac1e98cd688a024f1c385383b17952bc27d7e5 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Thu, 22 Feb 2024 10:17:49 -0500 Subject: [PATCH 22/97] readme tweak --- README.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5c9a551..38ec325 100644 --- a/README.md +++ b/README.md @@ -95,14 +95,11 @@ settings settings to your `nix.conf`. You can do this directly by modifying your `/etc/nix/nix.conf`, or in the flake definition. In the above example flake these `nix.conf` settings are added by the `nixConfig` attribute ([doc -link](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html?highlight=flake#flake-format)), -note that this will only work if the user running `nix build` is in +link](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html?highlight=flake#flake-format)). +Note that this will only work if the user running `nix build` is in [`trusted-users`](https://nixos.org/manual/nix/stable/command-ref/conf-file.html?highlight=nix.conf#conf-trusted-users) -or the substituter is in [`trusted-substituters`](https://nixos.org/manual/nix/stable/command-ref/conf-file.html?highlight=nix.conf#conf-trusted-substituters). - -``` -trusted-users = root -``` +or the substituter is in +[`trusted-substituters`](https://nixos.org/manual/nix/stable/command-ref/conf-file.html?highlight=nix.conf#conf-trusted-substituters). ## Building an sd-card image From 19a8570ec93e861d752fc5d84cf1a516e4057187 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Wed, 24 Jan 2024 11:16:46 -0500 Subject: [PATCH 23/97] booting --- rpi/default.nix | 74 ++++++++++++++++++++++++++++++++++++++++---- sd-image/default.nix | 52 ++++++++++++++++++++++++------- 2 files changed, 108 insertions(+), 18 deletions(-) diff --git a/rpi/default.nix b/rpi/default.nix index 6ed0563..f1e3087 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -1,6 +1,8 @@ { core-overlay, libcamera-overlay }: { lib, pkgs, config, ... }: +let cfg = config.raspberry-pi-nix; +in { imports = [ ../sd-image ./config.nix ./i2c.nix ]; @@ -18,18 +20,41 @@ type = types.bool; }; }; + uboot = { + enable = mkOption { + default = true; + type = types.bool; + }; + }; }; }; config = { + boot.kernelParams = + if cfg.uboot.enable then [ ] + else [ + "root=PARTUUID=2178694e-02" # todo: use option + "rootfstype=ext4" + "fsck.repair=yes" + "rootwait" + "init=/sbin/init" + ]; systemd.services = { "raspberry-pi-firmware-migrate" = - lib.mkIf config.raspberry-pi-nix.firmware-migration-service.enable { + { description = "update the firmware partition"; - wantedBy = [ "multi-user.target" ]; + wantedBy = if cfg.firmware-migration-service.enable then [ "multi-user.target" ] else [ ]; serviceConfig = - let firmware-path = "/boot/firmware"; - in { + let + firmware-path = "/boot/firmware"; + kernel-params = pkgs.writeTextFile { + name = "cmdline.txt"; + text = '' + ${lib.strings.concatStringsSep " " config.boot.kernelParams} + ''; + }; + in + { Type = "oneshot"; MountImages = "/dev/disk/by-label/${config.sdImage.firmwarePartitionName}:${firmware-path}"; @@ -41,6 +66,8 @@ TARGET_OVERLAYS_DIR="$TARGET_FIRMWARE_DIR/overlays" TMPFILE="$TARGET_FIRMWARE_DIR/tmp" UBOOT="${pkgs.uboot_rpi_arm64}/u-boot.bin" + KERNEL="${pkgs.rpi-kernels.latest.kernel}/Image" + SHOULD_UBOOT=${if cfg.uboot.enable then "1" else "0"} SRC_FIRMWARE_DIR="${pkgs.raspberrypifw}/share/raspberrypi/boot" STARTFILES=("$SRC_FIRMWARE_DIR"/start*.elf) DTBS=("$SRC_FIRMWARE_DIR"/*.dtb) @@ -61,6 +88,28 @@ rm "$STATE_DIRECTORY/uboot-migration-in-progress" } + migrate_kernel() { + echo "migrating kernel" + touch "$STATE_DIRECTORY/kernel-migration-in-progress" + cp "$KERNEL" "$TMPFILE" + mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/kernel.img" + echo "${ + builtins.toString pkgs.rpi-kernels.latest.kernel + }" > "$STATE_DIRECTORY/kernel-version" + rm "$STATE_DIRECTORY/kernel-migration-in-progress" + } + + migrate_cmdline() { + echo "migrating cmdline" + touch "$STATE_DIRECTORY/cmdline-migration-in-progress" + cp "${kernel-params}" "$TMPFILE" + mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/cmdline.txt" + echo "${ + builtins.toString kernel-params + }" > "$STATE_DIRECTORY/cmdline-version" + rm "$STATE_DIRECTORY/cmdline-migration-in-progress" + } + migrate_config() { echo "migrating config.txt" touch "$STATE_DIRECTORY/config-migration-in-progress" @@ -94,12 +143,24 @@ rm "$STATE_DIRECTORY/firmware-migration-in-progress" } - if [[ -f "$STATE_DIRECTORY/uboot-migration-in-progress" || ! -f "$STATE_DIRECTORY/uboot-version" || $(< "$STATE_DIRECTORY/uboot-version") != ${ + if [[ "$SHOULD_UBOOT" -eq 1 ]] && [[ -f "$STATE_DIRECTORY/uboot-migration-in-progress" || ! -f "$STATE_DIRECTORY/uboot-version" || $(< "$STATE_DIRECTORY/uboot-version") != ${ builtins.toString pkgs.uboot_rpi_arm64 } ]]; then migrate_uboot fi + if [[ "$SHOULD_UBOOT" -ne 1 ]] && [[ ! -f "$STATE_DIRECTORY/kernel-version" || $(< "$STATE_DIRECTORY/kernel-version") != ${ + builtins.toString pkgs.rpi-kernels.latest.kernel + } ]]; then + migrate_kernel + fi + + if [[ "$SHOULD_UBOOT" -ne 1 ]] && [[ ! -f "$STATE_DIRECTORY/cmdline-version" || $(< "$STATE_DIRECTORY/cmdline-version") != ${ + builtins.toString kernel-params + } ]]; then + migrate_cmdline + fi + if [[ -f "$STATE_DIRECTORY/config-migration-in-progress" || ! -f "$STATE_DIRECTORY/config-version" || $(< "$STATE_DIRECTORY/config-version") != ${ builtins.toString config.hardware.raspberry-pi.config-output } ]]; then @@ -194,8 +255,9 @@ loader = { grub.enable = lib.mkDefault false; + initScript.enable = !cfg.uboot.enable; generic-extlinux-compatible = { - enable = lib.mkDefault true; + enable = lib.mkDefault cfg.uboot.enable; # We want to use the device tree provided by firmware, so don't # add FDTDIR to the extlinux conf file. useGenerationDeviceTree = false; diff --git a/sd-image/default.nix b/sd-image/default.nix index 2804d06..c14e50b 100644 --- a/sd-image/default.nix +++ b/sd-image/default.nix @@ -5,23 +5,51 @@ config = { boot.loader.grub.enable = false; - boot.loader.generic-extlinux-compatible.enable = true; boot.consoleLogLevel = lib.mkDefault 7; # https://github.com/raspberrypi/firmware/issues/1539#issuecomment-784498108 boot.kernelParams = [ "console=serial0,115200n8" "console=tty1" ]; - sdImage = { - populateFirmwareCommands = '' - cp ${pkgs.uboot_rpi_arm64}/u-boot.bin firmware/u-boot-rpi-arm64.bin - 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 = '' - mkdir -p ./files/boot - ${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot - ''; - }; + sdImage = + let + kernel-params = pkgs.writeTextFile { + name = "cmdline.txt"; + text = '' + ${lib.strings.concatStringsSep " " config.boot.kernelParams} + ''; + }; + populate-kernel = + if config.raspberry-pi-nix.uboot.enable + then '' + cp ${pkgs.uboot_rpi_arm64}/u-boot.bin firmware/u-boot-rpi-arm64.bin + '' + else '' + cp "${pkgs.rpi-kernels.latest.kernel}/Image" firmware/kernel.img + 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 config.raspberry-pi-nix.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 "#!${config.system.build.toplevel.pkgs.bashInteractive}/bin/bash" + echo "exec ${config.system.build.toplevel}/init" + )" + echo "$content" > ./files/sbin/init + chmod 744 ./files/sbin/init + ''; + }; }; } From 462167cc9355770e7b9322375ab82b005073936b Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Tue, 20 Feb 2024 12:43:24 -0500 Subject: [PATCH 24/97] add udev rules --- rpi/default.nix | 53 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/rpi/default.nix b/rpi/default.nix index f1e3087..24d3a45 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -202,7 +202,7 @@ in # linux kernel. kernel = { enable = true; - value = "u-boot-rpi-arm64.bin"; + value = if cfg.uboot.enable then "u-boot-rpi-arm64.bin" else "kernel.img"; }; arm_64bit = { enable = true; @@ -267,11 +267,52 @@ in hardware.enableRedistributableFirmware = true; services = { - udev.extraRules = '' - SUBSYSTEM=="dma_heap", GROUP="video", MODE="0660" - KERNEL=="gpiomem", GROUP="gpio", MODE="0660" - KERNEL=="gpiochip*", GROUP="gpio", MODE="0660" - ''; + udev.extraRules = + let shell = "${pkgs.bash}/bin/bash"; + in '' + # https://raw.githubusercontent.com/RPi-Distro/raspberrypi-sys-mods/master/etc.armhf/udev/rules.d/99-com.rules + SUBSYSTEM=="input", GROUP="input", MODE="0660" + SUBSYSTEM=="i2c-dev", GROUP="i2c", MODE="0660" + SUBSYSTEM=="spidev", GROUP="spi", MODE="0660" + SUBSYSTEM=="*gpiomem*", GROUP="gpio", MODE="0660" + SUBSYSTEM=="rpivid-*", GROUP="video", MODE="0660" + + KERNEL=="vcsm-cma", GROUP="video", MODE="0660" + SUBSYSTEM=="dma_heap", GROUP="video", MODE="0660" + + SUBSYSTEM=="gpio", GROUP="gpio", MODE="0660" + SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="${shell} -c 'chgrp -R gpio /sys/class/gpio && chmod -R g=u /sys/class/gpio'" + SUBSYSTEM=="gpio", ACTION=="add", PROGRAM="${shell} -c 'chgrp -R gpio /sys%p && chmod -R g=u /sys%p'" + + # PWM export results in a "change" action on the pwmchip device (not "add" of a new device), so match actions other than "remove". + SUBSYSTEM=="pwm", ACTION!="remove", PROGRAM="${shell} -c 'chgrp -R gpio /sys%p && chmod -R g=u /sys%p'" + + KERNEL=="ttyAMA[0-9]*|ttyS[0-9]*", PROGRAM="${shell} -c '\ + ALIASES=/proc/device-tree/aliases; \ + TTYNODE=$$(readlink /sys/class/tty/%k/device/of_node | sed 's/base/:/' | cut -d: -f2); \ + if [ -e $$ALIASES/bluetooth ] && [ $$TTYNODE/bluetooth = $$(strings $$ALIASES/bluetooth) ]; then \ + echo 1; \ + elif [ -e $$ALIASES/console ]; then \ + if [ $$TTYNODE = $$(strings $$ALIASES/console) ]; then \ + echo 0;\ + else \ + exit 1; \ + fi \ + elif [ $$TTYNODE = $$(strings $$ALIASES/serial0) ]; then \ + echo 0; \ + elif [ $$TTYNODE = $$(strings $$ALIASES/serial1) ]; then \ + echo 1; \ + else \ + exit 1; \ + fi \ + '", SYMLINK+="serial%c" + + ACTION=="add", SUBSYSTEM=="vtconsole", KERNEL=="vtcon1", RUN+="${shell} -c '\ + if echo RPi-Sense FB | cmp -s /sys/class/graphics/fb0/name; then \ + echo 0 > /sys$devpath/bind; \ + fi; \ + '" + ''; }; }; From adf670acf27505fb8119055003155a1c68b575d9 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 18 Mar 2024 20:28:06 -0400 Subject: [PATCH 25/97] don't hardcode root partition uuid --- rpi/default.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rpi/default.nix b/rpi/default.nix index 24d3a45..475c9ad 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -33,7 +33,11 @@ in boot.kernelParams = if cfg.uboot.enable then [ ] else [ - "root=PARTUUID=2178694e-02" # todo: use option + # This is ugly and fragile, but the sdImage image has an msdos + # 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" "rootfstype=ext4" "fsck.repair=yes" "rootwait" From bc745f7dc1089b2fae2b54cb69e8f0a35bf5a688 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 18 Mar 2024 20:46:27 -0400 Subject: [PATCH 26/97] document new options --- rpi/default.nix | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/rpi/default.nix b/rpi/default.nix index 475c9ad..1652799 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -12,18 +12,35 @@ in enable = mkOption { default = true; type = types.bool; + description = '' + Whether to run the migration service automatically or not. + ''; }; }; libcamera-overlay = { enable = mkOption { default = true; type = types.bool; + description = '' + If enabled then the libcamera overlay is applied which + overrides libcamera with the rpi fork. + ''; }; }; uboot = { enable = mkOption { default = true; type = types.bool; + description = '' + If enabled then uboot is used as the bootloader. If disabled + then the linux kernel is installed directly into the + firmware directory as expected by the raspberry pi boot + process. + + This can be useful for newer hardware that doesn't yet have + uboot compatibility or less common setups, like booting a + cm4 with an nvme drive. + ''; }; }; }; From 9405f0c18ace1c0fb3f1b1b7b63ba9d4b487457c Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 18 Mar 2024 22:02:20 -0400 Subject: [PATCH 27/97] init script bash --- sd-image/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sd-image/default.nix b/sd-image/default.nix index c14e50b..52016a2 100644 --- a/sd-image/default.nix +++ b/sd-image/default.nix @@ -44,7 +44,7 @@ else '' mkdir -p ./files/sbin content="$( - echo "#!${config.system.build.toplevel.pkgs.bashInteractive}/bin/bash" + echo "#!${pkgs.bash}/bin/bash" echo "exec ${config.system.build.toplevel}/init" )" echo "$content" > ./files/sbin/init From 8fc9cbd3e4a53d365596c9cc4fc3cc07cd447af4 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Sat, 11 May 2024 14:14:57 -0400 Subject: [PATCH 28/97] pin kernel --- flake.nix | 30 +++++++++++++++++++++--------- rpi/default.nix | 7 +++++-- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/flake.nix b/flake.nix index e20abc5..b407763 100644 --- a/flake.nix +++ b/flake.nix @@ -2,6 +2,7 @@ description = "raspberry-pi nixos configuration"; inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/9a9960b98418f8c385f52de3b09a63f9c561427a"; u-boot-src = { flake = false; url = "https://ftp.denx.de/pub/u-boot/u-boot-2024.01.tar.bz2"; @@ -36,14 +37,25 @@ }; }; - outputs = srcs@{ self, ... }: { - overlays = { - core = import ./overlays (builtins.removeAttrs srcs [ "self" ]); - libcamera = import ./overlays/libcamera.nix (builtins.removeAttrs srcs [ "self" ]); + outputs = srcs@{ self, ... }: + let + pinned = import nixpkgs { + system = "aarch64-linux"; + overlays = with self.overlays; [ core libcamera ]; + }; + in + { + overlays = { + core = import ./overlays (builtins.removeAttrs srcs [ "self" ]); + libcamera = import ./overlays/libcamera.nix (builtins.removeAttrs srcs [ "self" ]); + }; + nixosModules.raspberry-pi = import ./rpi { + inherit pinned; + core-overlay = self.overlays.core; + libcamera-overlay = self.overlays.libcamera; + }; + packages.aarch64-linux = { + linux = pinned.rpi-kernels.latest.kernel; + }; }; - nixosModules.raspberry-pi = import ./rpi { - core-overlay = self.overlays.core; - libcamera-overlay = self.overlays.libcamera; - }; - }; } diff --git a/rpi/default.nix b/rpi/default.nix index 1652799..0ac3b8a 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -1,4 +1,4 @@ -{ core-overlay, libcamera-overlay }: +{ pinned, core-overlay, libcamera-overlay }: { lib, pkgs, config, ... }: let cfg = config.raspberry-pi-nix; @@ -272,7 +272,10 @@ in "pcie_brcmstb" # required for the pcie bus to work "reset-raspberrypi" # required for vl805 firmware to load ]; - kernelPackages = pkgs.linuxPackagesFor (pkgs.rpi-kernels.latest.kernel); + # This pin is not necessary, it would be fine to replace it with + # `pkgs.rpi-kernels.latest.kernel`. It is helpful to ensure + # cache hits for kernel builds though. + kernelPackages = pinned.linuxPackagesFor (pinned.rpi-kernels.latest.kernel); loader = { grub.enable = lib.mkDefault false; From e858a137fd76d4ef5cbced399febadf8615f7267 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Sat, 11 May 2024 14:21:52 -0400 Subject: [PATCH 29/97] bump rpi sources --- flake.nix | 16 ++++++++-------- overlays/default.nix | 11 ++++++----- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/flake.nix b/flake.nix index b407763..7e592f7 100644 --- a/flake.nix +++ b/flake.nix @@ -5,15 +5,15 @@ nixpkgs.url = "github:NixOS/nixpkgs/9a9960b98418f8c385f52de3b09a63f9c561427a"; u-boot-src = { flake = false; - url = "https://ftp.denx.de/pub/u-boot/u-boot-2024.01.tar.bz2"; + url = "https://ftp.denx.de/pub/u-boot/u-boot-2024.04.tar.bz2"; }; - rpi-linux-6_1-src = { + rpi-linux-6_6-src = { flake = false; - url = "github:raspberrypi/linux/stable_20231123"; + url = "github:raspberrypi/linux/stable_20240423"; }; rpi-firmware-src = { flake = false; - url = "github:raspberrypi/firmware/7e6decce72fdff51923e9203db46716835ae889a"; + url = "github:raspberrypi/firmware/1.20240424"; }; rpi-firmware-nonfree-src = { flake = false; @@ -25,21 +25,21 @@ }; libcamera-apps-src = { flake = false; - url = "github:raspberrypi/libcamera-apps/v1.4.1"; + url = "github:raspberrypi/libcamera-apps/v1.4.4"; }; libcamera-src = { flake = false; - url = "github:raspberrypi/libcamera/563cd78e1c9858769f7e4cc2628e2515836fd6e7"; # v0.1.0+rpt20231122 + url = "github:raspberrypi/libcamera/eb00c13d7c9f937732305d47af5b8ccf895e700f"; # v0.2.0+rpt20240418 }; libpisp-src = { flake = false; - url = "github:raspberrypi/libpisp/v1.0.3"; + url = "github:raspberrypi/libpisp/v1.0.5"; }; }; outputs = srcs@{ self, ... }: let - pinned = import nixpkgs { + pinned = import srcs.nixpkgs { system = "aarch64-linux"; overlays = with self.overlays; [ core libcamera ]; }; diff --git a/overlays/default.nix b/overlays/default.nix index 5585e2e..0571d9d 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,5 +1,5 @@ { u-boot-src -, rpi-linux-6_1-src +, rpi-linux-6_6-src , rpi-firmware-src , rpi-firmware-nonfree-src , rpi-bluez-firmware-src @@ -8,7 +8,7 @@ final: prev: let # The version to stick at `pkgs.rpi-kernels.latest' - latest = "v6_1_63"; + latest = "v6_6_28"; # Helpers for building the `pkgs.rpi-kernels' map. rpi-kernel = { kernel, version, fw, wireless-fw, argsOverride ? null }: @@ -43,7 +43,7 @@ in defconfig = "rpi_arm64_defconfig"; extraMeta.platforms = [ "aarch64-linux" ]; filesToInstall = [ "u-boot.bin" ]; - version = "2024.01"; + version = "2024.04"; patches = [ ]; makeFlags = [ ]; src = u-boot-src; @@ -69,8 +69,8 @@ in # # For example: `pkgs.rpi-kernels.v5_15_87.kernel' rpi-kernels = rpi-kernels [{ - version = "6.1.63"; - kernel = rpi-linux-6_1-src; + version = "6.6.28"; + kernel = rpi-linux-6_6-src; fw = rpi-firmware-src; wireless-fw = import ./raspberrypi-wireless-firmware.nix { bluez-firmware = rpi-bluez-firmware-src; @@ -96,6 +96,7 @@ in # [2] https://github.com/raspberrypi/linux/blob/1.20230405/lib/kunit/Kconfig#L5-L14 # [3] https://github.com/raspberrypi/linux/blob/bb63dc31e48948bc2649357758c7a152210109c4/drivers/gpu/drm/vc4/Kconfig#L38-L52 KUNIT = no; + GPIO_PWM = no; }; }; }] // { From bacb0f119a700aea23a35f8b06866e1c587893c5 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 13 May 2024 22:03:05 -0400 Subject: [PATCH 30/97] add pin-kernel option --- rpi/default.nix | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/rpi/default.nix b/rpi/default.nix index 0ac3b8a..10ff30d 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -8,6 +8,15 @@ in options = with lib; { raspberry-pi-nix = { + pin-kernel = { + enable = mkOption { + default = true; + type = types.bool; + description = '' + Whether to pin the kernel to the latest cachix build. + ''; + }; + }; firmware-migration-service = { enable = mkOption { default = true; @@ -275,7 +284,10 @@ in # This pin is not necessary, it would be fine to replace it with # `pkgs.rpi-kernels.latest.kernel`. It is helpful to ensure # cache hits for kernel builds though. - kernelPackages = pinned.linuxPackagesFor (pinned.rpi-kernels.latest.kernel); + kernelPackages = + if cfg.pin-kernel.enable + then pinned.linuxPackagesFor (pinned.rpi-kernels.latest.kernel) + else pkgs.linuxPackagesFor (pkgs.rpi-kernels.latest.kernel); loader = { grub.enable = lib.mkDefault false; From cf9500ba4cd917dd225328dc8fa9b126ddc2c95e Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Tue, 14 May 2024 18:10:43 -0400 Subject: [PATCH 31/97] bump flake --- flake.lock | 102 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 79 insertions(+), 23 deletions(-) diff --git a/flake.lock b/flake.lock index 406d9d4..823f0fb 100644 --- a/flake.lock +++ b/flake.lock @@ -3,92 +3,147 @@ "libcamera-apps-src": { "flake": false, "locked": { - "lastModified": 1677660281, - "narHash": "sha256-A6UriYk8bHRL6wp6ehXOnUnbJH2/mNDkxwGemD/UYpw=", + "lastModified": 1713431793, + "narHash": "sha256-uoewZMGf3vsBoRDfRz8KBKl+J6st/J44SHvNRMBdaUI=", "owner": "raspberrypi", "repo": "libcamera-apps", - "rev": "54a781dffdd101954dcfa6acd0bd80006f67da83", + "rev": "414a7383464b98f21f5e5381a16cc73ae0350ba6", "type": "github" }, "original": { "owner": "raspberrypi", - "ref": "v1.1.2", + "ref": "v1.4.4", "repo": "libcamera-apps", "type": "github" } }, + "libcamera-src": { + "flake": false, + "locked": { + "lastModified": 1713446223, + "narHash": "sha256-p0/inkHPRUkxSIsTmj7VI7sIaX7OXdqjMGZ31W7cnt4=", + "owner": "raspberrypi", + "repo": "libcamera", + "rev": "eb00c13d7c9f937732305d47af5b8ccf895e700f", + "type": "github" + }, + "original": { + "owner": "raspberrypi", + "repo": "libcamera", + "rev": "eb00c13d7c9f937732305d47af5b8ccf895e700f", + "type": "github" + } + }, + "libpisp-src": { + "flake": false, + "locked": { + "lastModified": 1713362873, + "narHash": "sha256-CHd44CH5dBcZuK+5fZtONZ8HE/lwGKwK5U0BYUK8gG4=", + "owner": "raspberrypi", + "repo": "libpisp", + "rev": "999da5acb4f40cb8e93d22ec16e28edd55ec9414", + "type": "github" + }, + "original": { + "owner": "raspberrypi", + "ref": "v1.0.5", + "repo": "libpisp", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1715218190, + "narHash": "sha256-R98WOBHkk8wIi103JUVQF3ei3oui4HvoZcz9tYOAwlk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9a9960b98418f8c385f52de3b09a63f9c561427a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9a9960b98418f8c385f52de3b09a63f9c561427a", + "type": "github" + } + }, "root": { "inputs": { "libcamera-apps-src": "libcamera-apps-src", + "libcamera-src": "libcamera-src", + "libpisp-src": "libpisp-src", + "nixpkgs": "nixpkgs", "rpi-bluez-firmware-src": "rpi-bluez-firmware-src", "rpi-firmware-nonfree-src": "rpi-firmware-nonfree-src", "rpi-firmware-src": "rpi-firmware-src", - "rpi-linux-6_1-src": "rpi-linux-6_1-src", + "rpi-linux-6_6-src": "rpi-linux-6_6-src", "u-boot-src": "u-boot-src" } }, "rpi-bluez-firmware-src": { "flake": false, "locked": { - "lastModified": 1672928175, - "narHash": "sha256-gKGK0XzNrws5REkKg/JP6SZx3KsJduu53SfH3Dichkc=", + "lastModified": 1698157837, + "narHash": "sha256-CjbZ3t3TW/iJ3+t9QKEtM9NdQU7SwcUCDYuTmFEwvhU=", "owner": "RPi-Distro", "repo": "bluez-firmware", - "rev": "9556b08ace2a1735127894642cc8ea6529c04c90", + "rev": "d9d4741caba7314d6500f588b1eaa5ab387a4ff5", "type": "github" }, "original": { "owner": "RPi-Distro", "repo": "bluez-firmware", + "rev": "d9d4741caba7314d6500f588b1eaa5ab387a4ff5", "type": "github" } }, "rpi-firmware-nonfree-src": { "flake": false, "locked": { - "lastModified": 1683107406, - "narHash": "sha256-9UgB8f2AaxG7S5Px46jOP9wUeO1VXKB0uJiPWh32oDI=", + "lastModified": 1700058854, + "narHash": "sha256-Yynww79LPPkau4YDSLI6IMOjH64nMpHUdGjnCfIR2+M=", "owner": "RPi-Distro", "repo": "firmware-nonfree", - "rev": "2b465a10b04555b7f45b3acb85959c594922a3ce", + "rev": "88aa085bfa1a4650e1ccd88896f8343c22a24055", "type": "github" }, "original": { "owner": "RPi-Distro", "repo": "firmware-nonfree", + "rev": "88aa085bfa1a4650e1ccd88896f8343c22a24055", "type": "github" } }, "rpi-firmware-src": { "flake": false, "locked": { - "lastModified": 1680694337, - "narHash": "sha256-UtUd1MbsrDFxd/1C3eOAMDKPZMx+kSMFYOJP+Kc6IU8=", + "lastModified": 1713970515, + "narHash": "sha256-X5OinkLh/+mx34DM8mCk4tqOGuJdYxkvygv3gA77NJI=", "owner": "raspberrypi", "repo": "firmware", - "rev": "055e044d5359ded1aacc5a17a8e35365373d0b8b", + "rev": "969420b4121b522ab33c5001074cc4c2547dafaf", "type": "github" }, "original": { "owner": "raspberrypi", - "ref": "stable", + "ref": "1.20240424", "repo": "firmware", "type": "github" } }, - "rpi-linux-6_1-src": { + "rpi-linux-6_6-src": { "flake": false, "locked": { - "lastModified": 1680464256, - "narHash": "sha256-ILwecHZ1BN6GhZAUB6/UwiN/rZ8gHndKON6DUhidtxI=", + "lastModified": 1713516936, + "narHash": "sha256-mlsDuVczu0e57BlD/iq7IEEluOIgqbZ+W4Ju30E/zhw=", "owner": "raspberrypi", "repo": "linux", - "rev": "0afb5e98488aed7017b9bf321b575d0177feb7ed", + "rev": "0c341f47adc3578cd5f817aa20ee2b7f9ae6b23e", "type": "github" }, "original": { "owner": "raspberrypi", - "ref": "1.20230405", + "ref": "stable_20240423", "repo": "linux", "type": "github" } @@ -96,13 +151,14 @@ "u-boot-src": { "flake": false, "locked": { - "narHash": "sha256-30fe8klLHRsEtEQ1VpYh4S+AflG5yCQYWlGmpWyFL8w=", + "lastModified": 1712055538, + "narHash": "sha256-IlaDdjKq/Pq2orzcU959h93WXRZfvKBGDO/MFw9mZMg=", "type": "tarball", - "url": "https://ftp.denx.de/pub/u-boot/u-boot-2023.01.tar.bz2" + "url": "https://ftp.denx.de/pub/u-boot/u-boot-2024.04.tar.bz2" }, "original": { "type": "tarball", - "url": "https://ftp.denx.de/pub/u-boot/u-boot-2023.01.tar.bz2" + "url": "https://ftp.denx.de/pub/u-boot/u-boot-2024.04.tar.bz2" } } }, From 26d6ba2a91e6384252bfea5e94c3364e7f8879f2 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Tue, 21 May 2024 09:29:02 -0400 Subject: [PATCH 32/97] remove references to unpinned kernel --- rpi/default.nix | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/rpi/default.nix b/rpi/default.nix index 10ff30d..949a33e 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -1,7 +1,9 @@ { pinned, core-overlay, libcamera-overlay }: { lib, pkgs, config, ... }: -let cfg = config.raspberry-pi-nix; +let + cfg = config.raspberry-pi-nix; + kernel-pkgs = if cfg.pin-kernel.enable then pinned else pkgs; in { imports = [ ../sd-image ./config.nix ./i2c.nix ]; @@ -96,7 +98,7 @@ in TARGET_OVERLAYS_DIR="$TARGET_FIRMWARE_DIR/overlays" TMPFILE="$TARGET_FIRMWARE_DIR/tmp" UBOOT="${pkgs.uboot_rpi_arm64}/u-boot.bin" - KERNEL="${pkgs.rpi-kernels.latest.kernel}/Image" + KERNEL="${kernel-pkgs.rpi-kernels.latest.kernel}/Image" SHOULD_UBOOT=${if cfg.uboot.enable then "1" else "0"} SRC_FIRMWARE_DIR="${pkgs.raspberrypifw}/share/raspberrypi/boot" STARTFILES=("$SRC_FIRMWARE_DIR"/start*.elf) @@ -124,7 +126,7 @@ in cp "$KERNEL" "$TMPFILE" mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/kernel.img" echo "${ - builtins.toString pkgs.rpi-kernels.latest.kernel + builtins.toString kernel-pkgs.rpi-kernels.latest.kernel }" > "$STATE_DIRECTORY/kernel-version" rm "$STATE_DIRECTORY/kernel-migration-in-progress" } @@ -180,7 +182,7 @@ in fi if [[ "$SHOULD_UBOOT" -ne 1 ]] && [[ ! -f "$STATE_DIRECTORY/kernel-version" || $(< "$STATE_DIRECTORY/kernel-version") != ${ - builtins.toString pkgs.rpi-kernels.latest.kernel + builtins.toString kernel-pkgs.rpi-kernels.latest.kernel } ]]; then migrate_kernel fi @@ -284,10 +286,7 @@ in # This pin is not necessary, it would be fine to replace it with # `pkgs.rpi-kernels.latest.kernel`. It is helpful to ensure # cache hits for kernel builds though. - kernelPackages = - if cfg.pin-kernel.enable - then pinned.linuxPackagesFor (pinned.rpi-kernels.latest.kernel) - else pkgs.linuxPackagesFor (pkgs.rpi-kernels.latest.kernel); + kernelPackages = kernel-pkgs.linuxPackagesFor kernel-pkgs.rpi-kernels.latest.kernel; loader = { grub.enable = lib.mkDefault false; From 8a633100aaa3c36f874a1570b2164752f62d5b6a Mon Sep 17 00:00:00 2001 From: MinerSebas Date: Sun, 16 Jun 2024 16:40:53 +0200 Subject: [PATCH 33/97] Also dont use zstd for firmware compression --- overlays/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/overlays/default.nix b/overlays/default.nix index 0571d9d..0d65aa5 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -37,6 +37,7 @@ in # disable firmware compression so that brcm firmware can be found at # the path expected by raspberry pi firmware/device tree compressFirmwareXz = x: x; + compressFirmwareZstd = x: x; # provide generic rpi arm64 u-boot uboot_rpi_arm64 = prev.buildUBoot rec { From d77a2ae4ed1aca0b1025ab664b86fc3f412beb02 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Sun, 16 Jun 2024 12:09:08 -0400 Subject: [PATCH 34/97] optionally pin all inputs --- rpi/default.nix | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/rpi/default.nix b/rpi/default.nix index 949a33e..3514b9a 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -3,14 +3,13 @@ let cfg = config.raspberry-pi-nix; - kernel-pkgs = if cfg.pin-kernel.enable then pinned else pkgs; in { imports = [ ../sd-image ./config.nix ./i2c.nix ]; options = with lib; { raspberry-pi-nix = { - pin-kernel = { + pin-inputs = { enable = mkOption { default = true; type = types.bool; @@ -98,7 +97,7 @@ in TARGET_OVERLAYS_DIR="$TARGET_FIRMWARE_DIR/overlays" TMPFILE="$TARGET_FIRMWARE_DIR/tmp" UBOOT="${pkgs.uboot_rpi_arm64}/u-boot.bin" - KERNEL="${kernel-pkgs.rpi-kernels.latest.kernel}/Image" + KERNEL="${pkgs.rpi-kernels.latest.kernel}/Image" SHOULD_UBOOT=${if cfg.uboot.enable then "1" else "0"} SRC_FIRMWARE_DIR="${pkgs.raspberrypifw}/share/raspberrypi/boot" STARTFILES=("$SRC_FIRMWARE_DIR"/start*.elf) @@ -126,7 +125,7 @@ in cp "$KERNEL" "$TMPFILE" mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/kernel.img" echo "${ - builtins.toString kernel-pkgs.rpi-kernels.latest.kernel + builtins.toString pkgs.rpi-kernels.latest.kernel }" > "$STATE_DIRECTORY/kernel-version" rm "$STATE_DIRECTORY/kernel-migration-in-progress" } @@ -182,7 +181,7 @@ in fi if [[ "$SHOULD_UBOOT" -ne 1 ]] && [[ ! -f "$STATE_DIRECTORY/kernel-version" || $(< "$STATE_DIRECTORY/kernel-version") != ${ - builtins.toString kernel-pkgs.rpi-kernels.latest.kernel + builtins.toString pkgs.rpi-kernels.latest.kernel } ]]; then migrate_kernel fi @@ -271,9 +270,27 @@ in }; nixpkgs = { - overlays = [ core-overlay ] - ++ (if config.raspberry-pi-nix.libcamera-overlay.enable - then [ libcamera-overlay ] else [ ]); + overlays = + let + rpi-overlays = [ core-overlay ] + ++ (if config.raspberry-pi-nix.libcamera-overlay.enable + then [ libcamera-overlay ] else [ ]); + rpi-overlay = lib.composeManyExtensions rpi-overlays; + pin-prev-overlay = overlay: pinned-prev: final: prev: + let + # apply the overlay to pinned-prev and fix that so no references to the actual final + # and prev appear in applied-overlay + applied-overlay = + lib.fix (final: pinned-prev // overlay final pinned-prev); + # We only want to set keys that appear in the overlay, so restrict applied-overlay to + # these keys + restricted-overlay = lib.getAttrs (builtins.attrNames (overlay { } { })) applied-overlay; + in + prev // restricted-overlay; + in + if cfg.pin-inputs.enable + then [ (pin-prev-overlay rpi-overlay pinned) ] + else [ rpi-overlay ]; }; boot = { initrd.availableKernelModules = [ @@ -286,7 +303,7 @@ in # This pin is not necessary, it would be fine to replace it with # `pkgs.rpi-kernels.latest.kernel`. It is helpful to ensure # cache hits for kernel builds though. - kernelPackages = kernel-pkgs.linuxPackagesFor kernel-pkgs.rpi-kernels.latest.kernel; + kernelPackages = pkgs.linuxPackagesFor pkgs.rpi-kernels.latest.kernel; loader = { grub.enable = lib.mkDefault false; From f3eb50ea39f380c0964eb5d009549c0b5241d0a7 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 17 Jun 2024 12:29:09 -0400 Subject: [PATCH 35/97] expose more packages --- flake.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flake.nix b/flake.nix index 7e592f7..35eb3a6 100644 --- a/flake.nix +++ b/flake.nix @@ -56,6 +56,9 @@ }; packages.aarch64-linux = { linux = pinned.rpi-kernels.latest.kernel; + firmware = pinned.rpi-kernels.latest.firmware; + wireless-firmware = pinned.rpi-kernels.latest.wireless-firmware; + uboot-rpi-arm64 = pinned.uboot-rpi-arm64; }; }; } From 6045de5f79ac8eb432cd75e82e1accfb48caff45 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 17 Jun 2024 18:55:50 -0400 Subject: [PATCH 36/97] default uboot to false --- rpi/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpi/default.nix b/rpi/default.nix index 3514b9a..66ad9e4 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -39,7 +39,7 @@ in }; uboot = { enable = mkOption { - default = true; + default = false; type = types.bool; description = '' If enabled then uboot is used as the bootloader. If disabled From c2388c307b17de59ce3d57fe5feb052761905e88 Mon Sep 17 00:00:00 2001 From: adminy Date: Tue, 18 Jun 2024 23:58:46 +0100 Subject: [PATCH 37/97] chore: bump libs & fix libcamera, fix upstream nixpkgs --- flake.lock | 72 +++++------ flake.nix | 21 ++-- overlays/default.nix | 137 +++++++++++---------- overlays/libcamera-apps.nix | 24 +--- overlays/libcamera.nix | 27 +++- overlays/raspberrypi-wireless-firmware.nix | 4 +- rpi/default.nix | 24 +++- sd-image/default.nix | 4 +- 8 files changed, 171 insertions(+), 142 deletions(-) diff --git a/flake.lock b/flake.lock index 823f0fb..5d6ca0c 100644 --- a/flake.lock +++ b/flake.lock @@ -3,16 +3,16 @@ "libcamera-apps-src": { "flake": false, "locked": { - "lastModified": 1713431793, - "narHash": "sha256-uoewZMGf3vsBoRDfRz8KBKl+J6st/J44SHvNRMBdaUI=", + "lastModified": 1717081637, + "narHash": "sha256-s4zJh6r3VhiquO54KWZ78dVCH1BmlphY9zEB9BidNyo=", "owner": "raspberrypi", "repo": "libcamera-apps", - "rev": "414a7383464b98f21f5e5381a16cc73ae0350ba6", + "rev": "49344f2a8d1817558d4e6463032fcf11be618b38", "type": "github" }, "original": { "owner": "raspberrypi", - "ref": "v1.4.4", + "ref": "v1.5.0", "repo": "libcamera-apps", "type": "github" } @@ -20,50 +20,50 @@ "libcamera-src": { "flake": false, "locked": { - "lastModified": 1713446223, - "narHash": "sha256-p0/inkHPRUkxSIsTmj7VI7sIaX7OXdqjMGZ31W7cnt4=", + "lastModified": 1718617480, + "narHash": "sha256-qqEMJzMotybf1nJp1dsz3zc910Qj0TmqCm1CwuSb1VY=", "owner": "raspberrypi", "repo": "libcamera", - "rev": "eb00c13d7c9f937732305d47af5b8ccf895e700f", + "rev": "6ddd79b5bdbedc1f61007aed35391f1559f9e29a", "type": "github" }, "original": { "owner": "raspberrypi", + "ref": "v0.3.0+rpt20240617", "repo": "libcamera", - "rev": "eb00c13d7c9f937732305d47af5b8ccf895e700f", "type": "github" } }, "libpisp-src": { "flake": false, "locked": { - "lastModified": 1713362873, - "narHash": "sha256-CHd44CH5dBcZuK+5fZtONZ8HE/lwGKwK5U0BYUK8gG4=", + "lastModified": 1718613892, + "narHash": "sha256-V/d4RrXoq8HNc8r/Kr1gH3E7YTZzfIdgbaJtq/Xi7uQ=", "owner": "raspberrypi", "repo": "libpisp", - "rev": "999da5acb4f40cb8e93d22ec16e28edd55ec9414", + "rev": "b567f04556801ca350331ed21a1ae3eef4675c23", "type": "github" }, "original": { "owner": "raspberrypi", - "ref": "v1.0.5", + "ref": "v1.0.6", "repo": "libpisp", "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1715218190, - "narHash": "sha256-R98WOBHkk8wIi103JUVQF3ei3oui4HvoZcz9tYOAwlk=", + "lastModified": 1718732645, + "narHash": "sha256-Zv8FapPPVVP5sqty4DWxSaL4p8sFuoAEglelBtSIhm0=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "9a9960b98418f8c385f52de3b09a63f9c561427a", + "rev": "9be7393d7204ba14ead6ec4f0381cc91bfb2aa24", "type": "github" }, "original": { "owner": "NixOS", "repo": "nixpkgs", - "rev": "9a9960b98418f8c385f52de3b09a63f9c561427a", + "rev": "9be7393d7204ba14ead6ec4f0381cc91bfb2aa24", "type": "github" } }, @@ -83,50 +83,50 @@ "rpi-bluez-firmware-src": { "flake": false, "locked": { - "lastModified": 1698157837, - "narHash": "sha256-CjbZ3t3TW/iJ3+t9QKEtM9NdQU7SwcUCDYuTmFEwvhU=", + "lastModified": 1708969706, + "narHash": "sha256-KakKnOBeWxh0exu44beZ7cbr5ni4RA9vkWYb9sGMb8Q=", "owner": "RPi-Distro", "repo": "bluez-firmware", - "rev": "d9d4741caba7314d6500f588b1eaa5ab387a4ff5", + "rev": "78d6a07730e2d20c035899521ab67726dc028e1c", "type": "github" }, "original": { "owner": "RPi-Distro", "repo": "bluez-firmware", - "rev": "d9d4741caba7314d6500f588b1eaa5ab387a4ff5", + "rev": "78d6a07730e2d20c035899521ab67726dc028e1c", "type": "github" } }, "rpi-firmware-nonfree-src": { "flake": false, "locked": { - "lastModified": 1700058854, - "narHash": "sha256-Yynww79LPPkau4YDSLI6IMOjH64nMpHUdGjnCfIR2+M=", + "lastModified": 1708967191, + "narHash": "sha256-BGq0+cr+xBRwQM/LqiQuRWuZpQsKM5jfcrNCqWMuVzM=", "owner": "RPi-Distro", "repo": "firmware-nonfree", - "rev": "88aa085bfa1a4650e1ccd88896f8343c22a24055", + "rev": "223ccf3a3ddb11b3ea829749fbbba4d65b380897", "type": "github" }, "original": { "owner": "RPi-Distro", "repo": "firmware-nonfree", - "rev": "88aa085bfa1a4650e1ccd88896f8343c22a24055", + "rev": "223ccf3a3ddb11b3ea829749fbbba4d65b380897", "type": "github" } }, "rpi-firmware-src": { "flake": false, "locked": { - "lastModified": 1713970515, - "narHash": "sha256-X5OinkLh/+mx34DM8mCk4tqOGuJdYxkvygv3gA77NJI=", + "lastModified": 1716978780, + "narHash": "sha256-KsCo7ZG6vKstxRyFljZtbQvnDSqiAPdUza32xTY/tlA=", "owner": "raspberrypi", "repo": "firmware", - "rev": "969420b4121b522ab33c5001074cc4c2547dafaf", + "rev": "3590de0c181d433af368a95f15bc480bdaff8b47", "type": "github" }, "original": { "owner": "raspberrypi", - "ref": "1.20240424", + "ref": "1.20240529", "repo": "firmware", "type": "github" } @@ -134,31 +134,31 @@ "rpi-linux-6_6-src": { "flake": false, "locked": { - "lastModified": 1713516936, - "narHash": "sha256-mlsDuVczu0e57BlD/iq7IEEluOIgqbZ+W4Ju30E/zhw=", + "lastModified": 1718722155, + "narHash": "sha256-WKlxHAAvDRN10M9pBmF3rNmXKd3uT2hv2/uxASa1LnQ=", "owner": "raspberrypi", "repo": "linux", - "rev": "0c341f47adc3578cd5f817aa20ee2b7f9ae6b23e", + "rev": "da87f91ad8450ccc5274cd7b6ba8d823b396c96f", "type": "github" }, "original": { "owner": "raspberrypi", - "ref": "stable_20240423", "repo": "linux", + "rev": "da87f91ad8450ccc5274cd7b6ba8d823b396c96f", "type": "github" } }, "u-boot-src": { "flake": false, "locked": { - "lastModified": 1712055538, - "narHash": "sha256-IlaDdjKq/Pq2orzcU959h93WXRZfvKBGDO/MFw9mZMg=", + "lastModified": 1717461299, + "narHash": "sha256-vcq+lR3Bw/Nreu8Muywvec4jUvZvodjk/E+8XkkKvZg=", "type": "tarball", - "url": "https://ftp.denx.de/pub/u-boot/u-boot-2024.04.tar.bz2" + "url": "https://ftp.denx.de/pub/u-boot/u-boot-2024.07-rc4.tar.bz2" }, "original": { "type": "tarball", - "url": "https://ftp.denx.de/pub/u-boot/u-boot-2024.04.tar.bz2" + "url": "https://ftp.denx.de/pub/u-boot/u-boot-2024.07-rc4.tar.bz2" } } }, diff --git a/flake.nix b/flake.nix index 35eb3a6..730f7a5 100644 --- a/flake.nix +++ b/flake.nix @@ -2,38 +2,38 @@ description = "raspberry-pi nixos configuration"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/9a9960b98418f8c385f52de3b09a63f9c561427a"; + nixpkgs.url = "github:NixOS/nixpkgs/9be7393d7204ba14ead6ec4f0381cc91bfb2aa24"; # 2024-06-18 u-boot-src = { flake = false; - url = "https://ftp.denx.de/pub/u-boot/u-boot-2024.04.tar.bz2"; + url = "https://ftp.denx.de/pub/u-boot/u-boot-2024.07-rc4.tar.bz2"; }; rpi-linux-6_6-src = { flake = false; - url = "github:raspberrypi/linux/stable_20240423"; + url = "github:raspberrypi/linux/da87f91ad8450ccc5274cd7b6ba8d823b396c96f"; # 2024-06-17 }; rpi-firmware-src = { flake = false; - url = "github:raspberrypi/firmware/1.20240424"; + url = "github:raspberrypi/firmware/1.20240529"; }; rpi-firmware-nonfree-src = { flake = false; - url = "github:RPi-Distro/firmware-nonfree/88aa085bfa1a4650e1ccd88896f8343c22a24055"; + url = "github:RPi-Distro/firmware-nonfree/223ccf3a3ddb11b3ea829749fbbba4d65b380897"; # 1:20230625-2+rpt2 }; rpi-bluez-firmware-src = { flake = false; - url = "github:RPi-Distro/bluez-firmware/d9d4741caba7314d6500f588b1eaa5ab387a4ff5"; + url = "github:RPi-Distro/bluez-firmware/78d6a07730e2d20c035899521ab67726dc028e1c"; # 1.2-9+rpt3 }; libcamera-apps-src = { flake = false; - url = "github:raspberrypi/libcamera-apps/v1.4.4"; + url = "github:raspberrypi/libcamera-apps/v1.5.0"; }; libcamera-src = { flake = false; - url = "github:raspberrypi/libcamera/eb00c13d7c9f937732305d47af5b8ccf895e700f"; # v0.2.0+rpt20240418 + url = "github:raspberrypi/libcamera/v0.3.0+rpt20240617"; }; libpisp-src = { flake = false; - url = "github:raspberrypi/libpisp/v1.0.5"; + url = "github:raspberrypi/libpisp/v1.0.6"; }; }; @@ -55,7 +55,8 @@ libcamera-overlay = self.overlays.libcamera; }; packages.aarch64-linux = { - linux = pinned.rpi-kernels.latest.kernel; + linux_2711 = pinned.rpi-kernels.latest_bcm2711.kernel; + linux_2712 = pinned.rpi-kernels.latest_bcm2712.kernel; firmware = pinned.rpi-kernels.latest.firmware; wireless-firmware = pinned.rpi-kernels.latest.wireless-firmware; uboot-rpi-arm64 = pinned.uboot-rpi-arm64; diff --git a/overlays/default.nix b/overlays/default.nix index 0d65aa5..dc71a19 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -7,70 +7,12 @@ }: final: prev: let - # The version to stick at `pkgs.rpi-kernels.latest' - latest = "v6_6_28"; + # The version to stick at `pkgs.rpi-kernels.latest_bcm271x' + latest = "v6_6_34"; - # Helpers for building the `pkgs.rpi-kernels' map. - rpi-kernel = { kernel, version, fw, wireless-fw, argsOverride ? null }: - let - new-kernel = prev.linux_rpi4.override { - argsOverride = { - src = kernel; - inherit version; - modDirVersion = version; - } // (if builtins.isNull argsOverride then { } else argsOverride); - }; - new-fw = prev.raspberrypifw.overrideAttrs (oldfw: { src = fw; }); - new-wireless-fw = final.callPackage wireless-fw { }; - version-slug = builtins.replaceStrings [ "." ] [ "_" ] version; - in - { - "v${version-slug}" = { - kernel = new-kernel; - firmware = new-fw; - wireless-firmware = new-wireless-fw; - }; - }; - rpi-kernels = builtins.foldl' (b: a: b // rpi-kernel a) { }; -in -{ - # disable firmware compression so that brcm firmware can be found at - # the path expected by raspberry pi firmware/device tree - compressFirmwareXz = x: x; - compressFirmwareZstd = x: x; - - # provide generic rpi arm64 u-boot - uboot_rpi_arm64 = prev.buildUBoot rec { - defconfig = "rpi_arm64_defconfig"; - extraMeta.platforms = [ "aarch64-linux" ]; - filesToInstall = [ "u-boot.bin" ]; - version = "2024.04"; - patches = [ ]; - makeFlags = [ ]; - src = u-boot-src; - # In raspberry pi sbcs the firmware manipulates the device tree in - # a variety of ways before handing it off to the linux kernel. [1] - # Since we have installed u-boot in place of a linux kernel we may - # pass the device tree passed by the firmware onto the kernel, or - # we may provide the kernel with a device tree of our own. This - # configuration uses the device tree provided by firmware so that - # we don't have to be aware of all manipulation done by the - # firmware and attempt to mimic it. - # - # 1. https://forums.raspberrypi.com/viewtopic.php?t=329799#p1974233 - }; - - # default to latest firmware - raspberrypiWirelessFirmware = final.rpi-kernels.latest.wireless-firmware; - raspberrypifw = final.rpi-kernels.latest.firmware; - -} // { - # rpi kernels and firmware are available at - # `pkgs.rpi-kernels..{kernel,firmware,wireless-firmware}'. - # - # For example: `pkgs.rpi-kernels.v5_15_87.kernel' - rpi-kernels = rpi-kernels [{ - version = "6.6.28"; + kernel-config = board: { + inherit board; + version = builtins.replaceStrings ["v" "_"] ["" "."] latest; kernel = rpi-linux-6_6-src; fw = rpi-firmware-src; wireless-fw = import ./raspberrypi-wireless-firmware.nix { @@ -100,7 +42,72 @@ in GPIO_PWM = no; }; }; - }] // { - latest = final.rpi-kernels."${latest}"; }; + + # Helpers for building the `pkgs.rpi-kernels' map. + rpi-kernel = { kernel, version, fw, wireless-fw, argsOverride ? null, board }: + let + new-kernel = prev.linux_rpi4.override { + argsOverride = { + src = kernel; + inherit version; + modDirVersion = version; + kernelPatches = []; + defconfig = "${board}_defconfig"; + postFixup = ""; + } // (if builtins.isNull argsOverride then { } else argsOverride); + }; + new-fw = prev.raspberrypifw.overrideAttrs (oldfw: { src = fw; }); + new-wireless-fw = final.callPackage wireless-fw { }; + version-slug = builtins.replaceStrings [ "." ] [ "_" ] version; + in + { + "latest_${board}" = { + kernel = new-kernel; + firmware = new-fw; + wireless-firmware = new-wireless-fw; + }; + }; + rpi-kernels = builtins.foldl' (b: a: b // rpi-kernel a) { }; +in +{ + # disable firmware compression so that brcm firmware can be found at + # the path expected by raspberry pi firmware/device tree + compressFirmwareXz = x: x; + compressFirmwareZstd = x: x; + + # provide generic rpi arm64 u-boot + uboot_rpi_arm64 = prev.buildUBoot rec { + defconfig = "rpi_arm64_defconfig"; + extraMeta.platforms = [ "aarch64-linux" ]; + filesToInstall = [ "u-boot.bin" ]; + version = "2024.07-rc4"; + patches = [ ]; + makeFlags = [ ]; + src = u-boot-src; + # In raspberry pi sbcs the firmware manipulates the device tree in + # a variety of ways before handing it off to the linux kernel. [1] + # Since we have installed u-boot in place of a linux kernel we may + # pass the device tree passed by the firmware onto the kernel, or + # we may provide the kernel with a device tree of our own. This + # configuration uses the device tree provided by firmware so that + # we don't have to be aware of all manipulation done by the + # firmware and attempt to mimic it. + # + # 1. https://forums.raspberrypi.com/viewtopic.php?t=329799#p1974233 + }; + + # default to latest firmware + raspberrypiWirelessFirmware = final.rpi-kernels.latest_bcm2712.wireless-firmware; + raspberrypifw = final.rpi-kernels.latest_bcm2712.firmware; + +} // { + # rpi kernels and firmware are available at + # `pkgs.rpi-kernels._.{kernel,firmware,wireless-firmware}'. + # + # For example: `pkgs.rpi-kernels.latest_bcm2712.kernel' + rpi-kernels = rpi-kernels [ + (kernel-config "bcm2711") + (kernel-config "bcm2712") + ]; } diff --git a/overlays/libcamera-apps.nix b/overlays/libcamera-apps.nix index df92f34..85529fb 100644 --- a/overlays/libcamera-apps.nix +++ b/overlays/libcamera-apps.nix @@ -1,28 +1,12 @@ -{ libcamera-apps-src -, lib -, stdenv -, fetchFromGitHub -, fetchpatch -, meson -, pkg-config -, libjpeg -, libtiff -, libpng -, libcamera -, libepoxy -, boost -, libexif -, ninja -}: - +{ libcamera-apps-src, lib, pkgs, stdenv }: stdenv.mkDerivation rec { pname = "libcamera-apps"; - version = "v1.4.1"; + version = "v1.5.0"; src = libcamera-apps-src; - nativeBuildInputs = [ meson pkg-config ]; - buildInputs = [ libjpeg libtiff libcamera libepoxy boost libexif libpng ninja ]; + nativeBuildInputs = with pkgs; [ meson pkg-config ]; + buildInputs = with pkgs; [ libjpeg libtiff libcamera libepoxy boost libexif libpng ninja ]; mesonFlags = [ "-Denable_qt=false" "-Denable_opencv=false" diff --git a/overlays/libcamera.nix b/overlays/libcamera.nix index 4869ed0..281979e 100644 --- a/overlays/libcamera.nix +++ b/overlays/libcamera.nix @@ -11,7 +11,7 @@ final: prev: libpisp = final.stdenv.mkDerivation { name = "libpisp"; - version = "1.0.3"; + version = "1.0.5"; src = libpisp-src; nativeBuildInputs = with final; [ pkg-config meson ninja ]; buildInputs = with final; [ nlohmann_json boost ]; @@ -22,9 +22,30 @@ final: prev: }; libcamera = prev.libcamera.overrideAttrs (old: { - version = "0.1.0"; + version = "0.2.0"; src = libcamera-src; - buildInputs = old.buildInputs ++ (with final; [ libpisp ]); + buildInputs = old.buildInputs ++ (with final; [ + libpisp openssl libtiff + (python3.withPackages (ps: with ps; [ + python3-gnutls pybind11 pyyaml ply + ])) + libglibutil gst_all_1.gst-plugins-base + + ]); patches = [ ]; + mesonFlags = [ + "--buildtype=release" + "-Dpipelines=rpi/vc4,rpi/pisp" + "-Dipas=rpi/vc4,rpi/pisp" + "-Dv4l2=true" + "-Dgstreamer=enabled" + "-Dtest=false" + "-Dlc-compliance=disabled" + "-Dcam=disabled" + "-Dqcam=disabled" + "-Ddocumentation=enabled" + "-Dpycamera=enabled" + ]; + }); } diff --git a/overlays/raspberrypi-wireless-firmware.nix b/overlays/raspberrypi-wireless-firmware.nix index 4e8217a..0e776ba 100644 --- a/overlays/raspberrypi-wireless-firmware.nix +++ b/overlays/raspberrypi-wireless-firmware.nix @@ -1,9 +1,9 @@ { bluez-firmware, firmware-nonfree }: -{ lib, stdenvNoCC, fetchFromGitHub }: +{ lib, stdenvNoCC }: stdenvNoCC.mkDerivation { pname = "raspberrypi-wireless-firmware"; - version = "2023-11-15"; + version = "2024-02-26"; srcs = [ ]; diff --git a/rpi/default.nix b/rpi/default.nix index 66ad9e4..4cd1900 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -3,12 +3,23 @@ let cfg = config.raspberry-pi-nix; + board = cfg.board; + kernel = pkgs.rpi-kernels."latest_${board}".kernel; in { imports = [ ../sd-image ./config.nix ./i2c.nix ]; options = with lib; { raspberry-pi-nix = { + board = mkOption { + default = "bcm2712"; + type = types.str; + description = '' + The kernel board version to build. + Examples at: https://github.com/NixOS/nixpkgs/blob/5c8e2fb3c690e8be1d92cda8d2bf0562cd67ce47/pkgs/os-specific/linux/kernel/linux-rpi.nix#L20-L25 + without the _defconfig part. + ''; + }; pin-inputs = { enable = mkOption { default = true; @@ -97,7 +108,7 @@ in TARGET_OVERLAYS_DIR="$TARGET_FIRMWARE_DIR/overlays" TMPFILE="$TARGET_FIRMWARE_DIR/tmp" UBOOT="${pkgs.uboot_rpi_arm64}/u-boot.bin" - KERNEL="${pkgs.rpi-kernels.latest.kernel}/Image" + KERNEL="${kernel}/Image" SHOULD_UBOOT=${if cfg.uboot.enable then "1" else "0"} SRC_FIRMWARE_DIR="${pkgs.raspberrypifw}/share/raspberrypi/boot" STARTFILES=("$SRC_FIRMWARE_DIR"/start*.elf) @@ -125,7 +136,7 @@ in cp "$KERNEL" "$TMPFILE" mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/kernel.img" echo "${ - builtins.toString pkgs.rpi-kernels.latest.kernel + builtins.toString kernel }" > "$STATE_DIRECTORY/kernel-version" rm "$STATE_DIRECTORY/kernel-migration-in-progress" } @@ -181,7 +192,7 @@ in fi if [[ "$SHOULD_UBOOT" -ne 1 ]] && [[ ! -f "$STATE_DIRECTORY/kernel-version" || $(< "$STATE_DIRECTORY/kernel-version") != ${ - builtins.toString pkgs.rpi-kernels.latest.kernel + builtins.toString kernel } ]]; then migrate_kernel fi @@ -301,9 +312,12 @@ in "reset-raspberrypi" # required for vl805 firmware to load ]; # This pin is not necessary, it would be fine to replace it with - # `pkgs.rpi-kernels.latest.kernel`. It is helpful to ensure + # `kernel`. It is helpful to ensure # cache hits for kernel builds though. - kernelPackages = pkgs.linuxPackagesFor pkgs.rpi-kernels.latest.kernel; + kernelPackages = pkgs.linuxPackagesFor (kernel.override { + # Some patches cannot be applied because they are already upstream. + ignoreConfigErrors = true; + }); loader = { grub.enable = lib.mkDefault false; diff --git a/sd-image/default.nix b/sd-image/default.nix index 52016a2..1dc4986 100644 --- a/sd-image/default.nix +++ b/sd-image/default.nix @@ -19,13 +19,15 @@ ${lib.strings.concatStringsSep " " config.boot.kernelParams} ''; }; + board = config.raspberry-pi-nix.board; + kernel = pkgs.rpi-kernels."latest_${board}".kernel; populate-kernel = if config.raspberry-pi-nix.uboot.enable then '' cp ${pkgs.uboot_rpi_arm64}/u-boot.bin firmware/u-boot-rpi-arm64.bin '' else '' - cp "${pkgs.rpi-kernels.latest.kernel}/Image" firmware/kernel.img + cp "${kernel}/Image" firmware/kernel.img cp "${kernel-params}" firmware/cmdline.txt ''; in From 5024cc20e2c2e4f66812841bdfb2f7ad4b8a310f Mon Sep 17 00:00:00 2001 From: adminy Date: Wed, 19 Jun 2024 00:32:04 +0100 Subject: [PATCH 38/97] add my kernel build cache url --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 38ec325..ed1ee21 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,10 @@ complete example. { description = "raspberry-pi-nix example"; nixConfig = { - extra-substituters = [ "https://raspberry-pi-nix.cachix.org" ]; + extra-substituters = [ "https://raspberry-pi-nix.cachix.org" https://adminy.cachix.org ]; extra-trusted-public-keys = [ "raspberry-pi-nix.cachix.org-1:WmV2rdSangxW0rZjY/tBvBDSaNFQ3DyEQsVw8EvHn9o=" + "adminy.cachix.org-1:xgrsLa9L9VCdTbY5dMDqtcl6qBFHA9U56SgEJosNbFc="" ]; }; inputs = { From 48bb6ed6fb3416e2683ee46a54abf1c78a8e51fc Mon Sep 17 00:00:00 2001 From: adminy Date: Wed, 19 Jun 2024 01:06:36 +0100 Subject: [PATCH 39/97] chore: remove unused --- overlays/default.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/overlays/default.nix b/overlays/default.nix index dc71a19..d65548c 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -59,7 +59,6 @@ let }; new-fw = prev.raspberrypifw.overrideAttrs (oldfw: { src = fw; }); new-wireless-fw = final.callPackage wireless-fw { }; - version-slug = builtins.replaceStrings [ "." ] [ "_" ] version; in { "latest_${board}" = { From 4240bff28088c808bdf617e376bfef883b36730b Mon Sep 17 00:00:00 2001 From: adminy Date: Sat, 22 Jun 2024 16:32:44 +0100 Subject: [PATCH 40/97] chore: no double caching, compression now supported --- README.md | 5 +++-- overlays/default.nix | 5 ----- rpi/config.nix | 3 +-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ed1ee21..0534b38 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,9 @@ complete example. { description = "raspberry-pi-nix example"; nixConfig = { - extra-substituters = [ "https://raspberry-pi-nix.cachix.org" https://adminy.cachix.org ]; + extra-substituters = [ "https://raspberry-pi-nix.cachix.org" ]; extra-trusted-public-keys = [ "raspberry-pi-nix.cachix.org-1:WmV2rdSangxW0rZjY/tBvBDSaNFQ3DyEQsVw8EvHn9o=" - "adminy.cachix.org-1:xgrsLa9L9VCdTbY5dMDqtcl6qBFHA9U56SgEJosNbFc="" ]; }; inputs = { @@ -293,3 +292,5 @@ is kept up to date by the overlay applied by this package, so you don't need configure this. However, if you want to use different firmware you can override that package to do so. +## What's not working? +- [ ] Pi 5 u-boot devices other than sd-cards (i.e. usb, nvme). diff --git a/overlays/default.nix b/overlays/default.nix index d65548c..7eac593 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -70,11 +70,6 @@ let rpi-kernels = builtins.foldl' (b: a: b // rpi-kernel a) { }; in { - # disable firmware compression so that brcm firmware can be found at - # the path expected by raspberry pi firmware/device tree - compressFirmwareXz = x: x; - compressFirmwareZstd = x: x; - # provide generic rpi arm64 u-boot uboot_rpi_arm64 = prev.buildUBoot rec { defconfig = "rpi_arm64_defconfig"; diff --git a/rpi/config.nix b/rpi/config.nix index 125cb13..8a785f1 100644 --- a/rpi/config.nix +++ b/rpi/config.nix @@ -16,8 +16,7 @@ let (lib.filterAttrs (k: v: v.enable) x); render-dt-overlay = { overlay, args }: "dtoverlay=" + overlay + "\n" - + lib.strings.concatMapStringsSep "\n" render-dt-param args + "\n" - + "dtoverlay="; + + lib.strings.concatMapStringsSep "\n" render-dt-param args + "\n"; render-base-dt-params = params: lib.strings.concatMapStringsSep "\n" render-dt-param (render-dt-kvs params); From b9c9972ec614e67ce3d93890908e59254715053b Mon Sep 17 00:00:00 2001 From: adminy Date: Sat, 22 Jun 2024 23:49:48 +0100 Subject: [PATCH 41/97] chore: return to stable versions, undo compression, fix libcamera version --- flake.lock | 24 ++++++++++++------------ flake.nix | 10 +++++----- overlays/default.nix | 5 +++++ overlays/libcamera.nix | 2 +- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/flake.lock b/flake.lock index 5d6ca0c..50e4485 100644 --- a/flake.lock +++ b/flake.lock @@ -6,14 +6,14 @@ "lastModified": 1717081637, "narHash": "sha256-s4zJh6r3VhiquO54KWZ78dVCH1BmlphY9zEB9BidNyo=", "owner": "raspberrypi", - "repo": "libcamera-apps", + "repo": "rpicam-apps", "rev": "49344f2a8d1817558d4e6463032fcf11be618b38", "type": "github" }, "original": { "owner": "raspberrypi", "ref": "v1.5.0", - "repo": "libcamera-apps", + "repo": "rpicam-apps", "type": "github" } }, @@ -53,17 +53,17 @@ }, "nixpkgs": { "locked": { - "lastModified": 1718732645, - "narHash": "sha256-Zv8FapPPVVP5sqty4DWxSaL4p8sFuoAEglelBtSIhm0=", + "lastModified": 1718835956, + "narHash": "sha256-wM9v2yIxClRYsGHut5vHICZTK7xdrUGfrLkXvSuv6s4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "9be7393d7204ba14ead6ec4f0381cc91bfb2aa24", + "rev": "dd457de7e08c6d06789b1f5b88fc9327f4d96309", "type": "github" }, "original": { "owner": "NixOS", + "ref": "nixos-24.05", "repo": "nixpkgs", - "rev": "9be7393d7204ba14ead6ec4f0381cc91bfb2aa24", "type": "github" } }, @@ -92,8 +92,8 @@ }, "original": { "owner": "RPi-Distro", + "ref": "bookworm", "repo": "bluez-firmware", - "rev": "78d6a07730e2d20c035899521ab67726dc028e1c", "type": "github" } }, @@ -109,8 +109,8 @@ }, "original": { "owner": "RPi-Distro", + "ref": "bookworm", "repo": "firmware-nonfree", - "rev": "223ccf3a3ddb11b3ea829749fbbba4d65b380897", "type": "github" } }, @@ -134,17 +134,17 @@ "rpi-linux-6_6-src": { "flake": false, "locked": { - "lastModified": 1718722155, - "narHash": "sha256-WKlxHAAvDRN10M9pBmF3rNmXKd3uT2hv2/uxASa1LnQ=", + "lastModified": 1716545726, + "narHash": "sha256-UWUTeCpEN7dlFSQjog6S3HyEWCCnaqiUqV5KxCjYink=", "owner": "raspberrypi", "repo": "linux", - "rev": "da87f91ad8450ccc5274cd7b6ba8d823b396c96f", + "rev": "c1432b4bae5b6582f4d32ba381459f33c34d1424", "type": "github" }, "original": { "owner": "raspberrypi", + "ref": "stable_20240529", "repo": "linux", - "rev": "da87f91ad8450ccc5274cd7b6ba8d823b396c96f", "type": "github" } }, diff --git a/flake.nix b/flake.nix index 730f7a5..0d88847 100644 --- a/flake.nix +++ b/flake.nix @@ -2,14 +2,14 @@ description = "raspberry-pi nixos configuration"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/9be7393d7204ba14ead6ec4f0381cc91bfb2aa24"; # 2024-06-18 + nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; u-boot-src = { flake = false; url = "https://ftp.denx.de/pub/u-boot/u-boot-2024.07-rc4.tar.bz2"; }; rpi-linux-6_6-src = { flake = false; - url = "github:raspberrypi/linux/da87f91ad8450ccc5274cd7b6ba8d823b396c96f"; # 2024-06-17 + url = "github:raspberrypi/linux/stable_20240529"; }; rpi-firmware-src = { flake = false; @@ -17,15 +17,15 @@ }; rpi-firmware-nonfree-src = { flake = false; - url = "github:RPi-Distro/firmware-nonfree/223ccf3a3ddb11b3ea829749fbbba4d65b380897"; # 1:20230625-2+rpt2 + url = "github:RPi-Distro/firmware-nonfree/bookworm"; }; rpi-bluez-firmware-src = { flake = false; - url = "github:RPi-Distro/bluez-firmware/78d6a07730e2d20c035899521ab67726dc028e1c"; # 1.2-9+rpt3 + url = "github:RPi-Distro/bluez-firmware/bookworm"; }; libcamera-apps-src = { flake = false; - url = "github:raspberrypi/libcamera-apps/v1.5.0"; + url = "github:raspberrypi/rpicam-apps/v1.5.0"; }; libcamera-src = { flake = false; diff --git a/overlays/default.nix b/overlays/default.nix index 7eac593..d65548c 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -70,6 +70,11 @@ let rpi-kernels = builtins.foldl' (b: a: b // rpi-kernel a) { }; in { + # disable firmware compression so that brcm firmware can be found at + # the path expected by raspberry pi firmware/device tree + compressFirmwareXz = x: x; + compressFirmwareZstd = x: x; + # provide generic rpi arm64 u-boot uboot_rpi_arm64 = prev.buildUBoot rec { defconfig = "rpi_arm64_defconfig"; diff --git a/overlays/libcamera.nix b/overlays/libcamera.nix index 281979e..9758808 100644 --- a/overlays/libcamera.nix +++ b/overlays/libcamera.nix @@ -11,7 +11,7 @@ final: prev: libpisp = final.stdenv.mkDerivation { name = "libpisp"; - version = "1.0.5"; + version = "1.0.6"; src = libpisp-src; nativeBuildInputs = with final; [ pkg-config meson ninja ]; buildInputs = with final; [ nlohmann_json boost ]; From aa99f3a2ddc08a8c3c22f8a6ddcdd5ddd245a55e Mon Sep 17 00:00:00 2001 From: adminy Date: Sun, 23 Jun 2024 00:02:04 +0100 Subject: [PATCH 42/97] chore: downgrade u-boot to stable release --- flake.lock | 8 ++++---- flake.nix | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/flake.lock b/flake.lock index 50e4485..98fd4b3 100644 --- a/flake.lock +++ b/flake.lock @@ -151,14 +151,14 @@ "u-boot-src": { "flake": false, "locked": { - "lastModified": 1717461299, - "narHash": "sha256-vcq+lR3Bw/Nreu8Muywvec4jUvZvodjk/E+8XkkKvZg=", + "lastModified": 1712055538, + "narHash": "sha256-IlaDdjKq/Pq2orzcU959h93WXRZfvKBGDO/MFw9mZMg=", "type": "tarball", - "url": "https://ftp.denx.de/pub/u-boot/u-boot-2024.07-rc4.tar.bz2" + "url": "https://ftp.denx.de/pub/u-boot/u-boot-2024.04.tar.bz2" }, "original": { "type": "tarball", - "url": "https://ftp.denx.de/pub/u-boot/u-boot-2024.07-rc4.tar.bz2" + "url": "https://ftp.denx.de/pub/u-boot/u-boot-2024.04.tar.bz2" } } }, diff --git a/flake.nix b/flake.nix index 0d88847..3a600c5 100644 --- a/flake.nix +++ b/flake.nix @@ -5,7 +5,7 @@ nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; u-boot-src = { flake = false; - url = "https://ftp.denx.de/pub/u-boot/u-boot-2024.07-rc4.tar.bz2"; + url = "https://ftp.denx.de/pub/u-boot/u-boot-2024.04.tar.bz2"; }; rpi-linux-6_6-src = { flake = false; From 57a532319e4198b858fce0f8a17b71012d143d85 Mon Sep 17 00:00:00 2001 From: adminy Date: Sun, 23 Jun 2024 02:00:09 +0100 Subject: [PATCH 43/97] chore: undo dtparams, improve kernel building code --- flake.nix | 8 +-- overlays/default.nix | 142 +++++++++++++++++++++++-------------------- rpi/config.nix | 3 +- rpi/default.nix | 10 ++- sd-image/default.nix | 3 +- 5 files changed, 93 insertions(+), 73 deletions(-) diff --git a/flake.nix b/flake.nix index 3a600c5..1000a07 100644 --- a/flake.nix +++ b/flake.nix @@ -55,10 +55,10 @@ libcamera-overlay = self.overlays.libcamera; }; packages.aarch64-linux = { - linux_2711 = pinned.rpi-kernels.latest_bcm2711.kernel; - linux_2712 = pinned.rpi-kernels.latest_bcm2712.kernel; - firmware = pinned.rpi-kernels.latest.firmware; - wireless-firmware = pinned.rpi-kernels.latest.wireless-firmware; + linux_2711 = pinned.rpi-kernels.v6_6_31.bcm2711; + linux_2712 = pinned.rpi-kernels.v6_6_31.bcm2712; + firmware = pinned.raspberrypifw; + wireless-firmware = pinned.raspberrypiWirelessFirmware; uboot-rpi-arm64 = pinned.uboot-rpi-arm64; }; }; diff --git a/overlays/default.nix b/overlays/default.nix index d65548c..ef0ceb5 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -7,66 +7,70 @@ }: final: prev: let - # The version to stick at `pkgs.rpi-kernels.latest_bcm271x' - latest = "v6_6_34"; - - kernel-config = board: { - inherit board; - version = builtins.replaceStrings ["v" "_"] ["" "."] latest; - kernel = rpi-linux-6_6-src; - fw = rpi-firmware-src; - wireless-fw = import ./raspberrypi-wireless-firmware.nix { - bluez-firmware = rpi-bluez-firmware-src; - firmware-nonfree = rpi-firmware-nonfree-src; - }; - argsOverride = { - structuredExtraConfig = with prev.lib.kernel; { - # The perl script to generate kernel options sets unspecified - # parameters to `m` if possible [1]. This results in the - # unspecified config option KUNIT [2] getting set to `m` which - # causes DRM_VC4_KUNIT_TEST [3] to get set to `y`. - # - # This vc4 unit test fails on boot due to a null pointer - # exception with the existing config. I'm not sure why, but in - # any case, the DRM_VC4_KUNIT_TEST config option itself states - # that it is only useful for kernel developers working on the - # vc4 driver. So, I feel no need to deviate from the standard - # rpi kernel and attempt to successfully enable this test and - # other unit tests because the nixos perl script has this - # sloppy "default to m" behavior. So, I set KUNIT to `n`. - # - # [1] https://github.com/NixOS/nixpkgs/blob/85bcb95aa83be667e562e781e9d186c57a07d757/pkgs/os-specific/linux/kernel/generate-config.pl#L1-L10 - # [2] https://github.com/raspberrypi/linux/blob/1.20230405/lib/kunit/Kconfig#L5-L14 - # [3] https://github.com/raspberrypi/linux/blob/bb63dc31e48948bc2649357758c7a152210109c4/drivers/gpu/drm/vc4/Kconfig#L38-L52 - KUNIT = no; - GPIO_PWM = no; - }; - }; + versions = { + v6_6_31 = rpi-linux-6_6-src; }; + boards = [ "bcmrpi" "bcm2709" "bcmrpi3" "bcm2711" "bcm2712" ]; # Helpers for building the `pkgs.rpi-kernels' map. - rpi-kernel = { kernel, version, fw, wireless-fw, argsOverride ? null, board }: - let - new-kernel = prev.linux_rpi4.override { - argsOverride = { - src = kernel; - inherit version; - modDirVersion = version; - kernelPatches = []; - defconfig = "${board}_defconfig"; - postFixup = ""; - } // (if builtins.isNull argsOverride then { } else argsOverride); - }; - new-fw = prev.raspberrypifw.overrideAttrs (oldfw: { src = fw; }); - new-wireless-fw = final.callPackage wireless-fw { }; - in - { - "latest_${board}" = { - kernel = new-kernel; - firmware = new-fw; - wireless-firmware = new-wireless-fw; - }; - }; + rpi-kernel = { version, board }: { + "${version}"."${board}" = prev.lib.overrideDerivation (prev.buildLinux { + modDirVersion = version; + inherit version; + pname = "linux-rpi"; + src = versions[version]; + defconfig = "${board}_defconfig"; + structuredExtraConfig = with lib.kernel; { + # Workaround https://github.com/raspberrypi/linux/issues/6198 + # Needed because NixOS 24.05+ sets DRM_SIMPLEDRM=y which pulls in + # DRM_KMS_HELPER=y. + BACKLIGHT_CLASS_DEVICE = yes; + # The perl script to generate kernel options sets unspecified + # parameters to `m` if possible [1]. This results in the + # unspecified config option KUNIT [2] getting set to `m` which + # causes DRM_VC4_KUNIT_TEST [3] to get set to `y`. + # + # This vc4 unit test fails on boot due to a null pointer + # exception with the existing config. I'm not sure why, but in + # any case, the DRM_VC4_KUNIT_TEST config option itself states + # that it is only useful for kernel developers working on the + # vc4 driver. So, I feel no need to deviate from the standard + # rpi kernel and attempt to successfully enable this test and + # other unit tests because the nixos perl script has this + # sloppy "default to m" behavior. So, I set KUNIT to `n`. + # + # [1] https://github.com/NixOS/nixpkgs/blob/85bcb95aa83be667e562e781e9d186c57a07d757/pkgs/os-specific/linux/kernel/generate-config.pl#L1-L10 + # [2] https://github.com/raspberrypi/linux/blob/1.20230405/lib/kunit/Kconfig#L5-L14 + # [3] https://github.com/raspberrypi/linux/blob/bb63dc31e48948bc2649357758c7a152210109c4/drivers/gpu/drm/vc4/Kconfig#L38-L52 + KUNIT = no; + }; + features.efiBootStub = false; + postConfigure = '' + # The v7 defconfig has this set to '-v7' which screws up our modDirVersion. + sed -i $buildRoot/.config -e 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=""/' + sed -i $buildRoot/include/config/auto.conf -e 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=""/' + ''; + postFixup = ""; + kernelPatches = [ + # Fix compilation errors due to incomplete patch backport. + # https://github.com/raspberrypi/linux/pull/6223 + { + name = "gpio-pwm_-_pwm_apply_might_sleep.patch"; + patch = fetchpatch { + url = "https://github.com/peat-psuwit/rpi-linux/commit/879f34b88c60dd59765caa30576cb5bfb8e73c56.patch"; + hash = "sha256-HlOkM9EFmlzOebCGoj7lNV5hc0wMjhaBFFZvaRCI0lI="; + }; + } + { + name = "ir-rx51_-_pwm_apply_might_sleep.patch"; + patch = fetchpatch { + url = "https://github.com/peat-psuwit/rpi-linux/commit/23431052d2dce8084b72e399fce82b05d86b847f.patch"; + hash = "sha256-UDX/BJCJG0WVndP/6PbPK+AZsfU3vVxDCrpn1kb1kqE="; + }; + } + ]; + }); + }; rpi-kernels = builtins.foldl' (b: a: b // rpi-kernel a) { }; in { @@ -80,7 +84,7 @@ in defconfig = "rpi_arm64_defconfig"; extraMeta.platforms = [ "aarch64-linux" ]; filesToInstall = [ "u-boot.bin" ]; - version = "2024.07-rc4"; + version = "2024.04"; patches = [ ]; makeFlags = [ ]; src = u-boot-src; @@ -97,16 +101,22 @@ in }; # default to latest firmware - raspberrypiWirelessFirmware = final.rpi-kernels.latest_bcm2712.wireless-firmware; - raspberrypifw = final.rpi-kernels.latest_bcm2712.firmware; + raspberrypiWirelessFirmware = final.callPackage ( + import ./raspberrypi-wireless-firmware.nix { + bluez-firmware = rpi-bluez-firmware-src; + firmware-nonfree = rpi-firmware-nonfree-src; + } + ) { }; + raspberrypifw = prev.raspberrypifw.overrideAttrs (oldfw: { src = rpi-firmware-src; }); } // { # rpi kernels and firmware are available at - # `pkgs.rpi-kernels._.{kernel,firmware,wireless-firmware}'. + # `pkgs.rpi-kernels..'. # - # For example: `pkgs.rpi-kernels.latest_bcm2712.kernel' - rpi-kernels = rpi-kernels [ - (kernel-config "bcm2711") - (kernel-config "bcm2712") - ]; + # For example: `pkgs.rpi-kernels.v6_6_31.bcm2712' + rpi-kernels = rpi-kernels ( + prev.lib.lists.crossLists + (board: version: { inherit board version; }) + [boards (builtins.attrNames versions)] + ); } diff --git a/rpi/config.nix b/rpi/config.nix index 8a785f1..125cb13 100644 --- a/rpi/config.nix +++ b/rpi/config.nix @@ -16,7 +16,8 @@ let (lib.filterAttrs (k: v: v.enable) x); render-dt-overlay = { overlay, args }: "dtoverlay=" + overlay + "\n" - + lib.strings.concatMapStringsSep "\n" render-dt-param args + "\n"; + + lib.strings.concatMapStringsSep "\n" render-dt-param args + "\n" + + "dtoverlay="; render-base-dt-params = params: lib.strings.concatMapStringsSep "\n" render-dt-param (render-dt-kvs params); diff --git a/rpi/default.nix b/rpi/default.nix index 4cd1900..ed81385 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -4,13 +4,21 @@ let cfg = config.raspberry-pi-nix; board = cfg.board; - kernel = pkgs.rpi-kernels."latest_${board}".kernel; + version = cfg.kernel_version; + kernel = pkgs.rpi-kernels."${version}"."${board}"; in { imports = [ ../sd-image ./config.nix ./i2c.nix ]; options = with lib; { raspberry-pi-nix = { + kernel_version = mkOption { + default = "v6_6_31"; + type = types.str; + description = '' + Kernel version to build. + ''; + }; board = mkOption { default = "bcm2712"; type = types.str; diff --git a/sd-image/default.nix b/sd-image/default.nix index 1dc4986..b24c4e8 100644 --- a/sd-image/default.nix +++ b/sd-image/default.nix @@ -20,7 +20,8 @@ ''; }; board = config.raspberry-pi-nix.board; - kernel = pkgs.rpi-kernels."latest_${board}".kernel; + version = config.raspberry-pi-nix.kernel_version; + kernel = pkgs.rpi-kernels."${version}"."${board}"; populate-kernel = if config.raspberry-pi-nix.uboot.enable then '' From b027897628cc5dc69ad3e323d953dc5e7072f360 Mon Sep 17 00:00:00 2001 From: adminy Date: Sun, 23 Jun 2024 16:43:11 +0100 Subject: [PATCH 44/97] fix: fix targets for flake, add kernel 6.6.34 --- flake.lock | 58 +++++++++++------ flake.nix | 13 ++-- overlays/default.nix | 65 ++++++++++--------- overlays/libcamera.nix | 7 +- .../{libcamera-apps.nix => rpicam-apps.nix} | 0 rpi/default.nix | 10 +-- sd-image/default.nix | 11 ++-- 7 files changed, 97 insertions(+), 67 deletions(-) rename overlays/{libcamera-apps.nix => rpicam-apps.nix} (100%) diff --git a/flake.lock b/flake.lock index 98fd4b3..e2453ac 100644 --- a/flake.lock +++ b/flake.lock @@ -1,22 +1,5 @@ { "nodes": { - "libcamera-apps-src": { - "flake": false, - "locked": { - "lastModified": 1717081637, - "narHash": "sha256-s4zJh6r3VhiquO54KWZ78dVCH1BmlphY9zEB9BidNyo=", - "owner": "raspberrypi", - "repo": "rpicam-apps", - "rev": "49344f2a8d1817558d4e6463032fcf11be618b38", - "type": "github" - }, - "original": { - "owner": "raspberrypi", - "ref": "v1.5.0", - "repo": "rpicam-apps", - "type": "github" - } - }, "libcamera-src": { "flake": false, "locked": { @@ -69,14 +52,15 @@ }, "root": { "inputs": { - "libcamera-apps-src": "libcamera-apps-src", "libcamera-src": "libcamera-src", "libpisp-src": "libpisp-src", "nixpkgs": "nixpkgs", "rpi-bluez-firmware-src": "rpi-bluez-firmware-src", "rpi-firmware-nonfree-src": "rpi-firmware-nonfree-src", "rpi-firmware-src": "rpi-firmware-src", - "rpi-linux-6_6-src": "rpi-linux-6_6-src", + "rpi-linux-6_6_31-src": "rpi-linux-6_6_31-src", + "rpi-linux-6_6_34-src": "rpi-linux-6_6_34-src", + "rpicam-apps-src": "rpicam-apps-src", "u-boot-src": "u-boot-src" } }, @@ -131,7 +115,7 @@ "type": "github" } }, - "rpi-linux-6_6-src": { + "rpi-linux-6_6_31-src": { "flake": false, "locked": { "lastModified": 1716545726, @@ -148,6 +132,40 @@ "type": "github" } }, + "rpi-linux-6_6_34-src": { + "flake": false, + "locked": { + "lastModified": 1718967581, + "narHash": "sha256-RMKvgdhHQQPSmGjAOpYYB7YpClPVks6f6Dw381qDYHY=", + "owner": "raspberrypi", + "repo": "linux", + "rev": "7af85d54e39733bb9a236b95ea5ed1ab8277d560", + "type": "github" + }, + "original": { + "owner": "raspberrypi", + "ref": "rpi-6.6.y", + "repo": "linux", + "type": "github" + } + }, + "rpicam-apps-src": { + "flake": false, + "locked": { + "lastModified": 1717081637, + "narHash": "sha256-s4zJh6r3VhiquO54KWZ78dVCH1BmlphY9zEB9BidNyo=", + "owner": "raspberrypi", + "repo": "rpicam-apps", + "rev": "49344f2a8d1817558d4e6463032fcf11be618b38", + "type": "github" + }, + "original": { + "owner": "raspberrypi", + "ref": "v1.5.0", + "repo": "rpicam-apps", + "type": "github" + } + }, "u-boot-src": { "flake": false, "locked": { diff --git a/flake.nix b/flake.nix index 1000a07..34a9bfd 100644 --- a/flake.nix +++ b/flake.nix @@ -7,10 +7,14 @@ flake = false; url = "https://ftp.denx.de/pub/u-boot/u-boot-2024.04.tar.bz2"; }; - rpi-linux-6_6-src = { + rpi-linux-6_6_31-src = { flake = false; url = "github:raspberrypi/linux/stable_20240529"; }; + rpi-linux-6_6_34-src = { + flake = false; + url = "github:raspberrypi/linux/rpi-6.6.y"; + }; rpi-firmware-src = { flake = false; url = "github:raspberrypi/firmware/1.20240529"; @@ -23,7 +27,7 @@ flake = false; url = "github:RPi-Distro/bluez-firmware/bookworm"; }; - libcamera-apps-src = { + rpicam-apps-src = { flake = false; url = "github:raspberrypi/rpicam-apps/v1.5.0"; }; @@ -55,8 +59,9 @@ libcamera-overlay = self.overlays.libcamera; }; packages.aarch64-linux = { - linux_2711 = pinned.rpi-kernels.v6_6_31.bcm2711; - linux_2712 = pinned.rpi-kernels.v6_6_31.bcm2712; + kernels = pinned.rpi-kernels; + # linux_2711 = pinned.rpi-kernels.v6_6_31.bcm2711; + # linux_2712 = pinned.rpi-kernels.v6_6_31.bcm2712; firmware = pinned.raspberrypifw; wireless-firmware = pinned.raspberrypiWirelessFirmware; uboot-rpi-arm64 = pinned.uboot-rpi-arm64; diff --git a/overlays/default.nix b/overlays/default.nix index ef0ceb5..01be479 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,5 +1,6 @@ { u-boot-src -, rpi-linux-6_6-src +, rpi-linux-6_6_31-src +, rpi-linux-6_6_34-src , rpi-firmware-src , rpi-firmware-nonfree-src , rpi-bluez-firmware-src @@ -8,19 +9,43 @@ final: prev: let versions = { - v6_6_31 = rpi-linux-6_6-src; + v6_6_31 = { + src = rpi-linux-6_6_31-src; + patches = [ + # Fix compilation errors due to incomplete patch backport. + # https://github.com/raspberrypi/linux/pull/6223 + { + name = "gpio-pwm_-_pwm_apply_might_sleep.patch"; + patch = prev.fetchpatch { + url = "https://github.com/peat-psuwit/rpi-linux/commit/879f34b88c60dd59765caa30576cb5bfb8e73c56.patch"; + hash = "sha256-HlOkM9EFmlzOebCGoj7lNV5hc0wMjhaBFFZvaRCI0lI="; + }; + } + { + name = "ir-rx51_-_pwm_apply_might_sleep.patch"; + patch = prev.fetchpatch { + url = "https://github.com/peat-psuwit/rpi-linux/commit/23431052d2dce8084b72e399fce82b05d86b847f.patch"; + hash = "sha256-UDX/BJCJG0WVndP/6PbPK+AZsfU3vVxDCrpn1kb1kqE="; + }; + } + ]; + }; + v6_6_34.src = rpi-linux-6_6_34-src; }; boards = [ "bcmrpi" "bcm2709" "bcmrpi3" "bcm2711" "bcm2712" ]; # Helpers for building the `pkgs.rpi-kernels' map. - rpi-kernel = { version, board }: { + rpi-kernel = { version, board }: let + kernel = versions[version]; + version-slug = builtins.replaceStrings [ "v" "_" ] [ "" "." ] version; + in { "${version}"."${board}" = prev.lib.overrideDerivation (prev.buildLinux { - modDirVersion = version; - inherit version; + modDirVersion = version-slug; + version = version-slug; pname = "linux-rpi"; - src = versions[version]; + src = kernel.src; defconfig = "${board}_defconfig"; - structuredExtraConfig = with lib.kernel; { + structuredExtraConfig = with prev.lib.kernel; { # Workaround https://github.com/raspberrypi/linux/issues/6198 # Needed because NixOS 24.05+ sets DRM_SIMPLEDRM=y which pulls in # DRM_KMS_HELPER=y. @@ -51,24 +76,7 @@ let sed -i $buildRoot/include/config/auto.conf -e 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=""/' ''; postFixup = ""; - kernelPatches = [ - # Fix compilation errors due to incomplete patch backport. - # https://github.com/raspberrypi/linux/pull/6223 - { - name = "gpio-pwm_-_pwm_apply_might_sleep.patch"; - patch = fetchpatch { - url = "https://github.com/peat-psuwit/rpi-linux/commit/879f34b88c60dd59765caa30576cb5bfb8e73c56.patch"; - hash = "sha256-HlOkM9EFmlzOebCGoj7lNV5hc0wMjhaBFFZvaRCI0lI="; - }; - } - { - name = "ir-rx51_-_pwm_apply_might_sleep.patch"; - patch = fetchpatch { - url = "https://github.com/peat-psuwit/rpi-linux/commit/23431052d2dce8084b72e399fce82b05d86b847f.patch"; - hash = "sha256-UDX/BJCJG0WVndP/6PbPK+AZsfU3vVxDCrpn1kb1kqE="; - }; - } - ]; + kernelPatches = if kernel.patches != null then kernel.patches else []; }); }; rpi-kernels = builtins.foldl' (b: a: b // rpi-kernel a) { }; @@ -80,7 +88,7 @@ in compressFirmwareZstd = x: x; # provide generic rpi arm64 u-boot - uboot_rpi_arm64 = prev.buildUBoot rec { + uboot-rpi-arm64 = prev.buildUBoot rec { defconfig = "rpi_arm64_defconfig"; extraMeta.platforms = [ "aarch64-linux" ]; filesToInstall = [ "u-boot.bin" ]; @@ -115,8 +123,7 @@ in # # For example: `pkgs.rpi-kernels.v6_6_31.bcm2712' rpi-kernels = rpi-kernels ( - prev.lib.lists.crossLists - (board: version: { inherit board version; }) - [boards (builtins.attrNames versions)] + prev.lib.cartesianProductOfSets # this gets renamed yet again to cartesianProduct in April 19 2024 + { board = boards; version = (builtins.attrNames versions); } ); } diff --git a/overlays/libcamera.nix b/overlays/libcamera.nix index 9758808..ba887cf 100644 --- a/overlays/libcamera.nix +++ b/overlays/libcamera.nix @@ -1,13 +1,13 @@ -{ libcamera-apps-src +{ rpicam-apps-src , libcamera-src , libpisp-src , ... }: final: prev: { - # A recent known working version of libcamera-apps + # A recent known working version of rpicam-apps libcamera-apps = - final.callPackage ./libcamera-apps.nix { inherit libcamera-apps-src; }; + final.callPackage ./rpicam-apps.nix { inherit rpicam-apps-src; }; libpisp = final.stdenv.mkDerivation { name = "libpisp"; @@ -46,6 +46,5 @@ final: prev: "-Ddocumentation=enabled" "-Dpycamera=enabled" ]; - }); } diff --git a/overlays/libcamera-apps.nix b/overlays/rpicam-apps.nix similarity index 100% rename from overlays/libcamera-apps.nix rename to overlays/rpicam-apps.nix diff --git a/rpi/default.nix b/rpi/default.nix index ed81385..1dcf2eb 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -4,7 +4,7 @@ let cfg = config.raspberry-pi-nix; board = cfg.board; - version = cfg.kernel_version; + version = cfg.kernel-version; kernel = pkgs.rpi-kernels."${version}"."${board}"; in { @@ -12,7 +12,7 @@ in options = with lib; { raspberry-pi-nix = { - kernel_version = mkOption { + kernel-version = mkOption { default = "v6_6_31"; type = types.str; description = '' @@ -115,7 +115,7 @@ in TARGET_FIRMWARE_DIR="${firmware-path}" TARGET_OVERLAYS_DIR="$TARGET_FIRMWARE_DIR/overlays" TMPFILE="$TARGET_FIRMWARE_DIR/tmp" - UBOOT="${pkgs.uboot_rpi_arm64}/u-boot.bin" + UBOOT="${pkgs.uboot-rpi-arm64}/u-boot.bin" KERNEL="${kernel}/Image" SHOULD_UBOOT=${if cfg.uboot.enable then "1" else "0"} SRC_FIRMWARE_DIR="${pkgs.raspberrypifw}/share/raspberrypi/boot" @@ -133,7 +133,7 @@ in cp "$UBOOT" "$TMPFILE" mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/u-boot-rpi-arm64.bin" echo "${ - builtins.toString pkgs.uboot_rpi_arm64 + builtins.toString pkgs.uboot-rpi-arm64 }" > "$STATE_DIRECTORY/uboot-version" rm "$STATE_DIRECTORY/uboot-migration-in-progress" } @@ -194,7 +194,7 @@ in } if [[ "$SHOULD_UBOOT" -eq 1 ]] && [[ -f "$STATE_DIRECTORY/uboot-migration-in-progress" || ! -f "$STATE_DIRECTORY/uboot-version" || $(< "$STATE_DIRECTORY/uboot-version") != ${ - builtins.toString pkgs.uboot_rpi_arm64 + builtins.toString pkgs.uboot-rpi-arm64 } ]]; then migrate_uboot fi diff --git a/sd-image/default.nix b/sd-image/default.nix index b24c4e8..98aa3e1 100644 --- a/sd-image/default.nix +++ b/sd-image/default.nix @@ -19,13 +19,14 @@ ${lib.strings.concatStringsSep " " config.boot.kernelParams} ''; }; - board = config.raspberry-pi-nix.board; - version = config.raspberry-pi-nix.kernel_version; + cfg = config.raspberry-pi-nix; + board = cfg.board; + version = cfg.kernel-version; kernel = pkgs.rpi-kernels."${version}"."${board}"; populate-kernel = - if config.raspberry-pi-nix.uboot.enable + if cfg.uboot.enable then '' - cp ${pkgs.uboot_rpi_arm64}/u-boot.bin firmware/u-boot-rpi-arm64.bin + cp ${pkgs.uboot-rpi-arm64}/u-boot.bin firmware/u-boot-rpi-arm64.bin '' else '' cp "${kernel}/Image" firmware/kernel.img @@ -39,7 +40,7 @@ cp ${config.hardware.raspberry-pi.config-output} firmware/config.txt ''; populateRootCommands = - if config.raspberry-pi-nix.uboot.enable + if cfg.uboot.enable then '' mkdir -p ./files/boot ${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot From 9113306d60bda3b0d6c0223773bb19857da42661 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 24 Jun 2024 09:11:22 -0400 Subject: [PATCH 45/97] run nixpkgs-fmt --- overlays/default.nix | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/overlays/default.nix b/overlays/default.nix index 01be479..4611cf2 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -35,11 +35,13 @@ let boards = [ "bcmrpi" "bcm2709" "bcmrpi3" "bcm2711" "bcm2712" ]; # Helpers for building the `pkgs.rpi-kernels' map. - rpi-kernel = { version, board }: let - kernel = versions[version]; - version-slug = builtins.replaceStrings [ "v" "_" ] [ "" "." ] version; - in { - "${version}"."${board}" = prev.lib.overrideDerivation (prev.buildLinux { + rpi-kernel = { version, board }: + let + kernel = versions [ version ]; + version-slug = builtins.replaceStrings [ "v" "_" ] [ "" "." ] version; + in + { + "${version}"."${board}" = prev.lib.overrideDerivation (prev.buildLinux { modDirVersion = version-slug; version = version-slug; pname = "linux-rpi"; @@ -76,9 +78,9 @@ let sed -i $buildRoot/include/config/auto.conf -e 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=""/' ''; postFixup = ""; - kernelPatches = if kernel.patches != null then kernel.patches else []; - }); - }; + kernelPatches = if kernel.patches != null then kernel.patches else [ ]; + }); + }; rpi-kernels = builtins.foldl' (b: a: b // rpi-kernel a) { }; in { @@ -109,12 +111,14 @@ in }; # default to latest firmware - raspberrypiWirelessFirmware = final.callPackage ( - import ./raspberrypi-wireless-firmware.nix { - bluez-firmware = rpi-bluez-firmware-src; - firmware-nonfree = rpi-firmware-nonfree-src; - } - ) { }; + raspberrypiWirelessFirmware = final.callPackage + ( + import ./raspberrypi-wireless-firmware.nix { + bluez-firmware = rpi-bluez-firmware-src; + firmware-nonfree = rpi-firmware-nonfree-src; + } + ) + { }; raspberrypifw = prev.raspberrypifw.overrideAttrs (oldfw: { src = rpi-firmware-src; }); } // { From 50e36bf86a956e2016f38283b6ee04812fbf175f Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 24 Jun 2024 09:13:52 -0400 Subject: [PATCH 46/97] fix version lookup --- overlays/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/overlays/default.nix b/overlays/default.nix index 4611cf2..d8f328f 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -37,7 +37,7 @@ let # Helpers for building the `pkgs.rpi-kernels' map. rpi-kernel = { version, board }: let - kernel = versions [ version ]; + kernel = builtins.getAttr version versions; version-slug = builtins.replaceStrings [ "v" "_" ] [ "" "." ] version; in { From f1bf6b9d9b928cb5f0af070839e3f6212a5b54a2 Mon Sep 17 00:00:00 2001 From: Nigel Choi <9gel@users.noreply.github.com> Date: Mon, 24 Jun 2024 21:16:30 +0800 Subject: [PATCH 47/97] Add groups so udev rules work in parity with official rpi --- rpi/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rpi/default.nix b/rpi/default.nix index 66ad9e4..08ac59f 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -318,6 +318,8 @@ in }; hardware.enableRedistributableFirmware = true; + users.groups = builtins.listToAttrs (map (k: { name = k; value = {}; }) + ["input" "sudo" "plugdev" "games" "netdev" "gpio" "i2c" "spi"]); services = { udev.extraRules = let shell = "${pkgs.bash}/bin/bash"; From f0c963957bdc931ac35943d1fa31c99b6db35521 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 24 Jun 2024 09:18:51 -0400 Subject: [PATCH 48/97] remove overrideDerivation It wasn't fully applied and it isn't necessary for these overrides anyway --- overlays/default.nix | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/overlays/default.nix b/overlays/default.nix index d8f328f..5f5850f 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -41,13 +41,13 @@ let version-slug = builtins.replaceStrings [ "v" "_" ] [ "" "." ] version; in { - "${version}"."${board}" = prev.lib.overrideDerivation (prev.buildLinux { + "${version}"."${board}" = (final.buildLinux { modDirVersion = version-slug; version = version-slug; pname = "linux-rpi"; src = kernel.src; defconfig = "${board}_defconfig"; - structuredExtraConfig = with prev.lib.kernel; { + structuredExtraConfig = with final.lib.kernel; { # Workaround https://github.com/raspberrypi/linux/issues/6198 # Needed because NixOS 24.05+ sets DRM_SIMPLEDRM=y which pulls in # DRM_KMS_HELPER=y. @@ -72,14 +72,16 @@ let KUNIT = no; }; features.efiBootStub = false; - postConfigure = '' - # The v7 defconfig has this set to '-v7' which screws up our modDirVersion. - sed -i $buildRoot/.config -e 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=""/' - sed -i $buildRoot/include/config/auto.conf -e 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=""/' - ''; - postFixup = ""; - kernelPatches = if kernel.patches != null then kernel.patches else [ ]; - }); + kernelPatches = + if kernel ? "patches" then kernel.patches else [ ]; + }).overrideAttrs + (oldAttrs: { + postConfigure = '' + # The v7 defconfig has this set to '-v7' which screws up our modDirVersion. + sed -i $buildRoot/.config -e 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=""/' + sed -i $buildRoot/include/config/auto.conf -e 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=""/' + ''; + }); }; rpi-kernels = builtins.foldl' (b: a: b // rpi-kernel a) { }; in From 7f3a320cc09443d4166347cb03e23d8d7f7b0e43 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 24 Jun 2024 09:20:26 -0400 Subject: [PATCH 49/97] fix clobbering of all but one board per version --- overlays/default.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/overlays/default.nix b/overlays/default.nix index 5f5850f..72f2437 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -83,7 +83,9 @@ let ''; }); }; - rpi-kernels = builtins.foldl' (b: a: b // rpi-kernel a) { }; + rpi-kernels = builtins.foldl' + (b: a: final.lib.recursiveUpdate b (rpi-kernel a)) + { }; in { # disable firmware compression so that brcm firmware can be found at From 4f517c83bfccdfc9a8930fda8c022012766324d9 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 24 Jun 2024 09:21:22 -0400 Subject: [PATCH 50/97] use final when appropriate --- overlays/default.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/overlays/default.nix b/overlays/default.nix index 72f2437..4b7a5f5 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -16,14 +16,14 @@ let # https://github.com/raspberrypi/linux/pull/6223 { name = "gpio-pwm_-_pwm_apply_might_sleep.patch"; - patch = prev.fetchpatch { + patch = final.fetchpatch { url = "https://github.com/peat-psuwit/rpi-linux/commit/879f34b88c60dd59765caa30576cb5bfb8e73c56.patch"; hash = "sha256-HlOkM9EFmlzOebCGoj7lNV5hc0wMjhaBFFZvaRCI0lI="; }; } { name = "ir-rx51_-_pwm_apply_might_sleep.patch"; - patch = prev.fetchpatch { + patch = final.fetchpatch { url = "https://github.com/peat-psuwit/rpi-linux/commit/23431052d2dce8084b72e399fce82b05d86b847f.patch"; hash = "sha256-UDX/BJCJG0WVndP/6PbPK+AZsfU3vVxDCrpn1kb1kqE="; }; @@ -94,7 +94,7 @@ in compressFirmwareZstd = x: x; # provide generic rpi arm64 u-boot - uboot-rpi-arm64 = prev.buildUBoot rec { + uboot-rpi-arm64 = final.buildUBoot rec { defconfig = "rpi_arm64_defconfig"; extraMeta.platforms = [ "aarch64-linux" ]; filesToInstall = [ "u-boot.bin" ]; @@ -131,7 +131,7 @@ in # # For example: `pkgs.rpi-kernels.v6_6_31.bcm2712' rpi-kernels = rpi-kernels ( - prev.lib.cartesianProductOfSets # this gets renamed yet again to cartesianProduct in April 19 2024 + final.lib.cartesianProductOfSets # this gets renamed yet again to cartesianProduct in April 19 2024 { board = boards; version = (builtins.attrNames versions); } ); } From 16d872085fe10077bd6665e2652582f013107e65 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 24 Jun 2024 09:24:34 -0400 Subject: [PATCH 51/97] Avoid tags with `+` in them due to parsing bug https://github.com/NixOS/nix/issues/6688 --- flake.lock | 2 +- flake.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.lock b/flake.lock index e2453ac..99b2d11 100644 --- a/flake.lock +++ b/flake.lock @@ -12,8 +12,8 @@ }, "original": { "owner": "raspberrypi", - "ref": "v0.3.0+rpt20240617", "repo": "libcamera", + "rev": "6ddd79b5bdbedc1f61007aed35391f1559f9e29a", "type": "github" } }, diff --git a/flake.nix b/flake.nix index 34a9bfd..b218e6c 100644 --- a/flake.nix +++ b/flake.nix @@ -33,7 +33,7 @@ }; libcamera-src = { flake = false; - url = "github:raspberrypi/libcamera/v0.3.0+rpt20240617"; + url = "github:raspberrypi/libcamera/6ddd79b5bdbedc1f61007aed35391f1559f9e29a"; # v0.3.0+rpt20240617 }; libpisp-src = { flake = false; From 40011886152e5299a098f04bf80d2ee64df74370 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 24 Jun 2024 09:26:37 -0400 Subject: [PATCH 52/97] remove package comment --- flake.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/flake.nix b/flake.nix index b218e6c..7289281 100644 --- a/flake.nix +++ b/flake.nix @@ -60,8 +60,6 @@ }; packages.aarch64-linux = { kernels = pinned.rpi-kernels; - # linux_2711 = pinned.rpi-kernels.v6_6_31.bcm2711; - # linux_2712 = pinned.rpi-kernels.v6_6_31.bcm2712; firmware = pinned.raspberrypifw; wireless-firmware = pinned.raspberrypiWirelessFirmware; uboot-rpi-arm64 = pinned.uboot-rpi-arm64; From caed11b1f6273ddd10460a033cfaf5230d843cdd Mon Sep 17 00:00:00 2001 From: adminy Date: Tue, 25 Jun 2024 00:12:11 +0100 Subject: [PATCH 53/97] chore: remove error silencing --- rpi/default.nix | 12 +++--------- sd-image/default.nix | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/rpi/default.nix b/rpi/default.nix index 1dcf2eb..df52430 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -3,8 +3,8 @@ let cfg = config.raspberry-pi-nix; - board = cfg.board; version = cfg.kernel-version; + board = cfg.board; kernel = pkgs.rpi-kernels."${version}"."${board}"; in { @@ -15,9 +15,7 @@ in kernel-version = mkOption { default = "v6_6_31"; type = types.str; - description = '' - Kernel version to build. - ''; + description = "Kernel version to build."; }; board = mkOption { default = "bcm2712"; @@ -322,11 +320,7 @@ in # This pin is not necessary, it would be fine to replace it with # `kernel`. It is helpful to ensure # cache hits for kernel builds though. - kernelPackages = pkgs.linuxPackagesFor (kernel.override { - # Some patches cannot be applied because they are already upstream. - ignoreConfigErrors = true; - }); - + kernelPackages = pkgs.linuxPackagesFor kernel; loader = { grub.enable = lib.mkDefault false; initScript.enable = !cfg.uboot.enable; diff --git a/sd-image/default.nix b/sd-image/default.nix index 98aa3e1..d1dc124 100644 --- a/sd-image/default.nix +++ b/sd-image/default.nix @@ -20,8 +20,8 @@ ''; }; cfg = config.raspberry-pi-nix; - board = cfg.board; version = cfg.kernel-version; + board = cfg.board; kernel = pkgs.rpi-kernels."${version}"."${board}"; populate-kernel = if cfg.uboot.enable From 196c7f8e4b2dce3510abdb10296ea8f6032e73bc Mon Sep 17 00:00:00 2001 From: adminy Date: Fri, 28 Jun 2024 07:53:31 +0100 Subject: [PATCH 54/97] chore: build latest kernel --- flake.lock | 36 ++++++++++++++++++------------------ flake.nix | 4 ++-- overlays/default.nix | 19 +++++++++++++------ 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/flake.lock b/flake.lock index 99b2d11..9c5513e 100644 --- a/flake.lock +++ b/flake.lock @@ -58,8 +58,8 @@ "rpi-bluez-firmware-src": "rpi-bluez-firmware-src", "rpi-firmware-nonfree-src": "rpi-firmware-nonfree-src", "rpi-firmware-src": "rpi-firmware-src", + "rpi-linux-6_10_0-rc5-src": "rpi-linux-6_10_0-rc5-src", "rpi-linux-6_6_31-src": "rpi-linux-6_6_31-src", - "rpi-linux-6_6_34-src": "rpi-linux-6_6_34-src", "rpicam-apps-src": "rpicam-apps-src", "u-boot-src": "u-boot-src" } @@ -115,6 +115,23 @@ "type": "github" } }, + "rpi-linux-6_10_0-rc5-src": { + "flake": false, + "locked": { + "lastModified": 1719265450, + "narHash": "sha256-xd/Pz/uZFYW9hJIFKryWDE9Aks6f2EIvEDCmfk0C70c=", + "owner": "raspberrypi", + "repo": "linux", + "rev": "f61d3aca8045e70d64b55f7b98f083738f639ad2", + "type": "github" + }, + "original": { + "owner": "raspberrypi", + "ref": "rpi-6.10.y", + "repo": "linux", + "type": "github" + } + }, "rpi-linux-6_6_31-src": { "flake": false, "locked": { @@ -132,23 +149,6 @@ "type": "github" } }, - "rpi-linux-6_6_34-src": { - "flake": false, - "locked": { - "lastModified": 1718967581, - "narHash": "sha256-RMKvgdhHQQPSmGjAOpYYB7YpClPVks6f6Dw381qDYHY=", - "owner": "raspberrypi", - "repo": "linux", - "rev": "7af85d54e39733bb9a236b95ea5ed1ab8277d560", - "type": "github" - }, - "original": { - "owner": "raspberrypi", - "ref": "rpi-6.6.y", - "repo": "linux", - "type": "github" - } - }, "rpicam-apps-src": { "flake": false, "locked": { diff --git a/flake.nix b/flake.nix index 7289281..d127311 100644 --- a/flake.nix +++ b/flake.nix @@ -11,9 +11,9 @@ flake = false; url = "github:raspberrypi/linux/stable_20240529"; }; - rpi-linux-6_6_34-src = { + rpi-linux-6_10_0-rc5-src = { flake = false; - url = "github:raspberrypi/linux/rpi-6.6.y"; + url = "github:raspberrypi/linux/rpi-6.10.y"; }; rpi-firmware-src = { flake = false; diff --git a/overlays/default.nix b/overlays/default.nix index 4b7a5f5..058ef30 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,6 +1,6 @@ { u-boot-src , rpi-linux-6_6_31-src -, rpi-linux-6_6_34-src +, rpi-linux-6_10_0-rc5-src , rpi-firmware-src , rpi-firmware-nonfree-src , rpi-bluez-firmware-src @@ -30,7 +30,18 @@ let } ]; }; - v6_6_34.src = rpi-linux-6_6_34-src; + v6_10_0-rc5 = { + src = rpi-linux-6_10_0-rc5-src; + patches = [ + { + name = "remove-readme-target.patch"; + patch = final.fetchpatch { + url = "https://github.com/raspberrypi/linux/commit/3c0fd51d184f1748b83d28e1113265425c19bcb5.patch"; + hash = "sha256-v7uZOmPCUp2i7NGVgjqnQYe6dEBD+aATuP/oRs9jfuk="; + }; + } + ]; + }; }; boards = [ "bcmrpi" "bcm2709" "bcmrpi3" "bcm2711" "bcm2712" ]; @@ -48,10 +59,6 @@ let src = kernel.src; defconfig = "${board}_defconfig"; structuredExtraConfig = with final.lib.kernel; { - # Workaround https://github.com/raspberrypi/linux/issues/6198 - # Needed because NixOS 24.05+ sets DRM_SIMPLEDRM=y which pulls in - # DRM_KMS_HELPER=y. - BACKLIGHT_CLASS_DEVICE = yes; # The perl script to generate kernel options sets unspecified # parameters to `m` if possible [1]. This results in the # unspecified config option KUNIT [2] getting set to `m` which From 25b88136ac3a0cc15e29275db556ebed565686cb Mon Sep 17 00:00:00 2001 From: adminy Date: Fri, 28 Jun 2024 09:37:03 +0100 Subject: [PATCH 55/97] chore: undo backlight --- overlays/default.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/overlays/default.nix b/overlays/default.nix index 058ef30..c5cb91f 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -59,6 +59,10 @@ let src = kernel.src; defconfig = "${board}_defconfig"; structuredExtraConfig = with final.lib.kernel; { + # Workaround https://github.com/raspberrypi/linux/issues/6198 + # Needed because NixOS 24.05+ sets DRM_SIMPLEDRM=y which pulls in + # DRM_KMS_HELPER=y. + BACKLIGHT_CLASS_DEVICE = yes; # The perl script to generate kernel options sets unspecified # parameters to `m` if possible [1]. This results in the # unspecified config option KUNIT [2] getting set to `m` which From 02b119708c5ddbb3bdbe51e924a143ca5056a2d1 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Fri, 26 Jul 2024 08:44:48 -0400 Subject: [PATCH 56/97] Remove default board, requiring the user to specify --- rpi/default.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/rpi/default.nix b/rpi/default.nix index e72313c..f11ac51 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -18,7 +18,6 @@ in description = "Kernel version to build."; }; board = mkOption { - default = "bcm2712"; type = types.str; description = '' The kernel board version to build. From cc48d16dd4cd0b8affac0751c1e0cf6b31a107b9 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Fri, 26 Jul 2024 08:45:21 -0400 Subject: [PATCH 57/97] update board doc with better link --- rpi/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpi/default.nix b/rpi/default.nix index f11ac51..2c05609 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -21,7 +21,7 @@ in type = types.str; description = '' The kernel board version to build. - Examples at: https://github.com/NixOS/nixpkgs/blob/5c8e2fb3c690e8be1d92cda8d2bf0562cd67ce47/pkgs/os-specific/linux/kernel/linux-rpi.nix#L20-L25 + Examples at: https://www.raspberrypi.com/documentation/computers/linux_kernel.html#native-build-configuration without the _defconfig part. ''; }; From 3375c37c2cda13074ede1f5ed12bcb651d0ffc5a Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Fri, 26 Jul 2024 08:50:52 -0400 Subject: [PATCH 58/97] restrict board options --- overlays/default.nix | 2 +- rpi/default.nix | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/overlays/default.nix b/overlays/default.nix index c5cb91f..5de4638 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -43,7 +43,7 @@ let ]; }; }; - boards = [ "bcmrpi" "bcm2709" "bcmrpi3" "bcm2711" "bcm2712" ]; + boards = [ "bcm2711" "bcm2712" ]; # Helpers for building the `pkgs.rpi-kernels' map. rpi-kernel = { version, board }: diff --git a/rpi/default.nix b/rpi/default.nix index 2c05609..6332846 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -18,7 +18,7 @@ in description = "Kernel version to build."; }; board = mkOption { - type = types.str; + type = types.enum [ "bcm2711" "bcm2712" ]; description = '' The kernel board version to build. Examples at: https://www.raspberrypi.com/documentation/computers/linux_kernel.html#native-build-configuration @@ -333,8 +333,8 @@ in }; hardware.enableRedistributableFirmware = true; - users.groups = builtins.listToAttrs (map (k: { name = k; value = {}; }) - ["input" "sudo" "plugdev" "games" "netdev" "gpio" "i2c" "spi"]); + users.groups = builtins.listToAttrs (map (k: { name = k; value = { }; }) + [ "input" "sudo" "plugdev" "games" "netdev" "gpio" "i2c" "spi" ]); services = { udev.extraRules = let shell = "${pkgs.bash}/bin/bash"; From 336a0cf07051e579407da4f246442c08db869738 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Fri, 26 Jul 2024 09:06:18 -0400 Subject: [PATCH 59/97] remove outdated comment --- rpi/default.nix | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/rpi/default.nix b/rpi/default.nix index 6332846..cab1bc6 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -73,19 +73,6 @@ in }; config = { - boot.kernelParams = - if cfg.uboot.enable then [ ] - else [ - # This is ugly and fragile, but the sdImage image has an msdos - # 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" - "rootfstype=ext4" - "fsck.repair=yes" - "rootwait" - "init=/sbin/init" - ]; systemd.services = { "raspberry-pi-firmware-migrate" = { @@ -309,16 +296,28 @@ in else [ rpi-overlay ]; }; boot = { - initrd.availableKernelModules = [ - "usbhid" - "usb_storage" - "vc4" - "pcie_brcmstb" # required for the pcie bus to work - "reset-raspberrypi" # required for vl805 firmware to load - ]; - # This pin is not necessary, it would be fine to replace it with - # `kernel`. It is helpful to ensure - # cache hits for kernel builds though. + kernelParams = + if cfg.uboot.enable then [ ] + else [ + # This is ugly and fragile, but the sdImage image has an msdos + # 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" + "rootfstype=ext4" + "fsck.repair=yes" + "rootwait" + "init=/sbin/init" + ]; + initrd = { + availableKernelModules = [ + "usbhid" + "usb_storage" + "vc4" + "pcie_brcmstb" # required for the pcie bus to work + "reset-raspberrypi" # required for vl805 firmware to load + ]; + }; kernelPackages = pkgs.linuxPackagesFor kernel; loader = { grub.enable = lib.mkDefault false; From 953aca9361ca8b29ccc5bc897fd569f3f28069dd Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Fri, 26 Jul 2024 20:51:21 -0400 Subject: [PATCH 60/97] add flake checks flatten kernel attrset in order to adhere to flake spec --- flake.nix | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index d127311..033984a 100644 --- a/flake.nix +++ b/flake.nix @@ -58,11 +58,23 @@ core-overlay = self.overlays.core; libcamera-overlay = self.overlays.libcamera; }; - packages.aarch64-linux = { - kernels = pinned.rpi-kernels; - firmware = pinned.raspberrypifw; - wireless-firmware = pinned.raspberrypiWirelessFirmware; - uboot-rpi-arm64 = pinned.uboot-rpi-arm64; - }; + checks.aarch64-linux = self.packages.aarch64-linux; + packages.aarch64-linux = with pinned.lib; + let + kernels = + foldlAttrs f { } pinned.rpi-kernels; + f = acc: kernel-version: board-attr-set: + foldlAttrs + (acc: board-version: drv: acc // { + "linux-${kernel-version}-${board-version}" = drv; + }) + acc + board-attr-set; + in + { + firmware = pinned.raspberrypifw; + wireless-firmware = pinned.raspberrypiWirelessFirmware; + uboot-rpi-arm64 = pinned.uboot-rpi-arm64; + } // kernels; }; } From 0dfdbce026642a78243c7e34aaeb9c3a44f53235 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Sat, 27 Jul 2024 10:11:02 -0400 Subject: [PATCH 61/97] add example image to packages and CI --- example/default.nix | 37 +++++++++++++++++++++++++++++++++++++ flake.nix | 7 +++++++ 2 files changed, 44 insertions(+) create mode 100644 example/default.nix diff --git a/example/default.nix b/example/default.nix new file mode 100644 index 0000000..4f8dcb6 --- /dev/null +++ b/example/default.nix @@ -0,0 +1,37 @@ +{ pkgs, lib, ... }: { + time.timeZone = "America/New_York"; + users.users.root.initialPassword = "root"; + networking = { + hostName = "example"; + useDHCP = false; + interfaces = { + wlan0.useDHCP = true; + eth0.useDHCP = true; + }; + }; + raspberry-pi-nix.board = "bcm2711"; + hardware = { + raspberry-pi = { + config = { + all = { + base-dt-params = { + BOOT_UART = { + value = 1; + enable = true; + }; + uart_2ndstage = { + value = 1; + enable = true; + }; + }; + dt-overlays = { + disable-bt = { + enable = true; + params = { }; + }; + }; + }; + }; + }; + }; +} diff --git a/flake.nix b/flake.nix index 033984a..43c3893 100644 --- a/flake.nix +++ b/flake.nix @@ -58,6 +58,12 @@ core-overlay = self.overlays.core; libcamera-overlay = self.overlays.libcamera; }; + nixosConfigurations = { + rpi-example = srcs.nixpkgs.lib.nixosSystem { + system = "aarch64-linux"; + modules = [ self.nixosModules.raspberry-pi ./example ]; + }; + }; checks.aarch64-linux = self.packages.aarch64-linux; packages.aarch64-linux = with pinned.lib; let @@ -72,6 +78,7 @@ board-attr-set; in { + example-sd-image = self.nixosConfigurations.rpi-example.config.system.build.sdImage; firmware = pinned.raspberrypifw; wireless-firmware = pinned.raspberrypiWirelessFirmware; uboot-rpi-arm64 = pinned.uboot-rpi-arm64; From 4ecdee4572eed2c2be13908bc8fbd8a7a8b3d7ec Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Sat, 27 Jul 2024 10:35:45 -0400 Subject: [PATCH 62/97] update readme --- README.md | 107 ++++++++++++++++++++++++++---------------------------- 1 file changed, 51 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 0534b38..f26009e 100644 --- a/README.md +++ b/README.md @@ -19,36 +19,35 @@ and `rpi/config.nix`. The other modules are mostly wrappers that set ## Example -See [the example -repo](https://github.com/tstat/raspberry-pi-nix-example) for a -complete example. +See the `rpi-example` config in this flake for a CI-checked example. ```nix { description = "raspberry-pi-nix example"; - nixConfig = { - extra-substituters = [ "https://raspberry-pi-nix.cachix.org" ]; - extra-trusted-public-keys = [ - "raspberry-pi-nix.cachix.org-1:WmV2rdSangxW0rZjY/tBvBDSaNFQ3DyEQsVw8EvHn9o=" - ]; - }; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11"; - raspberry-pi-nix.url = "github:tstat/raspberry-pi-nix"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; + raspberry-pi-nix.url = "github:nix-community/raspberry-pi-nix"; }; outputs = { self, nixpkgs, raspberry-pi-nix }: let inherit (nixpkgs.lib) nixosSystem; basic-config = { pkgs, lib, ... }: { + # bcm2711 for rpi 3, 3+, 4, zero 2 w + # bcm2712 for rpi 5 + # See the docs at: + # https://www.raspberrypi.com/documentation/computers/linux_kernel.html#native-build-configuration + raspberry-pi-nix.board = "bcm2711"; time.timeZone = "America/New_York"; users.users.root.initialPassword = "root"; networking = { hostName = "basic-example"; useDHCP = false; - interfaces = { wlan0.useDHCP = true; }; + interfaces = { + wlan0.useDHCP = true; + eth0.useDHCP = true; + }; }; - environment.systemPackages = with pkgs; [ bluez bluez-tools ]; hardware = { bluetooth.enable = true; raspberry-pi = { @@ -80,11 +79,11 @@ complete example. ``` ## Using the provided cache to avoid compiling linux -This repo uses the raspberry pi linux kernel fork, and compiling linux -takes a while. I do push my kernel builds to a cachix cache that you -may use to avoid compiling linux yourself. The cache can be found -at https://raspberry-pi-nix.cachix.org, and you can follow the -instructions there to use this cache. +This repo uses the raspberry pi linux kernel fork, and compiling linux takes a +while. CI pushes kernel builds to the nix-community cachix cache that you may +use to avoid compiling linux yourself. The cache can be found at +https://nix-community.cachix.org, and you can follow the instructions there +to use this cache. You don't need the cachix binary to use the cachix cache though, you just need to add the relevant @@ -114,16 +113,15 @@ nix build '.#nixosConfigurations.rpi-example.config.system.build.sdImage' ## The firmware partition -The image produced by this package is partitioned in the same way as -the aarch64 installation media from nixpkgs: There is a firmware -partition that contains necessary firmware, u-boot, and -config.txt. Then there is another partition (labeled `NIXOS_SD`) that -contains everything else. The firmware and `config.txt` file are -managed by NixOS modules defined in this package. Additionally, a -systemd service will update the firmware and `config.txt` in the -firmware partition __in place__. Linux kernels are stored in the -`NIXOS_SD` partition and will be booted by u-boot in the firmware -partition. +The image produced by this package is partitioned in the same way as the aarch64 +installation media from nixpkgs: There is a firmware partition that contains +necessary firmware, the kernel or u-boot, and config.txt. Then there is another +partition (labeled `NIXOS_SD`) that contains everything else. The firmware and +`config.txt` file are managed by NixOS modules defined in this +package. Additionally, a systemd service will update the firmware and +`config.txt` in the firmware partition __in place__. If uboot is enabled then +linux kernels are stored in the `NIXOS_SD` partition and will be booted by +u-boot in the firmware partition. ## `config.txt` generation @@ -258,39 +256,36 @@ nix build '.#nixosConfigurations.rpi-example.config.hardware.raspberry-pi.config ## Firmware partition implementation notes -In Raspberry Pi devices the proprietary firmware manipulates the -device tree in a number of ways before handing it off to the kernel -(or in our case, to u-boot). The transformations that are performed -aren't documented so well (although I have found [this -list](https://forums.raspberrypi.com/viewtopic.php?t=329799#p1974233) -). +In Raspberry Pi devices the proprietary firmware manipulates the device tree in +a number of ways before handing it off to the kernel (or in our case, to +u-boot). The transformations that are performed aren't documented so well +(although I have found [this +list](https://forums.raspberrypi.com/viewtopic.php?t=329799#p1974233) ). -This manipulation makes it difficult to use the device tree configured -directly by NixOS as the proprietary firmware's manipulation must be -known and reproduced. +This manipulation makes it difficult to use the device tree configured directly +by NixOS as the proprietary firmware's manipulation must be known and +reproduced. -Even if the manipulation were successfully reproduced, some benefits -would be lost. For example, the firmware can detect connected hardware -during boot and automatically configure the device tree accordingly -before passing it onto the kernel. If this firmware device tree is -ignored then a NixOS system rebuild with a different device tree would -be required when swapping connected hardware. Examples of what I mean -by hardware include: the specific Raspberry Pi device booting the -image, connected cameras, and connected displays. +Even if the manipulation were successfully reproduced, some benefits would be +lost. For example, the firmware can detect connected hardware during boot and +automatically configure the device tree accordingly before passing it onto the +kernel. If this firmware device tree is ignored then a NixOS system rebuild with +a different device tree would be required when swapping connected +hardware. Examples of what I mean by hardware include: the specific Raspberry Pi +device booting the image, connected cameras, and connected displays. -So, in order to avoid the headaches associated with failing to -reproduce some firmware device tree manipulation, and to reap the -benefits afforded by the firmware device tree configuration, u-boot is -configured to use the device tree that it is given (i.e. the one that -the raspberry pi firmware loads and manipulates). As a consequence, -device tree configuration is controlled via the [config.txt +So, in order to avoid the headaches associated with failing to reproduce some +firmware device tree manipulation, and to reap the benefits afforded by the +firmware device tree configuration, the bootloader is configured to use the +device tree that it is given (i.e. the one that the raspberry pi firmware loads +and manipulates). As a consequence, device tree configuration is controlled via +the [config.txt file](https://www.raspberrypi.com/documentation/computers/config_txt.html). -Additionally, the firmware, device trees, and overlays from the -`raspberrypifw` package populate the firmware partition. This package -is kept up to date by the overlay applied by this package, so you -don't need configure this. However, if you want to use different -firmware you can override that package to do so. +Additionally, the firmware, device trees, and overlays from the `raspberrypifw` +package populate the firmware partition. This package is kept up to date by the +overlay applied by this package, so you don't need configure this. However, if +you want to use different firmware you can override that package to do so. ## What's not working? - [ ] Pi 5 u-boot devices other than sd-cards (i.e. usb, nvme). From 4f3e27caaed189b0dd47cef2d8b4bbd054d9257d Mon Sep 17 00:00:00 2001 From: Yash Garg Date: Mon, 29 Jul 2024 18:41:39 +0530 Subject: [PATCH 63/97] fix: deprecated `lib.cartesianProductofSets` --- overlays/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/overlays/default.nix b/overlays/default.nix index 5de4638..320afa4 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -142,7 +142,7 @@ in # # For example: `pkgs.rpi-kernels.v6_6_31.bcm2712' rpi-kernels = rpi-kernels ( - final.lib.cartesianProductOfSets # this gets renamed yet again to cartesianProduct in April 19 2024 + final.lib.cartesianProduct { board = boards; version = (builtins.attrNames versions); } ); } From 9d173a9416c390e32b947882bc8f404d8c1d83f4 Mon Sep 17 00:00:00 2001 From: Eli Hastings Date: Mon, 29 Jul 2024 14:51:33 +0100 Subject: [PATCH 64/97] Fix libcamera build This backports the `postPatch` change from nixpkgs to the libcamera overlay so the build doesn't break, and also changes the rpicam-apps overlay so it builds properly now. The version in the libcamera overlay has been fixed to match upstream. --- overlays/libcamera.nix | 9 +++++---- overlays/rpicam-apps.nix | 23 +++++++++++++---------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/overlays/libcamera.nix b/overlays/libcamera.nix index ba887cf..57363d0 100644 --- a/overlays/libcamera.nix +++ b/overlays/libcamera.nix @@ -3,8 +3,7 @@ , libpisp-src , ... }: -final: prev: -{ +final: prev: { # A recent known working version of rpicam-apps libcamera-apps = final.callPackage ./rpicam-apps.nix { inherit rpicam-apps-src; }; @@ -22,7 +21,7 @@ final: prev: }; libcamera = prev.libcamera.overrideAttrs (old: { - version = "0.2.0"; + version = "0.3.0"; src = libcamera-src; buildInputs = old.buildInputs ++ (with final; [ libpisp openssl libtiff @@ -30,9 +29,11 @@ final: prev: python3-gnutls pybind11 pyyaml ply ])) libglibutil gst_all_1.gst-plugins-base - ]); patches = [ ]; + postPatch = '' + patchShebangs src/py/ utils/ + ''; mesonFlags = [ "--buildtype=release" "-Dpipelines=rpi/vc4,rpi/pisp" diff --git a/overlays/rpicam-apps.nix b/overlays/rpicam-apps.nix index 85529fb..13e3d2d 100644 --- a/overlays/rpicam-apps.nix +++ b/overlays/rpicam-apps.nix @@ -1,22 +1,25 @@ -{ libcamera-apps-src, lib, pkgs, stdenv }: -stdenv.mkDerivation rec { +{ rpicam-apps-src, lib, pkgs, stdenv }: + +stdenv.mkDerivation { pname = "libcamera-apps"; version = "v1.5.0"; - src = libcamera-apps-src; + src = rpicam-apps-src; nativeBuildInputs = with pkgs; [ meson pkg-config ]; - buildInputs = with pkgs; [ libjpeg libtiff libcamera libepoxy boost libexif libpng ninja ]; + buildInputs = with pkgs; [ libjpeg libtiff libcamera libepoxy boost libexif libpng ffmpeg libdrm ninja ]; mesonFlags = [ - "-Denable_qt=false" - "-Denable_opencv=false" - "-Denable_tflite=false" - "-Denable_drm=true" + "-Denable_qt=disabled" + "-Denable_opencv=disabled" + "-Denable_tflite=disabled" + "-Denable_egl=disabled" + "-Denable_hailo=disabled" + "-Denable_drm=enabled" ]; # Meson is no longer able to pick up Boost automatically. # https://github.com/NixOS/nixpkgs/issues/86131 - BOOST_INCLUDEDIR = "${lib.getDev boost}/include"; - BOOST_LIBRARYDIR = "${lib.getLib boost}/lib"; + BOOST_INCLUDEDIR = "${lib.getDev pkgs.boost}/include"; + BOOST_LIBRARYDIR = "${lib.getLib pkgs.boost}/lib"; meta = with lib; { description = "Userland tools interfacing with Raspberry Pi cameras"; From 7f06ac402f766e151942f89d15dc5ae2c4e83a23 Mon Sep 17 00:00:00 2001 From: Sebastian Sellmeier Date: Sat, 17 Aug 2024 19:34:36 +0200 Subject: [PATCH 65/97] libcamera: add flake-check to binary-cache via buildbot --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index 43c3893..28191a2 100644 --- a/flake.nix +++ b/flake.nix @@ -80,6 +80,7 @@ { example-sd-image = self.nixosConfigurations.rpi-example.config.system.build.sdImage; firmware = pinned.raspberrypifw; + libcamera = pinned.libcamera; wireless-firmware = pinned.raspberrypiWirelessFirmware; uboot-rpi-arm64 = pinned.uboot-rpi-arm64; } // kernels; From 98b74ed7f2bc3e9e005190b86fc4534003543517 Mon Sep 17 00:00:00 2001 From: Sebastian Sellmeier Date: Sat, 17 Aug 2024 19:54:49 +0200 Subject: [PATCH 66/97] uboot: do not reference package if uboot disabled --- rpi/default.nix | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/rpi/default.nix b/rpi/default.nix index cab1bc6..22d1652 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -99,7 +99,6 @@ in TARGET_FIRMWARE_DIR="${firmware-path}" TARGET_OVERLAYS_DIR="$TARGET_FIRMWARE_DIR/overlays" TMPFILE="$TARGET_FIRMWARE_DIR/tmp" - UBOOT="${pkgs.uboot-rpi-arm64}/u-boot.bin" KERNEL="${kernel}/Image" SHOULD_UBOOT=${if cfg.uboot.enable then "1" else "0"} SRC_FIRMWARE_DIR="${pkgs.raspberrypifw}/share/raspberrypi/boot" @@ -111,16 +110,18 @@ in SRC_OVERLAYS=("$SRC_OVERLAYS_DIR"/*) CONFIG="${config.hardware.raspberry-pi.config-output}" - migrate_uboot() { - echo "migrating uboot" - touch "$STATE_DIRECTORY/uboot-migration-in-progress" - cp "$UBOOT" "$TMPFILE" - mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/u-boot-rpi-arm64.bin" - echo "${ - builtins.toString pkgs.uboot-rpi-arm64 - }" > "$STATE_DIRECTORY/uboot-version" - rm "$STATE_DIRECTORY/uboot-migration-in-progress" - } + ${lib.strings.optionalString cfg.uboot.enable '' + UBOOT="${pkgs.uboot-rpi-arm64}/u-boot.bin" + + migrate_uboot() { + echo "migrating uboot" + touch "$STATE_DIRECTORY/uboot-migration-in-progress" + cp "$UBOOT" "$TMPFILE" + mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/u-boot-rpi-arm64.bin" + echo "${builtins.toString pkgs.uboot-rpi-arm64}" " > "$STATE_DIRECTORY/uboot-version" + rm "$STATE_DIRECTORY/uboot-migration-in-progress" + } + ''} migrate_kernel() { echo "migrating kernel" @@ -177,11 +178,13 @@ in rm "$STATE_DIRECTORY/firmware-migration-in-progress" } - if [[ "$SHOULD_UBOOT" -eq 1 ]] && [[ -f "$STATE_DIRECTORY/uboot-migration-in-progress" || ! -f "$STATE_DIRECTORY/uboot-version" || $(< "$STATE_DIRECTORY/uboot-version") != ${ - builtins.toString pkgs.uboot-rpi-arm64 - } ]]; then - migrate_uboot - fi + ${lib.strings.optionalString cfg.uboot.enable '' + if [[ "$SHOULD_UBOOT" -eq 1 ]] && [[ -f "$STATE_DIRECTORY/uboot-migration-in-progress" || ! -f "$STATE_DIRECTORY/uboot-version" || $(< "$STATE_DIRECTORY/uboot-version") != ${ + builtins.toString pkgs.uboot-rpi-arm64 + } ]]; then + migrate_uboot + fi + ''} if [[ "$SHOULD_UBOOT" -ne 1 ]] && [[ ! -f "$STATE_DIRECTORY/kernel-version" || $(< "$STATE_DIRECTORY/kernel-version") != ${ builtins.toString kernel From 9b56cda093c0aa78a2d7db585871ef9118ee383d Mon Sep 17 00:00:00 2001 From: dorkeline <87998193+dorkeline@users.noreply.github.com> Date: Thu, 22 Aug 2024 11:17:24 +0200 Subject: [PATCH 67/97] uboot: add package option --- rpi/default.nix | 7 +++++-- sd-image/default.nix | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/rpi/default.nix b/rpi/default.nix index 22d1652..7116459 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -68,6 +68,8 @@ in cm4 with an nvme drive. ''; }; + + package = mkPackageOption pkgs "uboot-rpi-arm64" {}; }; }; }; @@ -99,6 +101,7 @@ in TARGET_FIRMWARE_DIR="${firmware-path}" TARGET_OVERLAYS_DIR="$TARGET_FIRMWARE_DIR/overlays" TMPFILE="$TARGET_FIRMWARE_DIR/tmp" + UBOOT="${cfg.uboot.package}/u-boot.bin" KERNEL="${kernel}/Image" SHOULD_UBOOT=${if cfg.uboot.enable then "1" else "0"} SRC_FIRMWARE_DIR="${pkgs.raspberrypifw}/share/raspberrypi/boot" @@ -118,7 +121,7 @@ in touch "$STATE_DIRECTORY/uboot-migration-in-progress" cp "$UBOOT" "$TMPFILE" mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/u-boot-rpi-arm64.bin" - echo "${builtins.toString pkgs.uboot-rpi-arm64}" " > "$STATE_DIRECTORY/uboot-version" + echo "${builtins.toString cfg.uboot.package}" " > "$STATE_DIRECTORY/uboot-version" rm "$STATE_DIRECTORY/uboot-migration-in-progress" } ''} @@ -180,7 +183,7 @@ in ${lib.strings.optionalString cfg.uboot.enable '' if [[ "$SHOULD_UBOOT" -eq 1 ]] && [[ -f "$STATE_DIRECTORY/uboot-migration-in-progress" || ! -f "$STATE_DIRECTORY/uboot-version" || $(< "$STATE_DIRECTORY/uboot-version") != ${ - builtins.toString pkgs.uboot-rpi-arm64 + builtins.toString cfg.uboot.package } ]]; then migrate_uboot fi diff --git a/sd-image/default.nix b/sd-image/default.nix index d1dc124..9e9930a 100644 --- a/sd-image/default.nix +++ b/sd-image/default.nix @@ -26,7 +26,7 @@ populate-kernel = if cfg.uboot.enable then '' - cp ${pkgs.uboot-rpi-arm64}/u-boot.bin firmware/u-boot-rpi-arm64.bin + cp ${cfg.uboot.package}/u-boot.bin firmware/u-boot-rpi-arm64.bin '' else '' cp "${kernel}/Image" firmware/kernel.img From 8efedea712b2942004669e02371b483198c0eddb Mon Sep 17 00:00:00 2001 From: dorkeline <87998193+dorkeline@users.noreply.github.com> Date: Fri, 23 Aug 2024 09:28:26 +0200 Subject: [PATCH 68/97] migration: fix stray quote Introduced in a993f0c but likely flew under the radar due to eval caching? --- rpi/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpi/default.nix b/rpi/default.nix index 7116459..873f248 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -121,7 +121,7 @@ in touch "$STATE_DIRECTORY/uboot-migration-in-progress" cp "$UBOOT" "$TMPFILE" mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/u-boot-rpi-arm64.bin" - echo "${builtins.toString cfg.uboot.package}" " > "$STATE_DIRECTORY/uboot-version" + echo "${builtins.toString cfg.uboot.package}" > "$STATE_DIRECTORY/uboot-version" rm "$STATE_DIRECTORY/uboot-migration-in-progress" } ''} From 80df3d197e12d2ba77f67cce09d58773c1f4d7ea Mon Sep 17 00:00:00 2001 From: dorkeline <87998193+dorkeline@users.noreply.github.com> Date: Fri, 23 Aug 2024 10:59:23 +0200 Subject: [PATCH 69/97] uboot: fix a pkgs.uboot use in the migration script i didnt catch --- rpi/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpi/default.nix b/rpi/default.nix index 7116459..955529b 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -114,7 +114,7 @@ in CONFIG="${config.hardware.raspberry-pi.config-output}" ${lib.strings.optionalString cfg.uboot.enable '' - UBOOT="${pkgs.uboot-rpi-arm64}/u-boot.bin" + UBOOT="${cfg.uboot.package}/u-boot.bin" migrate_uboot() { echo "migrating uboot" From 3fbf83622410c1060dbcd988218cabf98dcd53ca Mon Sep 17 00:00:00 2001 From: dorkeline Date: Fri, 23 Aug 2024 20:20:53 +0200 Subject: [PATCH 70/97] uboot: remove mistakenly added line --- rpi/default.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/rpi/default.nix b/rpi/default.nix index 955529b..e1665dc 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -101,7 +101,6 @@ in TARGET_FIRMWARE_DIR="${firmware-path}" TARGET_OVERLAYS_DIR="$TARGET_FIRMWARE_DIR/overlays" TMPFILE="$TARGET_FIRMWARE_DIR/tmp" - UBOOT="${cfg.uboot.package}/u-boot.bin" KERNEL="${kernel}/Image" SHOULD_UBOOT=${if cfg.uboot.enable then "1" else "0"} SRC_FIRMWARE_DIR="${pkgs.raspberrypifw}/share/raspberrypi/boot" From 0ffba0a5bfb541fc4cb3041a33d956ddd71fc512 Mon Sep 17 00:00:00 2001 From: adminy <22717869+adminy@users.noreply.github.com> Date: Tue, 10 Sep 2024 14:35:02 +0100 Subject: [PATCH 71/97] chore: packages version bump --- flake.lock | 74 ++++++++++++++++++++++---------------------- flake.nix | 16 +++++----- overlays/default.nix | 36 ++++----------------- rpi/default.nix | 2 +- 4 files changed, 52 insertions(+), 76 deletions(-) diff --git a/flake.lock b/flake.lock index 9c5513e..335e4c7 100644 --- a/flake.lock +++ b/flake.lock @@ -3,44 +3,44 @@ "libcamera-src": { "flake": false, "locked": { - "lastModified": 1718617480, - "narHash": "sha256-qqEMJzMotybf1nJp1dsz3zc910Qj0TmqCm1CwuSb1VY=", + "lastModified": 1725630279, + "narHash": "sha256-KH30jmHfxXq4j2CL7kv18DYECJRp9ECuWNPnqPZajPA=", "owner": "raspberrypi", "repo": "libcamera", - "rev": "6ddd79b5bdbedc1f61007aed35391f1559f9e29a", + "rev": "69a894c4adad524d3063dd027f5c4774485cf9db", "type": "github" }, "original": { "owner": "raspberrypi", + "ref": "v0.3.1+rpt20240906", "repo": "libcamera", - "rev": "6ddd79b5bdbedc1f61007aed35391f1559f9e29a", "type": "github" } }, "libpisp-src": { "flake": false, "locked": { - "lastModified": 1718613892, - "narHash": "sha256-V/d4RrXoq8HNc8r/Kr1gH3E7YTZzfIdgbaJtq/Xi7uQ=", + "lastModified": 1724944683, + "narHash": "sha256-Fo2UJmQHS855YSSKKmGrsQnJzXog1cdpkIOO72yYAM4=", "owner": "raspberrypi", "repo": "libpisp", - "rev": "b567f04556801ca350331ed21a1ae3eef4675c23", + "rev": "28196ed6edcfeda88d23cc5f213d51aa6fa17bb3", "type": "github" }, "original": { "owner": "raspberrypi", - "ref": "v1.0.6", + "ref": "v1.0.7", "repo": "libpisp", "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1718835956, - "narHash": "sha256-wM9v2yIxClRYsGHut5vHICZTK7xdrUGfrLkXvSuv6s4=", + "lastModified": 1725826545, + "narHash": "sha256-L64N1rpLlXdc94H+F6scnrbuEu+utC03cDDVvvJGOME=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "dd457de7e08c6d06789b1f5b88fc9327f4d96309", + "rev": "f4c846aee8e1e29062aa8514d5e0ab270f4ec2f9", "type": "github" }, "original": { @@ -58,8 +58,8 @@ "rpi-bluez-firmware-src": "rpi-bluez-firmware-src", "rpi-firmware-nonfree-src": "rpi-firmware-nonfree-src", "rpi-firmware-src": "rpi-firmware-src", - "rpi-linux-6_10_0-rc5-src": "rpi-linux-6_10_0-rc5-src", - "rpi-linux-6_6_31-src": "rpi-linux-6_6_31-src", + "rpi-linux-6_10_8-src": "rpi-linux-6_10_8-src", + "rpi-linux-6_6_47-src": "rpi-linux-6_6_47-src", "rpicam-apps-src": "rpicam-apps-src", "u-boot-src": "u-boot-src" } @@ -84,11 +84,11 @@ "rpi-firmware-nonfree-src": { "flake": false, "locked": { - "lastModified": 1708967191, - "narHash": "sha256-BGq0+cr+xBRwQM/LqiQuRWuZpQsKM5jfcrNCqWMuVzM=", + "lastModified": 1723266537, + "narHash": "sha256-T7eTKXqY9cxEMdab8Snda4CEOrEihy5uOhA6Fy+Mhnw=", "owner": "RPi-Distro", "repo": "firmware-nonfree", - "rev": "223ccf3a3ddb11b3ea829749fbbba4d65b380897", + "rev": "4b356e134e8333d073bd3802d767a825adec3807", "type": "github" }, "original": { @@ -101,28 +101,28 @@ "rpi-firmware-src": { "flake": false, "locked": { - "lastModified": 1716978780, - "narHash": "sha256-KsCo7ZG6vKstxRyFljZtbQvnDSqiAPdUza32xTY/tlA=", + "lastModified": 1725277507, + "narHash": "sha256-DN+NlesZ8YfuVwLKQSHckvpNZxqsbKRflOcS3ShO3Ss=", "owner": "raspberrypi", "repo": "firmware", - "rev": "3590de0c181d433af368a95f15bc480bdaff8b47", + "rev": "b5eb52b343e9bc1391a8059a38e12e470c109f5c", "type": "github" }, "original": { "owner": "raspberrypi", - "ref": "1.20240529", + "ref": "1.20240902", "repo": "firmware", "type": "github" } }, - "rpi-linux-6_10_0-rc5-src": { + "rpi-linux-6_10_8-src": { "flake": false, "locked": { - "lastModified": 1719265450, - "narHash": "sha256-xd/Pz/uZFYW9hJIFKryWDE9Aks6f2EIvEDCmfk0C70c=", + "lastModified": 1725639824, + "narHash": "sha256-ogItkH2cBiNGmenJUPAhAH591qufrWh1zeqAJCNAExw=", "owner": "raspberrypi", "repo": "linux", - "rev": "f61d3aca8045e70d64b55f7b98f083738f639ad2", + "rev": "0c0217e02da43439fb08b2f6b09530723331ed15", "type": "github" }, "original": { @@ -132,19 +132,19 @@ "type": "github" } }, - "rpi-linux-6_6_31-src": { + "rpi-linux-6_6_47-src": { "flake": false, "locked": { - "lastModified": 1716545726, - "narHash": "sha256-UWUTeCpEN7dlFSQjog6S3HyEWCCnaqiUqV5KxCjYink=", + "lastModified": 1725956269, + "narHash": "sha256-zn1Totn8NU8MCJmWRGsdarNeSo8rzscrBnhdRVMBuT0=", "owner": "raspberrypi", "repo": "linux", - "rev": "c1432b4bae5b6582f4d32ba381459f33c34d1424", + "rev": "cc50cdbcf3e8f065bd7798a92689f54578b4169f", "type": "github" }, "original": { "owner": "raspberrypi", - "ref": "stable_20240529", + "ref": "rpi-6.6.y", "repo": "linux", "type": "github" } @@ -152,16 +152,16 @@ "rpicam-apps-src": { "flake": false, "locked": { - "lastModified": 1717081637, - "narHash": "sha256-s4zJh6r3VhiquO54KWZ78dVCH1BmlphY9zEB9BidNyo=", + "lastModified": 1725543038, + "narHash": "sha256-rl5GVigiZWXkpfIteRWUMjtCaPweXRWrBrZOjQ1hiU8=", "owner": "raspberrypi", "repo": "rpicam-apps", - "rev": "49344f2a8d1817558d4e6463032fcf11be618b38", + "rev": "d7a1a13b041ef2842cd56d7e395b8c9a0ffc3bf5", "type": "github" }, "original": { "owner": "raspberrypi", - "ref": "v1.5.0", + "ref": "v1.5.1", "repo": "rpicam-apps", "type": "github" } @@ -169,14 +169,14 @@ "u-boot-src": { "flake": false, "locked": { - "lastModified": 1712055538, - "narHash": "sha256-IlaDdjKq/Pq2orzcU959h93WXRZfvKBGDO/MFw9mZMg=", + "lastModified": 1719857238, + "narHash": "sha256-mJ2TBy0Y5ZtcGFgtU5RKr0UDUp5FWzojbFb+o/ebRJU=", "type": "tarball", - "url": "https://ftp.denx.de/pub/u-boot/u-boot-2024.04.tar.bz2" + "url": "https://ftp.denx.de/pub/u-boot/u-boot-2024.07.tar.bz2" }, "original": { "type": "tarball", - "url": "https://ftp.denx.de/pub/u-boot/u-boot-2024.04.tar.bz2" + "url": "https://ftp.denx.de/pub/u-boot/u-boot-2024.07.tar.bz2" } } }, diff --git a/flake.nix b/flake.nix index 28191a2..d4e9793 100644 --- a/flake.nix +++ b/flake.nix @@ -5,19 +5,19 @@ nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; u-boot-src = { flake = false; - url = "https://ftp.denx.de/pub/u-boot/u-boot-2024.04.tar.bz2"; + url = "https://ftp.denx.de/pub/u-boot/u-boot-2024.07.tar.bz2"; }; - rpi-linux-6_6_31-src = { + rpi-linux-6_6_47-src = { flake = false; - url = "github:raspberrypi/linux/stable_20240529"; + url = "github:raspberrypi/linux/rpi-6.6.y"; }; - rpi-linux-6_10_0-rc5-src = { + rpi-linux-6_10_8-src = { flake = false; url = "github:raspberrypi/linux/rpi-6.10.y"; }; rpi-firmware-src = { flake = false; - url = "github:raspberrypi/firmware/1.20240529"; + url = "github:raspberrypi/firmware/1.20240902"; }; rpi-firmware-nonfree-src = { flake = false; @@ -29,15 +29,15 @@ }; rpicam-apps-src = { flake = false; - url = "github:raspberrypi/rpicam-apps/v1.5.0"; + url = "github:raspberrypi/rpicam-apps/v1.5.1"; }; libcamera-src = { flake = false; - url = "github:raspberrypi/libcamera/6ddd79b5bdbedc1f61007aed35391f1559f9e29a"; # v0.3.0+rpt20240617 + url = "github:raspberrypi/libcamera/v0.3.1+rpt20240906"; }; libpisp-src = { flake = false; - url = "github:raspberrypi/libpisp/v1.0.6"; + url = "github:raspberrypi/libpisp/v1.0.7"; }; }; diff --git a/overlays/default.nix b/overlays/default.nix index 320afa4..fa7c343 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,6 +1,6 @@ { u-boot-src -, rpi-linux-6_6_31-src -, rpi-linux-6_10_0-rc5-src +, rpi-linux-6_6_47-src +, rpi-linux-6_10_8-src , rpi-firmware-src , rpi-firmware-nonfree-src , rpi-bluez-firmware-src @@ -9,29 +9,9 @@ final: prev: let versions = { - v6_6_31 = { - src = rpi-linux-6_6_31-src; - patches = [ - # Fix compilation errors due to incomplete patch backport. - # https://github.com/raspberrypi/linux/pull/6223 - { - name = "gpio-pwm_-_pwm_apply_might_sleep.patch"; - patch = final.fetchpatch { - url = "https://github.com/peat-psuwit/rpi-linux/commit/879f34b88c60dd59765caa30576cb5bfb8e73c56.patch"; - hash = "sha256-HlOkM9EFmlzOebCGoj7lNV5hc0wMjhaBFFZvaRCI0lI="; - }; - } - { - name = "ir-rx51_-_pwm_apply_might_sleep.patch"; - patch = final.fetchpatch { - url = "https://github.com/peat-psuwit/rpi-linux/commit/23431052d2dce8084b72e399fce82b05d86b847f.patch"; - hash = "sha256-UDX/BJCJG0WVndP/6PbPK+AZsfU3vVxDCrpn1kb1kqE="; - }; - } - ]; - }; - v6_10_0-rc5 = { - src = rpi-linux-6_10_0-rc5-src; + v6_6_47.src = rpi-linux-6_6_47-src; + v6_10_8 = { + src = rpi-linux-6_10_8-src; patches = [ { name = "remove-readme-target.patch"; @@ -59,10 +39,6 @@ let src = kernel.src; defconfig = "${board}_defconfig"; structuredExtraConfig = with final.lib.kernel; { - # Workaround https://github.com/raspberrypi/linux/issues/6198 - # Needed because NixOS 24.05+ sets DRM_SIMPLEDRM=y which pulls in - # DRM_KMS_HELPER=y. - BACKLIGHT_CLASS_DEVICE = yes; # The perl script to generate kernel options sets unspecified # parameters to `m` if possible [1]. This results in the # unspecified config option KUNIT [2] getting set to `m` which @@ -140,7 +116,7 @@ in # rpi kernels and firmware are available at # `pkgs.rpi-kernels..'. # - # For example: `pkgs.rpi-kernels.v6_6_31.bcm2712' + # For example: `pkgs.rpi-kernels.v6_6_47.bcm2712' rpi-kernels = rpi-kernels ( final.lib.cartesianProduct { board = boards; version = (builtins.attrNames versions); } diff --git a/rpi/default.nix b/rpi/default.nix index c67e131..a96d937 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -13,7 +13,7 @@ in options = with lib; { raspberry-pi-nix = { kernel-version = mkOption { - default = "v6_6_31"; + default = "v6_6_47"; type = types.str; description = "Kernel version to build."; }; From 5e9607fa18b5c27dcca0a605aef92385ac57a51a Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Thu, 12 Sep 2024 16:39:16 -0400 Subject: [PATCH 72/97] fixes #63: don't use tag with + in it --- flake.lock | 2 +- flake.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.lock b/flake.lock index 335e4c7..ecfd034 100644 --- a/flake.lock +++ b/flake.lock @@ -12,8 +12,8 @@ }, "original": { "owner": "raspberrypi", - "ref": "v0.3.1+rpt20240906", "repo": "libcamera", + "rev": "69a894c4adad524d3063dd027f5c4774485cf9db", "type": "github" } }, diff --git a/flake.nix b/flake.nix index d4e9793..7359791 100644 --- a/flake.nix +++ b/flake.nix @@ -33,7 +33,7 @@ }; libcamera-src = { flake = false; - url = "github:raspberrypi/libcamera/v0.3.1+rpt20240906"; + url = "github:raspberrypi/libcamera/69a894c4adad524d3063dd027f5c4774485cf9db"; # v0.3.1+rpt20240906 }; libpisp-src = { flake = false; From 90ff6a72a9f2e287c6890fbf6cbe60fde5115844 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Thu, 19 Sep 2024 19:36:24 -0400 Subject: [PATCH 73/97] remove somewhat off-topic details about setting up a substituter --- README.md | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/README.md b/README.md index f26009e..91ca157 100644 --- a/README.md +++ b/README.md @@ -85,21 +85,6 @@ use to avoid compiling linux yourself. The cache can be found at https://nix-community.cachix.org, and you can follow the instructions there to use this cache. -You don't need the cachix binary to use the cachix cache though, you -just need to add the relevant -[`substituters`](https://nixos.org/manual/nix/stable/command-ref/conf-file.html?highlight=nix.conf#conf-substituters) -and -[`trusted-public-keys`](https://nixos.org/manual/nix/stable/command-ref/conf-file.html?highlight=nix.conf#conf-trusted-public-keys) -settings settings to your `nix.conf`. You can do this directly by -modifying your `/etc/nix/nix.conf`, or in the flake definition. In the -above example flake these `nix.conf` settings are added by the -`nixConfig` attribute ([doc -link](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html?highlight=flake#flake-format)). -Note that this will only work if the user running `nix build` is in -[`trusted-users`](https://nixos.org/manual/nix/stable/command-ref/conf-file.html?highlight=nix.conf#conf-trusted-users) -or the substituter is in -[`trusted-substituters`](https://nixos.org/manual/nix/stable/command-ref/conf-file.html?highlight=nix.conf#conf-trusted-substituters). - ## Building an sd-card image An image suitable for flashing to an sd-card can be found at the From 81707d7230d5151650220800515b1ff01a4c4959 Mon Sep 17 00:00:00 2001 From: Sebastian Sellmeier Date: Fri, 20 Sep 2024 13:52:24 +0200 Subject: [PATCH 74/97] example: add pipewire --- example/default.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/example/default.nix b/example/default.nix index 4f8dcb6..31e787f 100644 --- a/example/default.nix +++ b/example/default.nix @@ -34,4 +34,11 @@ }; }; }; + security.rtkit.enable = true; + services.pipewire = { + enable = true; + alsa.enable = true; + alsa.support32Bit = true; + pulse.enable = true; + }; } From 4501cff5298c20c75cb3a4f0815bd9b265d372ce Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 7 Oct 2024 17:11:55 -0400 Subject: [PATCH 75/97] bump deps --- flake.lock | 42 +++++++++++++++++++++--------------------- flake.nix | 8 ++++---- overlays/default.nix | 12 ++++++------ overlays/libcamera.nix | 16 +++++++++++----- rpi/default.nix | 4 ++-- 5 files changed, 44 insertions(+), 38 deletions(-) diff --git a/flake.lock b/flake.lock index ecfd034..abb934b 100644 --- a/flake.lock +++ b/flake.lock @@ -36,11 +36,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1725826545, - "narHash": "sha256-L64N1rpLlXdc94H+F6scnrbuEu+utC03cDDVvvJGOME=", + "lastModified": 1728193676, + "narHash": "sha256-PbDWAIjKJdlVg+qQRhzdSor04bAPApDqIv2DofTyynk=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "f4c846aee8e1e29062aa8514d5e0ab270f4ec2f9", + "rev": "ecbc1ca8ffd6aea8372ad16be9ebbb39889e55b6", "type": "github" }, "original": { @@ -58,8 +58,8 @@ "rpi-bluez-firmware-src": "rpi-bluez-firmware-src", "rpi-firmware-nonfree-src": "rpi-firmware-nonfree-src", "rpi-firmware-src": "rpi-firmware-src", - "rpi-linux-6_10_8-src": "rpi-linux-6_10_8-src", - "rpi-linux-6_6_47-src": "rpi-linux-6_6_47-src", + "rpi-linux-6_10_12-src": "rpi-linux-6_10_12-src", + "rpi-linux-6_6_54-src": "rpi-linux-6_6_54-src", "rpicam-apps-src": "rpicam-apps-src", "u-boot-src": "u-boot-src" } @@ -101,28 +101,28 @@ "rpi-firmware-src": { "flake": false, "locked": { - "lastModified": 1725277507, - "narHash": "sha256-DN+NlesZ8YfuVwLKQSHckvpNZxqsbKRflOcS3ShO3Ss=", + "lastModified": 1727798811, + "narHash": "sha256-eavbshXGYmkYR33y9FLcQMJoAYdYTESVEy0g/RRXnb0=", "owner": "raspberrypi", "repo": "firmware", - "rev": "b5eb52b343e9bc1391a8059a38e12e470c109f5c", + "rev": "287e6a6c2d3b50eee3e2c5b2eacdd907e5cbe09a", "type": "github" }, "original": { "owner": "raspberrypi", - "ref": "1.20240902", + "ref": "1.20241001", "repo": "firmware", "type": "github" } }, - "rpi-linux-6_10_8-src": { + "rpi-linux-6_10_12-src": { "flake": false, "locked": { - "lastModified": 1725639824, - "narHash": "sha256-ogItkH2cBiNGmenJUPAhAH591qufrWh1zeqAJCNAExw=", + "lastModified": 1728305462, + "narHash": "sha256-LtvNmGD1D5YYv+C9xxxddAeHw69o3OX/H9M7F663L74=", "owner": "raspberrypi", "repo": "linux", - "rev": "0c0217e02da43439fb08b2f6b09530723331ed15", + "rev": "26ee50d56618c2d98100b1bc672fd201aed4d00f", "type": "github" }, "original": { @@ -132,14 +132,14 @@ "type": "github" } }, - "rpi-linux-6_6_47-src": { + "rpi-linux-6_6_54-src": { "flake": false, "locked": { - "lastModified": 1725956269, - "narHash": "sha256-zn1Totn8NU8MCJmWRGsdarNeSo8rzscrBnhdRVMBuT0=", + "lastModified": 1728155174, + "narHash": "sha256-/8RjW35XQMnshjAE4Ey8j3oWzE2GOntnBYY6PlvZGhs=", "owner": "raspberrypi", "repo": "linux", - "rev": "cc50cdbcf3e8f065bd7798a92689f54578b4169f", + "rev": "12f0f28db3afe451a81a34c5a444f6841c10067c", "type": "github" }, "original": { @@ -152,16 +152,16 @@ "rpicam-apps-src": { "flake": false, "locked": { - "lastModified": 1725543038, - "narHash": "sha256-rl5GVigiZWXkpfIteRWUMjtCaPweXRWrBrZOjQ1hiU8=", + "lastModified": 1727515047, + "narHash": "sha256-qCYGrcibOeGztxf+sd44lD6VAOGoUNwRqZDdAmcTa/U=", "owner": "raspberrypi", "repo": "rpicam-apps", - "rev": "d7a1a13b041ef2842cd56d7e395b8c9a0ffc3bf5", + "rev": "a8ccf9f3cd9df49875dfb834a2b490d41d226031", "type": "github" }, "original": { "owner": "raspberrypi", - "ref": "v1.5.1", + "ref": "v1.5.2", "repo": "rpicam-apps", "type": "github" } diff --git a/flake.nix b/flake.nix index 7359791..ed8be8e 100644 --- a/flake.nix +++ b/flake.nix @@ -7,17 +7,17 @@ flake = false; url = "https://ftp.denx.de/pub/u-boot/u-boot-2024.07.tar.bz2"; }; - rpi-linux-6_6_47-src = { + rpi-linux-6_6_54-src = { flake = false; url = "github:raspberrypi/linux/rpi-6.6.y"; }; - rpi-linux-6_10_8-src = { + rpi-linux-6_10_12-src = { flake = false; url = "github:raspberrypi/linux/rpi-6.10.y"; }; rpi-firmware-src = { flake = false; - url = "github:raspberrypi/firmware/1.20240902"; + url = "github:raspberrypi/firmware/1.20241001"; }; rpi-firmware-nonfree-src = { flake = false; @@ -29,7 +29,7 @@ }; rpicam-apps-src = { flake = false; - url = "github:raspberrypi/rpicam-apps/v1.5.1"; + url = "github:raspberrypi/rpicam-apps/v1.5.2"; }; libcamera-src = { flake = false; diff --git a/overlays/default.nix b/overlays/default.nix index fa7c343..162330c 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,6 +1,6 @@ { u-boot-src -, rpi-linux-6_6_47-src -, rpi-linux-6_10_8-src +, rpi-linux-6_6_54-src +, rpi-linux-6_10_12-src , rpi-firmware-src , rpi-firmware-nonfree-src , rpi-bluez-firmware-src @@ -9,9 +9,9 @@ final: prev: let versions = { - v6_6_47.src = rpi-linux-6_6_47-src; - v6_10_8 = { - src = rpi-linux-6_10_8-src; + v6_6_54.src = rpi-linux-6_6_54-src; + v6_10_12 = { + src = rpi-linux-6_10_12-src; patches = [ { name = "remove-readme-target.patch"; @@ -116,7 +116,7 @@ in # rpi kernels and firmware are available at # `pkgs.rpi-kernels..'. # - # For example: `pkgs.rpi-kernels.v6_6_47.bcm2712' + # For example: `pkgs.rpi-kernels.v6_6_54.bcm2712' rpi-kernels = rpi-kernels ( final.lib.cartesianProduct { board = boards; version = (builtins.attrNames versions); } diff --git a/overlays/libcamera.nix b/overlays/libcamera.nix index 57363d0..878fb28 100644 --- a/overlays/libcamera.nix +++ b/overlays/libcamera.nix @@ -10,7 +10,7 @@ final: prev: { libpisp = final.stdenv.mkDerivation { name = "libpisp"; - version = "1.0.6"; + version = "1.0.7"; src = libpisp-src; nativeBuildInputs = with final; [ pkg-config meson ninja ]; buildInputs = with final; [ nlohmann_json boost ]; @@ -21,14 +21,20 @@ final: prev: { }; libcamera = prev.libcamera.overrideAttrs (old: { - version = "0.3.0"; + version = "0.3.1"; src = libcamera-src; buildInputs = old.buildInputs ++ (with final; [ - libpisp openssl libtiff + libpisp + openssl + libtiff (python3.withPackages (ps: with ps; [ - python3-gnutls pybind11 pyyaml ply + python3-gnutls + pybind11 + pyyaml + ply ])) - libglibutil gst_all_1.gst-plugins-base + libglibutil + gst_all_1.gst-plugins-base ]); patches = [ ]; postPatch = '' diff --git a/rpi/default.nix b/rpi/default.nix index a96d937..02b582a 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -13,7 +13,7 @@ in options = with lib; { raspberry-pi-nix = { kernel-version = mkOption { - default = "v6_6_47"; + default = "v6_6_54"; type = types.str; description = "Kernel version to build."; }; @@ -69,7 +69,7 @@ in ''; }; - package = mkPackageOption pkgs "uboot-rpi-arm64" {}; + package = mkPackageOption pkgs "uboot-rpi-arm64" { }; }; }; }; From 50a273f172d275e9feb4e9cb6295ea6bfeda9a18 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Sat, 19 Oct 2024 16:07:01 +0100 Subject: [PATCH 76/97] allow empty base dtparams --- rpi/config.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpi/config.nix b/rpi/config.nix index 125cb13..f48ba60 100644 --- a/rpi/config.nix +++ b/rpi/config.nix @@ -93,7 +93,7 @@ in }; }; base-dt-params = lib.mkOption { - type = with lib.types; attrsOf (submodule rpi-config-param); + type = with lib.types; attrsOf (submodule dt-param); default = { }; example = { i2c = { From d039a262cecc42897c4d8b3014e83cadbd9c46e3 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Thu, 3 Oct 2024 18:39:26 -0400 Subject: [PATCH 77/97] disable sd-image --- flake.nix | 13 ++++++++----- rpi/default.nix | 8 ++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/flake.nix b/flake.nix index ed8be8e..c0acdc3 100644 --- a/flake.nix +++ b/flake.nix @@ -53,15 +53,18 @@ core = import ./overlays (builtins.removeAttrs srcs [ "self" ]); libcamera = import ./overlays/libcamera.nix (builtins.removeAttrs srcs [ "self" ]); }; - nixosModules.raspberry-pi = import ./rpi { - inherit pinned; - core-overlay = self.overlays.core; - libcamera-overlay = self.overlays.libcamera; + nixosModules = { + raspberry-pi = import ./rpi { + inherit pinned; + core-overlay = self.overlays.core; + libcamera-overlay = self.overlays.libcamera; + }; + sd-image = import ./sd-image; }; nixosConfigurations = { rpi-example = srcs.nixpkgs.lib.nixosSystem { system = "aarch64-linux"; - modules = [ self.nixosModules.raspberry-pi ./example ]; + modules = [ self.nixosModules.raspberry-pi self.nixosModules.sd-image ./example ]; }; }; checks.aarch64-linux = self.packages.aarch64-linux; diff --git a/rpi/default.nix b/rpi/default.nix index 02b582a..57b93a1 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -8,7 +8,7 @@ let kernel = pkgs.rpi-kernels."${version}"."${board}"; in { - imports = [ ../sd-image ./config.nix ./i2c.nix ]; + imports = [ ./config.nix ./i2c.nix ]; options = with lib; { raspberry-pi-nix = { @@ -93,7 +93,7 @@ in { Type = "oneshot"; MountImages = - "/dev/disk/by-label/${config.sdImage.firmwarePartitionName}:${firmware-path}"; + "/dev/disk/by-label/FIRMWARE:${firmware-path}"; StateDirectory = "raspberrypi-firmware"; ExecStart = pkgs.writeShellScript "migrate-rpi-firmware" '' shopt -s nullglob @@ -308,8 +308,8 @@ in # 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" - "rootfstype=ext4" + # "root=PARTUUID=${lib.strings.removePrefix "0x" config.sdImage.firmwarePartitionID}-02" + # "rootfstype=ext4" "fsck.repair=yes" "rootwait" "init=/sbin/init" From ee53143215d82acfe159009b5745795828fddb5b Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Sun, 3 Nov 2024 12:06:15 -0500 Subject: [PATCH 78/97] add initrd --- rpi/default.nix | 11 +++++++++++ sd-image/default.nix | 2 ++ 2 files changed, 13 insertions(+) diff --git a/rpi/default.nix b/rpi/default.nix index 57b93a1..8a15a9b 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -6,6 +6,7 @@ let version = cfg.kernel-version; board = cfg.board; kernel = pkgs.rpi-kernels."${version}"."${board}"; + initrd = "${config.system.build.initialRamdisk}/${config.system.boot.loader.initrdFile}"; in { imports = [ ./config.nix ./i2c.nix ]; @@ -130,6 +131,8 @@ in touch "$STATE_DIRECTORY/kernel-migration-in-progress" cp "$KERNEL" "$TMPFILE" mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/kernel.img" + cp "${initrd}" "$TMPFILE" + mv -T "$TMPFILE" "$TARGET_FIRMWARE_DIR/initrd" echo "${ builtins.toString kernel }" > "$STATE_DIRECTORY/kernel-version" @@ -243,6 +246,14 @@ in enable = true; value = if cfg.uboot.enable then "u-boot-rpi-arm64.bin" else "kernel.img"; }; + ramfsfile = { + enable = !cfg.uboot.enable; + value = "initrd"; + }; + ramfsaddr = { + enable = !cfg.uboot.enable; + value = -1; + }; arm_64bit = { enable = true; value = true; diff --git a/sd-image/default.nix b/sd-image/default.nix index 9e9930a..fb9c684 100644 --- a/sd-image/default.nix +++ b/sd-image/default.nix @@ -23,6 +23,7 @@ version = cfg.kernel-version; board = cfg.board; kernel = pkgs.rpi-kernels."${version}"."${board}"; + initrd = "${config.system.build.initialRamdisk}/${config.system.boot.loader.initrdFile}"; populate-kernel = if cfg.uboot.enable then '' @@ -30,6 +31,7 @@ '' else '' cp "${kernel}/Image" firmware/kernel.img + cp "${initrd}" firmware/initrd cp "${kernel-params}" firmware/cmdline.txt ''; in From f872d7748f503af66ed577aaf9b621c69235f40c Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Sun, 3 Nov 2024 20:20:01 -0500 Subject: [PATCH 79/97] shuffle kernel params --- rpi/default.nix | 10 ++-------- sd-image/default.nix | 11 ++++++++++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/rpi/default.nix b/rpi/default.nix index 8a15a9b..3d9bb64 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -315,14 +315,8 @@ in kernelParams = if cfg.uboot.enable then [ ] else [ - # This is ugly and fragile, but the sdImage image has an msdos - # 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" - # "rootfstype=ext4" - "fsck.repair=yes" - "rootwait" + "console=tty1" + "console=serial0,115200n8" "init=/sbin/init" ]; initrd = { diff --git a/sd-image/default.nix b/sd-image/default.nix index fb9c684..a9b3f68 100644 --- a/sd-image/default.nix +++ b/sd-image/default.nix @@ -9,7 +9,16 @@ boot.consoleLogLevel = lib.mkDefault 7; # https://github.com/raspberrypi/firmware/issues/1539#issuecomment-784498108 - boot.kernelParams = [ "console=serial0,115200n8" "console=tty1" ]; + boot.kernelParams = [ + # This is ugly and fragile, but the sdImage image has an msdos + # 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" + "rootfstype=ext4" + "fsck.repair=yes" + "rootwait" + ]; sdImage = let From ecc8ca530d788c49b79de8a9e1bb665626d1b89b Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 4 Nov 2024 22:43:44 -0500 Subject: [PATCH 80/97] only mention rpi-kernels when overriding kernel so that migrations / sd-image building work if there are additional kernel overrides --- rpi/default.nix | 4 ++-- sd-image/default.nix | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rpi/default.nix b/rpi/default.nix index 02b582a..c5a9d49 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -5,7 +5,7 @@ let cfg = config.raspberry-pi-nix; version = cfg.kernel-version; board = cfg.board; - kernel = pkgs.rpi-kernels."${version}"."${board}"; + kernel = config.system.build.kernel; in { imports = [ ../sd-image ./config.nix ./i2c.nix ]; @@ -323,7 +323,7 @@ in "reset-raspberrypi" # required for vl805 firmware to load ]; }; - kernelPackages = pkgs.linuxPackagesFor kernel; + kernelPackages = pkgs.linuxPackagesFor pkgs.rpi-kernels."${version}"."${board}"; loader = { grub.enable = lib.mkDefault false; initScript.enable = !cfg.uboot.enable; diff --git a/sd-image/default.nix b/sd-image/default.nix index 9e9930a..212634d 100644 --- a/sd-image/default.nix +++ b/sd-image/default.nix @@ -22,7 +22,7 @@ cfg = config.raspberry-pi-nix; version = cfg.kernel-version; board = cfg.board; - kernel = pkgs.rpi-kernels."${version}"."${board}"; + kernel = config.system.build.kernel; populate-kernel = if cfg.uboot.enable then '' From 61d43e92fd7530d0162d9125a6cb9f27b4e1e32c Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 4 Nov 2024 22:57:26 -0500 Subject: [PATCH 81/97] use config.system.boot.loader.kernelFile --- rpi/default.nix | 2 +- sd-image/default.nix | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rpi/default.nix b/rpi/default.nix index c6d73ce..339d3f0 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -102,7 +102,7 @@ in TARGET_FIRMWARE_DIR="${firmware-path}" TARGET_OVERLAYS_DIR="$TARGET_FIRMWARE_DIR/overlays" TMPFILE="$TARGET_FIRMWARE_DIR/tmp" - KERNEL="${kernel}/Image" + KERNEL="${kernel}/${config.system.boot.loader.kernelFile}" SHOULD_UBOOT=${if cfg.uboot.enable then "1" else "0"} SRC_FIRMWARE_DIR="${pkgs.raspberrypifw}/share/raspberrypi/boot" STARTFILES=("$SRC_FIRMWARE_DIR"/start*.elf) diff --git a/sd-image/default.nix b/sd-image/default.nix index 99a1be4..931fb29 100644 --- a/sd-image/default.nix +++ b/sd-image/default.nix @@ -31,7 +31,7 @@ cfg = config.raspberry-pi-nix; version = cfg.kernel-version; board = cfg.board; - kernel = config.system.build.kernel; + 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 @@ -39,7 +39,7 @@ cp ${cfg.uboot.package}/u-boot.bin firmware/u-boot-rpi-arm64.bin '' else '' - cp "${kernel}/Image" firmware/kernel.img + cp "${kernel}" firmware/kernel.img cp "${initrd}" firmware/initrd cp "${kernel-params}" firmware/cmdline.txt ''; From beb01f006a795fa1c3d46ca2a7a3dd199d919b0b Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 11 Nov 2024 11:36:56 -0500 Subject: [PATCH 82/97] add firmware-partition-label option --- rpi/default.nix | 7 ++++++- sd-image/sd-image.nix | 18 ++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/rpi/default.nix b/rpi/default.nix index 339d3f0..70d9509 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -26,6 +26,11 @@ in without the _defconfig part. ''; }; + firmware-partition-label = mkOption { + default = "FIRMWARE"; + type = types.str; + description = "label of rpi firmware partition"; + }; pin-inputs = { enable = mkOption { default = true; @@ -94,7 +99,7 @@ in { Type = "oneshot"; MountImages = - "/dev/disk/by-label/FIRMWARE:${firmware-path}"; + "/dev/disk/by-label/${cfg.firmware-partition-label}:${firmware-path}"; StateDirectory = "raspberrypi-firmware"; ExecStart = pkgs.writeShellScript "migrate-rpi-firmware" '' shopt -s nullglob diff --git a/sd-image/sd-image.nix b/sd-image/sd-image.nix index 9ca69d8..60eedfc 100644 --- a/sd-image/sd-image.nix +++ b/sd-image/sd-image.nix @@ -30,7 +30,8 @@ let } // optionalAttrs (config.sdImage.rootPartitionUUID != null) { uuid = config.sdImage.rootPartitionUUID; }); -in { +in +{ imports = [ ]; options.sdImage = { @@ -82,14 +83,6 @@ in { ''; }; - firmwarePartitionName = mkOption { - type = types.str; - default = "FIRMWARE"; - description = '' - Name of the filesystem which holds the boot firmware. - ''; - }; - rootPartitionUUID = mkOption { type = types.nullOr types.str; default = null; @@ -160,7 +153,7 @@ in { config = { fileSystems = { "/boot/firmware" = { - device = "/dev/disk/by-label/${config.sdImage.firmwarePartitionName}"; + device = "/dev/disk/by-label/${config.raspberry-pi-nix.firmware-partition-label}"; fsType = "vfat"; }; "/" = { @@ -226,7 +219,7 @@ 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 + 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 @@ -244,7 +237,8 @@ in { zstd -T$NIX_BUILD_CORES --rm $img fi ''; - }) { }; + }) + { }; boot.postBootCommands = lib.mkIf config.sdImage.expandOnBoot '' # On the first boot do some maintenance tasks From b7c3578710785c93c7d9e714bb1c8dd2421875bb Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Tue, 12 Nov 2024 12:31:36 -0500 Subject: [PATCH 83/97] move comment --- rpi/default.nix | 1 + sd-image/default.nix | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/rpi/default.nix b/rpi/default.nix index 70d9509..5900692 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -321,6 +321,7 @@ in if cfg.uboot.enable then [ ] else [ "console=tty1" + # https://github.com/raspberrypi/firmware/issues/1539#issuecomment-784498108 "console=serial0,115200n8" "init=/sbin/init" ]; diff --git a/sd-image/default.nix b/sd-image/default.nix index 931fb29..b845de3 100644 --- a/sd-image/default.nix +++ b/sd-image/default.nix @@ -8,7 +8,6 @@ boot.consoleLogLevel = lib.mkDefault 7; - # https://github.com/raspberrypi/firmware/issues/1539#issuecomment-784498108 boot.kernelParams = [ # This is ugly and fragile, but the sdImage image has an msdos # table, so the partition table id is a 1-indexed hex From 848c5add7f5c4ad0792c86d9db620c6aa4abc30e Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Tue, 12 Nov 2024 12:36:49 -0500 Subject: [PATCH 84/97] readme tweaks --- README.md | 67 +++++-------------------------------------------------- 1 file changed, 5 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 91ca157..4c7882e 100644 --- a/README.md +++ b/README.md @@ -19,64 +19,7 @@ and `rpi/config.nix`. The other modules are mostly wrappers that set ## Example -See the `rpi-example` config in this flake for a CI-checked example. - -```nix -{ - description = "raspberry-pi-nix example"; - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; - raspberry-pi-nix.url = "github:nix-community/raspberry-pi-nix"; - }; - - outputs = { self, nixpkgs, raspberry-pi-nix }: - let - inherit (nixpkgs.lib) nixosSystem; - basic-config = { pkgs, lib, ... }: { - # bcm2711 for rpi 3, 3+, 4, zero 2 w - # bcm2712 for rpi 5 - # See the docs at: - # https://www.raspberrypi.com/documentation/computers/linux_kernel.html#native-build-configuration - raspberry-pi-nix.board = "bcm2711"; - time.timeZone = "America/New_York"; - users.users.root.initialPassword = "root"; - networking = { - hostName = "basic-example"; - useDHCP = false; - interfaces = { - wlan0.useDHCP = true; - eth0.useDHCP = true; - }; - }; - hardware = { - bluetooth.enable = true; - raspberry-pi = { - config = { - all = { - base-dt-params = { - # enable autoprobing of bluetooth driver - # https://github.com/raspberrypi/linux/blob/c8c99191e1419062ac8b668956d19e788865912a/arch/arm/boot/dts/overlays/README#L222-L224 - krnbt = { - enable = true; - value = "on"; - }; - }; - }; - }; - }; - }; - }; - - in { - nixosConfigurations = { - rpi-example = nixosSystem { - system = "aarch64-linux"; - modules = [ raspberry-pi-nix.nixosModules.raspberry-pi basic-config ]; - }; - }; - }; -} -``` +See the `rpi-example` config in this flake for an example config built by CI. ## Using the provided cache to avoid compiling linux This repo uses the raspberry pi linux kernel fork, and compiling linux takes a @@ -87,10 +30,10 @@ to use this cache. ## Building an sd-card image -An image suitable for flashing to an sd-card can be found at the -attribute `config.system.build.sdImage`. For example, if you wanted to -build an image for `rpi-example` in the above configuration -example you could run: +Include the provided `sd-image` nixos module this flake provides, then an image +suitable for flashing to an sd-card can be found at the attribute +`config.system.build.sdImage`. For example, if you wanted to build an image for +`rpi-example` in the above configuration example you could run: ``` nix build '.#nixosConfigurations.rpi-example.config.system.build.sdImage' From aaec735faf81ff05356d65c7408136d2c1522d34 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 18 Nov 2024 09:56:57 -0500 Subject: [PATCH 85/97] add stability note --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 4c7882e..8c94ef9 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,12 @@ The important modules are `overlay/default.nix`, `rpi/default.nix`, and `rpi/config.nix`. The other modules are mostly wrappers that set `config.txt` settings and enable required kernel modules. +## Stability note + +`master` is the development branch -- if you want to avoid breaking changes, you +should pin your flake to a specific release and refer to the release notes when +upgrading. + ## Example See the `rpi-example` config in this flake for an example config built by CI. From 4a74a0208c3ab31e4e7d07367361aef2cf648b1a Mon Sep 17 00:00:00 2001 From: empunkt <102794+nevesenin@users.noreply.github.com> Date: Tue, 26 Nov 2024 13:35:07 +0100 Subject: [PATCH 86/97] Determine partition number for root partition by PARTN column --- sd-image/sd-image.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sd-image/sd-image.nix b/sd-image/sd-image.nix index 60eedfc..b9fed6a 100644 --- a/sd-image/sd-image.nix +++ b/sd-image/sd-image.nix @@ -248,7 +248,7 @@ in # Figure out device names for the boot device and root filesystem. rootPart=$(${pkgs.util-linux}/bin/findmnt -n -o SOURCE /) bootDevice=$(lsblk -npo PKNAME $rootPart) - partNum=$(lsblk -npo MAJ:MIN $rootPart | ${pkgs.gawk}/bin/awk -F: '{print $2}') + partNum=$(lsblk -npo PARTN $rootPart) # Resize the root partition and the filesystem to fit the disk echo ",+," | sfdisk -N$partNum --no-reread $bootDevice From 97c51868c6a820951439162507b80e1b026d8ad4 Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Thu, 26 Dec 2024 11:07:45 -0800 Subject: [PATCH 87/97] Update kernel from 6.6.54 to 6.6.67 --- flake.lock | 10 +++++----- flake.nix | 2 +- overlays/default.nix | 6 +++--- rpi/default.nix | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/flake.lock b/flake.lock index abb934b..e06aee3 100644 --- a/flake.lock +++ b/flake.lock @@ -59,7 +59,7 @@ "rpi-firmware-nonfree-src": "rpi-firmware-nonfree-src", "rpi-firmware-src": "rpi-firmware-src", "rpi-linux-6_10_12-src": "rpi-linux-6_10_12-src", - "rpi-linux-6_6_54-src": "rpi-linux-6_6_54-src", + "rpi-linux-6_6_67-src": "rpi-linux-6_6_67-src", "rpicam-apps-src": "rpicam-apps-src", "u-boot-src": "u-boot-src" } @@ -132,14 +132,14 @@ "type": "github" } }, - "rpi-linux-6_6_54-src": { + "rpi-linux-6_6_67-src": { "flake": false, "locked": { - "lastModified": 1728155174, - "narHash": "sha256-/8RjW35XQMnshjAE4Ey8j3oWzE2GOntnBYY6PlvZGhs=", + "lastModified": 1734790986, + "narHash": "sha256-q9swM2TmmuzbUuQnbLZk5PseKWD7/SNPwtth6bpGIqE=", "owner": "raspberrypi", "repo": "linux", - "rev": "12f0f28db3afe451a81a34c5a444f6841c10067c", + "rev": "811ff707533bcd67cdcd368bbd46223082009b12", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index c0acdc3..d48a39c 100644 --- a/flake.nix +++ b/flake.nix @@ -7,7 +7,7 @@ flake = false; url = "https://ftp.denx.de/pub/u-boot/u-boot-2024.07.tar.bz2"; }; - rpi-linux-6_6_54-src = { + rpi-linux-6_6_67-src = { flake = false; url = "github:raspberrypi/linux/rpi-6.6.y"; }; diff --git a/overlays/default.nix b/overlays/default.nix index 162330c..3d5c6d9 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,5 +1,5 @@ { u-boot-src -, rpi-linux-6_6_54-src +, rpi-linux-6_6_67-src , rpi-linux-6_10_12-src , rpi-firmware-src , rpi-firmware-nonfree-src @@ -9,7 +9,7 @@ final: prev: let versions = { - v6_6_54.src = rpi-linux-6_6_54-src; + v6_6_67.src = rpi-linux-6_6_67-src; v6_10_12 = { src = rpi-linux-6_10_12-src; patches = [ @@ -116,7 +116,7 @@ in # rpi kernels and firmware are available at # `pkgs.rpi-kernels..'. # - # For example: `pkgs.rpi-kernels.v6_6_54.bcm2712' + # For example: `pkgs.rpi-kernels.v6_6_67.bcm2712' rpi-kernels = rpi-kernels ( final.lib.cartesianProduct { board = boards; version = (builtins.attrNames versions); } diff --git a/rpi/default.nix b/rpi/default.nix index 5900692..b6be690 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -14,7 +14,7 @@ in options = with lib; { raspberry-pi-nix = { kernel-version = mkOption { - default = "v6_6_54"; + default = "v6_6_67"; type = types.str; description = "Kernel version to build."; }; From f85fbd621f353db2654173300c75e8c00fc8b6b5 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Mon, 6 Jan 2025 10:19:04 -0500 Subject: [PATCH 88/97] bump nixpkgs to 24.11 --- flake.lock | 8 ++++---- flake.nix | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/flake.lock b/flake.lock index e06aee3..d6df713 100644 --- a/flake.lock +++ b/flake.lock @@ -36,16 +36,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1728193676, - "narHash": "sha256-PbDWAIjKJdlVg+qQRhzdSor04bAPApDqIv2DofTyynk=", + "lastModified": 1736061677, + "narHash": "sha256-DjkQPnkAfd7eB522PwnkGhOMuT9QVCZspDpJJYyOj60=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "ecbc1ca8ffd6aea8372ad16be9ebbb39889e55b6", + "rev": "cbd8ec4de4469333c82ff40d057350c30e9f7d36", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-24.05", + "ref": "nixos-24.11", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index d48a39c..652ae10 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,7 @@ description = "raspberry-pi nixos configuration"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11"; u-boot-src = { flake = false; url = "https://ftp.denx.de/pub/u-boot/u-boot-2024.07.tar.bz2"; From 25b46a0be002fbc4f4b5b36ba7d2ce9652d23c53 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Wed, 8 Jan 2025 11:54:30 -0500 Subject: [PATCH 89/97] add stable kernel --- flake.lock | 18 ++++++++++++++++++ flake.nix | 4 ++++ overlays/default.nix | 2 ++ 3 files changed, 24 insertions(+) diff --git a/flake.lock b/flake.lock index d6df713..4f68be4 100644 --- a/flake.lock +++ b/flake.lock @@ -60,6 +60,7 @@ "rpi-firmware-src": "rpi-firmware-src", "rpi-linux-6_10_12-src": "rpi-linux-6_10_12-src", "rpi-linux-6_6_67-src": "rpi-linux-6_6_67-src", + "rpi-linux-stable-src": "rpi-linux-stable-src", "rpicam-apps-src": "rpicam-apps-src", "u-boot-src": "u-boot-src" } @@ -149,6 +150,23 @@ "type": "github" } }, + "rpi-linux-stable-src": { + "flake": false, + "locked": { + "lastModified": 1728403745, + "narHash": "sha256-phCxkuO+jUGZkfzSrBq6yErQeO2Td+inIGHxctXbD5U=", + "owner": "raspberrypi", + "repo": "linux", + "rev": "5aeecea9f4a45248bcf564dec924965e066a7bfd", + "type": "github" + }, + "original": { + "owner": "raspberrypi", + "ref": "stable_20241008", + "repo": "linux", + "type": "github" + } + }, "rpicam-apps-src": { "flake": false, "locked": { diff --git a/flake.nix b/flake.nix index 652ae10..390d550 100644 --- a/flake.nix +++ b/flake.nix @@ -7,6 +7,10 @@ flake = false; url = "https://ftp.denx.de/pub/u-boot/u-boot-2024.07.tar.bz2"; }; + rpi-linux-stable-src = { + flake = false; + url = "github:raspberrypi/linux/stable_20241008"; + }; rpi-linux-6_6_67-src = { flake = false; url = "github:raspberrypi/linux/rpi-6.6.y"; diff --git a/overlays/default.nix b/overlays/default.nix index 3d5c6d9..325e9b2 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,4 +1,5 @@ { u-boot-src +, rpi-linux-stable-src , rpi-linux-6_6_67-src , rpi-linux-6_10_12-src , rpi-firmware-src @@ -9,6 +10,7 @@ final: prev: let versions = { + v6_6_51.src = rpi-linux-stable-src; v6_6_67.src = rpi-linux-6_6_67-src; v6_10_12 = { src = rpi-linux-6_10_12-src; From 340fc9e3806bd789418a815f2181d7d6be9045d7 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Wed, 8 Jan 2025 11:55:38 -0500 Subject: [PATCH 90/97] default to stable kernel --- rpi/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpi/default.nix b/rpi/default.nix index b6be690..dc207eb 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -14,7 +14,7 @@ in options = with lib; { raspberry-pi-nix = { kernel-version = mkOption { - default = "v6_6_67"; + default = "v6_6_51"; type = types.str; description = "Kernel version to build."; }; From 85faa0f775e3590ff4223c80786862c6f26018c5 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Wed, 8 Jan 2025 11:59:48 -0500 Subject: [PATCH 91/97] matching firmware --- flake.lock | 8 ++++---- flake.nix | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/flake.lock b/flake.lock index 4f68be4..5ef88a3 100644 --- a/flake.lock +++ b/flake.lock @@ -102,16 +102,16 @@ "rpi-firmware-src": { "flake": false, "locked": { - "lastModified": 1727798811, - "narHash": "sha256-eavbshXGYmkYR33y9FLcQMJoAYdYTESVEy0g/RRXnb0=", + "lastModified": 1728405098, + "narHash": "sha256-4gnK0KbqFnjBmWia9Jt2gveVWftmHrprpwBqYVqE/k0=", "owner": "raspberrypi", "repo": "firmware", - "rev": "287e6a6c2d3b50eee3e2c5b2eacdd907e5cbe09a", + "rev": "7bbb5f80d20a2335066a8781459c9f33e5eebc64", "type": "github" }, "original": { "owner": "raspberrypi", - "ref": "1.20241001", + "ref": "1.20241008", "repo": "firmware", "type": "github" } diff --git a/flake.nix b/flake.nix index 390d550..c13eab2 100644 --- a/flake.nix +++ b/flake.nix @@ -21,7 +21,7 @@ }; rpi-firmware-src = { flake = false; - url = "github:raspberrypi/firmware/1.20241001"; + url = "github:raspberrypi/firmware/1.20241008"; }; rpi-firmware-nonfree-src = { flake = false; From e94b747760d09619786a64b84fad30fd6839dd4f Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Thu, 26 Dec 2024 11:23:52 -0800 Subject: [PATCH 92/97] Drop kernel 6.10.12 in favour of 6.12.11 --- flake.lock | 12 ++++++------ flake.nix | 4 ++-- overlays/default.nix | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/flake.lock b/flake.lock index 5ef88a3..71d9a0d 100644 --- a/flake.lock +++ b/flake.lock @@ -58,7 +58,7 @@ "rpi-bluez-firmware-src": "rpi-bluez-firmware-src", "rpi-firmware-nonfree-src": "rpi-firmware-nonfree-src", "rpi-firmware-src": "rpi-firmware-src", - "rpi-linux-6_10_12-src": "rpi-linux-6_10_12-src", + "rpi-linux-6_12_11-src": "rpi-linux-6_12_11-src", "rpi-linux-6_6_67-src": "rpi-linux-6_6_67-src", "rpi-linux-stable-src": "rpi-linux-stable-src", "rpicam-apps-src": "rpicam-apps-src", @@ -116,19 +116,19 @@ "type": "github" } }, - "rpi-linux-6_10_12-src": { + "rpi-linux-6_12_11-src": { "flake": false, "locked": { - "lastModified": 1728305462, - "narHash": "sha256-LtvNmGD1D5YYv+C9xxxddAeHw69o3OX/H9M7F663L74=", + "lastModified": 1738149451, + "narHash": "sha256-NGmZcaC2vlewTEV/p0z2+6PWnHB229dkGui45kI8HOE=", "owner": "raspberrypi", "repo": "linux", - "rev": "26ee50d56618c2d98100b1bc672fd201aed4d00f", + "rev": "fab655ee33e6d647da5996c5548cfd7d43447a53", "type": "github" }, "original": { "owner": "raspberrypi", - "ref": "rpi-6.10.y", + "ref": "rpi-6.12.y", "repo": "linux", "type": "github" } diff --git a/flake.nix b/flake.nix index c13eab2..1668198 100644 --- a/flake.nix +++ b/flake.nix @@ -15,9 +15,9 @@ flake = false; url = "github:raspberrypi/linux/rpi-6.6.y"; }; - rpi-linux-6_10_12-src = { + rpi-linux-6_12_11-src = { flake = false; - url = "github:raspberrypi/linux/rpi-6.10.y"; + url = "github:raspberrypi/linux/rpi-6.12.y"; }; rpi-firmware-src = { flake = false; diff --git a/overlays/default.nix b/overlays/default.nix index 325e9b2..1ad69a6 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,7 +1,7 @@ { u-boot-src , rpi-linux-stable-src , rpi-linux-6_6_67-src -, rpi-linux-6_10_12-src +, rpi-linux-6_12_11-src , rpi-firmware-src , rpi-firmware-nonfree-src , rpi-bluez-firmware-src @@ -12,8 +12,8 @@ let versions = { v6_6_51.src = rpi-linux-stable-src; v6_6_67.src = rpi-linux-6_6_67-src; - v6_10_12 = { - src = rpi-linux-6_10_12-src; + v6_12_11 = { + src = rpi-linux-6_12_11-src; patches = [ { name = "remove-readme-target.patch"; From 25118248489e047a7da43a21409b457aa2af315e Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Wed, 29 Jan 2025 20:39:50 -0800 Subject: [PATCH 93/97] Ignore kernel configuration errors Fixes #113 See https://github.com/NixOS/nixpkgs/pull/366004 --- overlays/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/overlays/default.nix b/overlays/default.nix index 325e9b2..ffbe76c 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -63,6 +63,7 @@ let features.efiBootStub = false; kernelPatches = if kernel ? "patches" then kernel.patches else [ ]; + ignoreConfigErrors = true; }).overrideAttrs (oldAttrs: { postConfigure = '' From 36d2ee3511581cbcb58bb09a820195c6da72408b Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Tue, 4 Feb 2025 09:23:49 -0800 Subject: [PATCH 94/97] Automatically update `flake.lock` using GitHub Actions --- .github/workflows/update-flake-lock.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/update-flake-lock.yml diff --git a/.github/workflows/update-flake-lock.yml b/.github/workflows/update-flake-lock.yml new file mode 100644 index 0000000..ec1a8cd --- /dev/null +++ b/.github/workflows/update-flake-lock.yml @@ -0,0 +1,23 @@ +name: update-flake-lock + +on: + workflow_dispatch: + schedule: + - cron: '0 0 * * 0' + +permissions: + contents: write + pull-requests: write + +jobs: + lockfile: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + + - name: Install nix + uses: DeterminateSystems/nix-installer-action@e50d5f73bfe71c2dd0aa4218de8f4afa59f8f81d # v16 + + - name: Update flake.lock + uses: DeterminateSystems/update-flake-lock@a2bbe0274e3a0c4194390a1e445f734c597ebc37 # v24 From 824ce252585a8fbf8b50023da67c8405d5f4ff85 Mon Sep 17 00:00:00 2001 From: Jeroen Leeuwestein Date: Sat, 8 Feb 2025 19:58:46 +0100 Subject: [PATCH 95/97] Make inclusion of console=serial0 in kernelParams (cmdline.txt) configurable --- rpi/default.nix | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/rpi/default.nix b/rpi/default.nix index dc207eb..ff0a62b 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -77,6 +77,18 @@ in package = mkPackageOption pkgs "uboot-rpi-arm64" { }; }; + serial-console = { + enable = mkOption { + default = true; + type = types.bool; + description = '' + Whether to enable a console on serial0. + + Corresponds with raspi-config's setting + "Would you like a login shell to be accessible over serial?" + ''; + }; + }; }; }; @@ -319,11 +331,14 @@ in boot = { kernelParams = if cfg.uboot.enable then [ ] - else [ - "console=tty1" - # https://github.com/raspberrypi/firmware/issues/1539#issuecomment-784498108 - "console=serial0,115200n8" - "init=/sbin/init" + else builtins.concatLists [ + [ "console=tty1" ] + (if cfg.serial-console.enable then [ + # https://github.com/raspberrypi/firmware/issues/1539#issuecomment-784498108 + "console=serial0,115200n8" + ] else [ ] + ) + [ "init=/sbin/init" ] ]; initrd = { availableKernelModules = [ From b54486ef66721f3e6c8fad98c83b8e7f61e2aad4 Mon Sep 17 00:00:00 2001 From: Will Fancher Date: Mon, 17 Feb 2025 14:11:59 -0500 Subject: [PATCH 96/97] use nixpkgs upstream uboot It's more up to date and it successfully cross compiles --- flake.lock | 16 +--------------- flake.nix | 4 ---- overlays/default.nix | 9 ++------- 3 files changed, 3 insertions(+), 26 deletions(-) diff --git a/flake.lock b/flake.lock index 71d9a0d..999dfd1 100644 --- a/flake.lock +++ b/flake.lock @@ -61,8 +61,7 @@ "rpi-linux-6_12_11-src": "rpi-linux-6_12_11-src", "rpi-linux-6_6_67-src": "rpi-linux-6_6_67-src", "rpi-linux-stable-src": "rpi-linux-stable-src", - "rpicam-apps-src": "rpicam-apps-src", - "u-boot-src": "u-boot-src" + "rpicam-apps-src": "rpicam-apps-src" } }, "rpi-bluez-firmware-src": { @@ -183,19 +182,6 @@ "repo": "rpicam-apps", "type": "github" } - }, - "u-boot-src": { - "flake": false, - "locked": { - "lastModified": 1719857238, - "narHash": "sha256-mJ2TBy0Y5ZtcGFgtU5RKr0UDUp5FWzojbFb+o/ebRJU=", - "type": "tarball", - "url": "https://ftp.denx.de/pub/u-boot/u-boot-2024.07.tar.bz2" - }, - "original": { - "type": "tarball", - "url": "https://ftp.denx.de/pub/u-boot/u-boot-2024.07.tar.bz2" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 1668198..8ede62a 100644 --- a/flake.nix +++ b/flake.nix @@ -3,10 +3,6 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11"; - u-boot-src = { - flake = false; - url = "https://ftp.denx.de/pub/u-boot/u-boot-2024.07.tar.bz2"; - }; rpi-linux-stable-src = { flake = false; url = "github:raspberrypi/linux/stable_20241008"; diff --git a/overlays/default.nix b/overlays/default.nix index 1ad69a6..83ef91f 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,5 +1,4 @@ -{ u-boot-src -, rpi-linux-stable-src +{ rpi-linux-stable-src , rpi-linux-6_6_67-src , rpi-linux-6_12_11-src , rpi-firmware-src @@ -83,14 +82,10 @@ in compressFirmwareZstd = x: x; # provide generic rpi arm64 u-boot - uboot-rpi-arm64 = final.buildUBoot rec { + uboot-rpi-arm64 = final.buildUBoot { defconfig = "rpi_arm64_defconfig"; extraMeta.platforms = [ "aarch64-linux" ]; filesToInstall = [ "u-boot.bin" ]; - version = "2024.04"; - patches = [ ]; - makeFlags = [ ]; - src = u-boot-src; # In raspberry pi sbcs the firmware manipulates the device tree in # a variety of ways before handing it off to the linux kernel. [1] # Since we have installed u-boot in place of a linux kernel we may From abd2352d0405bdae6c43d022e4c65085311d5d7d Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Sat, 1 Mar 2025 20:48:28 -0800 Subject: [PATCH 97/97] bump 6.6.y and 6.12.y kernel versions `rpi-6.6.y` went from `6.6.67` to `6.6.74`. `rpi-6.12.y` went from `6.12.11` to `6.12.17` --- flake.lock | 20 ++++++++++---------- flake.nix | 4 ++-- overlays/default.nix | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/flake.lock b/flake.lock index 999dfd1..81f91aa 100644 --- a/flake.lock +++ b/flake.lock @@ -58,8 +58,8 @@ "rpi-bluez-firmware-src": "rpi-bluez-firmware-src", "rpi-firmware-nonfree-src": "rpi-firmware-nonfree-src", "rpi-firmware-src": "rpi-firmware-src", - "rpi-linux-6_12_11-src": "rpi-linux-6_12_11-src", - "rpi-linux-6_6_67-src": "rpi-linux-6_6_67-src", + "rpi-linux-6_12_17-src": "rpi-linux-6_12_17-src", + "rpi-linux-6_6_78-src": "rpi-linux-6_6_78-src", "rpi-linux-stable-src": "rpi-linux-stable-src", "rpicam-apps-src": "rpicam-apps-src" } @@ -115,14 +115,14 @@ "type": "github" } }, - "rpi-linux-6_12_11-src": { + "rpi-linux-6_12_17-src": { "flake": false, "locked": { - "lastModified": 1738149451, - "narHash": "sha256-NGmZcaC2vlewTEV/p0z2+6PWnHB229dkGui45kI8HOE=", + "lastModified": 1740765145, + "narHash": "sha256-hoCsGc4+RC/2LmxDtswLBL5ZhWlw4vSiL4Vkl39r2MU=", "owner": "raspberrypi", "repo": "linux", - "rev": "fab655ee33e6d647da5996c5548cfd7d43447a53", + "rev": "5985ce32e511f4e8279a841a1b06a8c7d972b386", "type": "github" }, "original": { @@ -132,14 +132,14 @@ "type": "github" } }, - "rpi-linux-6_6_67-src": { + "rpi-linux-6_6_78-src": { "flake": false, "locked": { - "lastModified": 1734790986, - "narHash": "sha256-q9swM2TmmuzbUuQnbLZk5PseKWD7/SNPwtth6bpGIqE=", + "lastModified": 1740503700, + "narHash": "sha256-Y8+ot4Yi3UKwlZK3ap15rZZ16VZDvmeFkD46+6Ku7bE=", "owner": "raspberrypi", "repo": "linux", - "rev": "811ff707533bcd67cdcd368bbd46223082009b12", + "rev": "2e071057fded90e789c0101498e45a1778be93fe", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 8ede62a..fe3fc24 100644 --- a/flake.nix +++ b/flake.nix @@ -7,11 +7,11 @@ flake = false; url = "github:raspberrypi/linux/stable_20241008"; }; - rpi-linux-6_6_67-src = { + rpi-linux-6_6_78-src = { flake = false; url = "github:raspberrypi/linux/rpi-6.6.y"; }; - rpi-linux-6_12_11-src = { + rpi-linux-6_12_17-src = { flake = false; url = "github:raspberrypi/linux/rpi-6.12.y"; }; diff --git a/overlays/default.nix b/overlays/default.nix index f5e1367..b859342 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,6 +1,6 @@ { rpi-linux-stable-src -, rpi-linux-6_6_67-src -, rpi-linux-6_12_11-src +, rpi-linux-6_6_78-src +, rpi-linux-6_12_17-src , rpi-firmware-src , rpi-firmware-nonfree-src , rpi-bluez-firmware-src @@ -10,9 +10,9 @@ final: prev: let versions = { v6_6_51.src = rpi-linux-stable-src; - v6_6_67.src = rpi-linux-6_6_67-src; - v6_12_11 = { - src = rpi-linux-6_12_11-src; + v6_6_78.src = rpi-linux-6_6_78-src; + v6_12_17 = { + src = rpi-linux-6_12_17-src; patches = [ { name = "remove-readme-target.patch"; @@ -114,7 +114,7 @@ in # rpi kernels and firmware are available at # `pkgs.rpi-kernels..'. # - # For example: `pkgs.rpi-kernels.v6_6_67.bcm2712' + # For example: `pkgs.rpi-kernels.v6_6_78.bcm2712' rpi-kernels = rpi-kernels ( final.lib.cartesianProduct { board = boards; version = (builtins.attrNames versions); }