From 8a633100aaa3c36f874a1570b2164752f62d5b6a Mon Sep 17 00:00:00 2001 From: MinerSebas Date: Sun, 16 Jun 2024 16:40:53 +0200 Subject: [PATCH 01/65] 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 02/65] 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 03/65] 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 04/65] 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 05/65] 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 06/65] 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 07/65] 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 08/65] 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 09/65] 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 10/65] 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 11/65] 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 12/65] 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 13/65] 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 14/65] 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 15/65] 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 16/65] 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 17/65] 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 18/65] 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 19/65] 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 20/65] 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 21/65] 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 22/65] 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 23/65] 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 24/65] 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 25/65] 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 26/65] 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 27/65] 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 28/65] 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 29/65] 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 30/65] 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 31/65] 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 32/65] 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 33/65] 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 34/65] 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 35/65] 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 36/65] 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 37/65] 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 38/65] 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 39/65] 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 40/65] 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 41/65] 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 42/65] 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 43/65] 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 44/65] 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 45/65] 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 46/65] 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 47/65] 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 48/65] 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 49/65] 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 50/65] 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 51/65] 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 52/65] 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 53/65] 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 54/65] 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 55/65] 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 56/65] 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 57/65] 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 58/65] 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 59/65] 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 60/65] 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 61/65] 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 62/65] 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 63/65] 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 64/65] 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 65/65] 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); }