checkpoint lol

This commit is contained in:
mjallen18
2025-12-29 15:13:52 -06:00
parent 67fb7d7323
commit 82e062a7e8
15 changed files with 394 additions and 144 deletions

View File

@@ -228,12 +228,12 @@
pi5 = { pi5 = {
modules = with inputs; [ modules = with inputs; [
disko.nixosModules.disko disko.nixosModules.disko
nixos-raspberrypi.nixosModules.raspberry-pi-5.base # nixos-raspberrypi.nixosModules.raspberry-pi-5.base
nixos-raspberrypi.nixosModules.raspberry-pi-5.display-vc4 # nixos-raspberrypi.nixosModules.raspberry-pi-5.display-vc4
nixos-raspberrypi.nixosModules.raspberry-pi-5.bluetooth # nixos-raspberrypi.nixosModules.raspberry-pi-5.bluetooth
nixos-raspberrypi.nixosModules.raspberry-pi-5.page-size-16k # nixos-raspberrypi.nixosModules.raspberry-pi-5.page-size-16k
nixos-raspberrypi.nixosModules.nixpkgs-rpi # nixos-raspberrypi.nixosModules.nixpkgs-rpi
nixos-raspberrypi.nixosModules.trusted-nix-caches # nixos-raspberrypi.nixosModules.trusted-nix-caches
# nixos-raspberrypi.lib.inject-overlays # nixos-raspberrypi.lib.inject-overlays
# nixos-raspberrypi.lib.inject-overlays-global # nixos-raspberrypi.lib.inject-overlays-global
]; ];

View File

@@ -0,0 +1,67 @@
# modification of nixpkgs deviceTree.applyOverlays to resolve https://github.com/NixOS/nixpkgs/issues/125354
# derived from https://github.com/NixOS/nixpkgs/blob/916ca8f2b0c208def051f8ea9760c534a40309db/pkgs/os-specific/linux/device-tree/default.nix
{
lib,
stdenvNoCC,
dtc,
libraspberrypi,
}:
with lib;
(
base: overlays':
stdenvNoCC.mkDerivation {
name = "device-tree-overlays";
nativeBuildInputs = [
dtc
libraspberrypi
];
buildCommand =
let
overlays = toList overlays';
in
''
mkdir -p $out
cd "${base}"
find . -type f -name '*.dtb' -print0 \
| xargs -0 cp -v --no-preserve=mode --target-directory "$out" --parents
for dtb in $(find "$out" -type f -name '*.dtb'); do
dtbCompat=$(fdtget -t s "$dtb" / compatible 2>/dev/null || true)
# skip files without `compatible` string
test -z "$dtbCompat" && continue
${flip (concatMapStringsSep "\n") overlays (o: ''
overlayCompat="$(fdtget -t s "${o.dtboFile}" / compatible)"
# skip incompatible and non-matching overlays
if [[ ! "$dtbCompat" =~ "$overlayCompat" ]]; then
echo "Skipping overlay ${o.name}: incompatible with $(basename "$dtb")"
elif ${
if ((o.filter or null) == null) then
"false"
else
''
[[ "''${dtb//${o.filter}/}" == "$dtb" ]]
''
}
then
echo "Skipping overlay ${o.name}: filter does not match $(basename "$dtb")"
else
echo -n "Applying overlay ${o.name} to $(basename "$dtb")... "
mv "$dtb"{,.in}
# dtmerge requires a .dtbo ext for dtbo files, otherwise it adds it to the given file implicitly
dtboWithExt="$TMPDIR/$(basename "${o.dtboFile}").dtbo"
cp -r ${o.dtboFile} "$dtboWithExt"
dtmerge "$dtb.in" "$dtb" "$dtboWithExt"
echo "ok"
rm "$dtb.in" "$dtboWithExt"
fi
'')}
done'';
}
)

View File

@@ -7,6 +7,11 @@
}: }:
let let
cfg = config.${namespace}.hardware.raspberry-pi; cfg = config.${namespace}.hardware.raspberry-pi;
dt_ao_overlay = _final: prev: {
deviceTree = prev.deviceTree // {
applyOverlays = _final.callPackage ./apply-overlays-dtmerge.nix { };
};
};
in in
{ {
options.${namespace}.hardware.raspberry-pi = { options.${namespace}.hardware.raspberry-pi = {
@@ -19,13 +24,40 @@ in
]; ];
description = "Raspberry Pi variant (4 or 5)"; description = "Raspberry Pi variant (4 or 5)";
}; };
apply-overlays-dtmerge = {
enable = lib.mkEnableOption "" // {
description = ''
Whether replace deviceTree.applyOverlays implementation to use dtmerge from libraspberrypi.
This can resolve issues with applying dtbs for the pi.
'';
}; };
};
};
imports = [
./leds.nix
];
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
boot.initrd.availableKernelModules = lib.mkIf (cfg.variant == "5") [ boot = {
initrd.availableKernelModules = [
"usbhid"
"usb-storage"
] ++ (if (cfg.variant == "5") then [
"nvme" "nvme"
]; ] else
[
"vc4"
"pcie-brcmstb" # required for the pcie bus to work
"reset-raspberrypi" # required for vl805 firmware to load
]);
loader = {
generic-extlinux-compatible.enable = lib.mkDefault true;
grub.enable = lib.mkForce false;
};
};
# Common Raspberry Pi packages # Common Raspberry Pi packages
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
@@ -58,21 +90,65 @@ in
# Common hardware settings # Common hardware settings
hardware = { hardware = {
i2c.enable = lib.mkDefault true; deviceTree = {
filter = lib.mkDefault (if (cfg.variant == "5") then "bcm2712-rpi-*.dtb" else "bcm2711-rpi-*.dtb");
overlays = lib.mkIf (cfg.variant == "4") [
{
name = "rpi4-cpu-revision";
dtsText = ''
/dts-v1/;
/plugin/;
/ {
compatible = "raspberrypi,4-model-b";
fragment@0 {
target-path = "/";
__overlay__ {
system {
linux,revision = <0x00d03114>;
};
};
};
};
'';
}
{
name = "enable-xhci";
dtsText = ''
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2711";
fragment@0 {
//target-path = "/scb/xhci@7e9c0000";
target = <&xhci>;
__overlay__ {
status = "okay";
};
};
};
'';
}
];
};
firmware = [ pkgs.${namespace}.raspberryPiWirelessFirmware ];
graphics.enable32Bit = lib.mkForce false; graphics.enable32Bit = lib.mkForce false;
i2c.enable = lib.mkDefault true;
}; };
# Pi specific system tags # Pi specific system tags
system.nixos.tags = ( # system.nixos.tags = (
let # let
bootCfg = config.boot.loader.raspberry-pi; # bootCfg = config.boot.loader.raspberry-pi;
in # in
[ # [
"raspberry-pi-${bootCfg.variant}" # "raspberry-pi-${bootCfg.variant}"
bootCfg.bootloader # bootCfg.bootloader
config.boot.kernelPackages.kernel.version # config.boot.kernelPackages.kernel.version
] # ]
); # );
# Common programs # Common programs
programs.kdeconnect.enable = lib.mkDefault false; programs.kdeconnect.enable = lib.mkDefault false;
@@ -164,6 +240,7 @@ in
++ [ "${pageSizeFlag}=14" ]; ++ [ "${pageSizeFlag}=14" ];
}); });
}) })
] else [ ]); ] else [ ])
++ (if cfg.apply-overlays-dtmerge.enable then [ dt_ao_overlay ] else [ ]);
}; };
} }

View File

@@ -0,0 +1,132 @@
{ config, lib, namespace, ... }:
let
cfg = config.${namespace}.hardware.raspberry-pi.leds;
mkDisableOption =
name:
lib.mkOption {
default = false;
example = true;
description = "Whether to disable ${name}.";
type = lib.types.bool;
};
in
{
options.${namespace}.hardware = {
raspberry-pi.leds = {
eth.disable = mkDisableOption ''ethernet LEDs.'';
act.disable = mkDisableOption ''activity LED.'';
pwr.disable = mkDisableOption ''power LED.'';
};
};
# Adapted from: https://gist.github.com/SFrijters/206d2c09656affb04284f076c75a1969
config = lib.mkMerge [
(lib.mkIf (cfg.eth.disable || cfg.act.disable || cfg.pwr.disable) {
${namespace}.hardware.raspberry-pi.apply-overlays-dtmerge.enable = lib.mkDefault true;
hardware.deviceTree.filter = "*-rpi-4-*.dtb";
})
(lib.mkIf cfg.eth.disable {
hardware.deviceTree = {
overlays = [
# https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README
# eth_led0 Set mode of LED0 - amber on Pi3B+ (default "1"),
# green on Pi4 (default "0").
# The legal values are:
#
# Pi4
#
# 0=Speed/Activity 1=Speed
# 2=Flash activity 3=FDX
# 4=Off 5=On
# 6=Alt 7=Speed/Flash
# 8=Link 9=Activity
#
# Debugging:
# $ hexdump /proc/device-tree/scb/ethernet@7d580000/mdio@e14/ethernet-phy@1/led-modes
{
name = "disable-eth-leds";
filter = "*rpi-4-b*";
dtsText = ''
/dts-v1/;
/plugin/;
/{
compatible = "raspberrypi,4-model-b";
fragment@0 {
target = <&phy1>;
__overlay__ {
led-modes = <0x04 0x04>;
};
};
};
'';
}
];
};
})
(lib.mkIf cfg.act.disable {
hardware.deviceTree = {
overlays = [
# Debugging:
# $ hexdump /proc/device-tree/leds/led-act/gpios
# $ cat /proc/device-tree/leds/led-act/linux,default-trigger
{
name = "disable-act-led";
filter = "*rpi-4-b*";
dtsText =
let
kernelVersion = lib.versionAtLeast config.boot.kernelPackages.kernel.version "6.2";
target = if kernelVersion then "<&led_act>" else "<&act_led>";
in
''
/dts-v1/;
/plugin/;
/{
compatible = "raspberrypi,4-model-b";
fragment@0 {
target = ${target};
__overlay__ {
gpios = <&gpio 42 0>; /* first two values copied from bcm2711-rpi-4-b.dts */
linux,default-trigger = "none";
};
};
};
'';
}
];
};
})
(lib.mkIf cfg.pwr.disable {
hardware.deviceTree = {
overlays = [
# Debugging:
# $ hexdump /proc/device-tree/leds/led-pwr/gpios
# $ cat /proc/device-tree/leds/led-pwr/linux,default-trigger
{
name = "disable-pwr-led";
filter = "*rpi-4-b*";
dtsText =
let
kernelVersion = lib.versionAtLeast config.boot.kernelPackages.kernel.version "6.2";
target = if kernelVersion then "<&led_pwr>" else "<&pwr_led>";
in
''
/dts-v1/;
/plugin/;
/{
compatible = "raspberrypi,4-model-b";
fragment@0 {
target = ${target};
__overlay__ {
gpios = <&expgpio 2 0>; /* first two values copied from bcm2711-rpi-4-b.dts */
linux,default-trigger = "default-on";
};
};
};
'';
}
];
};
})
];
}

View File

@@ -27,21 +27,22 @@ in
"jemalloc" "jemalloc"
"jupiter-fan-control" "jupiter-fan-control"
"libcamera-rpi" "libcamera-rpi"
"${namespace}.libraspberrypi"
"libsecret" "libsecret"
"linux" "linux"
"linux-rpi" "${namespace}.linux-rpi"
"linuxPackages_cachyos" "${namespace}.linuxPackages_cachyos"
"linuxPackages_cachyos-lto" "${namespace}.linuxPackages_cachyos-lto"
"linuxPackages_cachyos-lto-znver4" "${namespace}.linuxPackages_cachyos-lto-znver4"
"linuxPackages_cachyos-server" "${namespace}.linuxPackages_cachyos-server"
"linuxPackages_cachyos-server-lto" "${namespace}.linuxPackages_cachyos-server-lto"
"linuxPackages_cachyos-server-lto-znver4" "${namespace}.linuxPackages_cachyos-server-lto-znver4"
"linuxPackages_cachyos-rc" "${namespace}.linuxPackages_cachyos-rc"
"linuxPackages_cachyos-rc-lto" "${namespace}.linuxPackages_cachyos-rc-lto"
"linuxPackages_cachyos-rc-lto-znver4" "${namespace}.linuxPackages_cachyos-rc-lto-znver4"
"linuxPackages_cachyos-hardened" "${namespace}.linuxPackages_cachyos-hardened"
"linuxPackages_cachyos-hardened-lto" "${namespace}.linuxPackages_cachyos-hardened-lto"
"linuxPackages_cachyos-hardened-lto-znver4" "${namespace}.linuxPackages_cachyos-hardened-lto-znver4"
"mesa" "mesa"
"mesa_i686" "mesa_i686"
"mesa-radeonsi-jupiter" "mesa-radeonsi-jupiter"
@@ -59,6 +60,7 @@ in
"qt3d" "qt3d"
"qtdeclarative" "qtdeclarative"
"qtmultimedia" "qtmultimedia"
"${namespace}.raspberrypi-utils"
"ryubing" "ryubing"
"sdl" "sdl"
"sdl2" "sdl2"
@@ -72,11 +74,8 @@ in
nixpkgs.overlays = [ nixpkgs.overlays = [
(_self: super: { (_self: super: {
${namespace} = super.${namespace} // { ${namespace} = super.${namespace} // {
linux-rpi = super.${namespace}.linux-rpi.override { stdenv = super.ccacheStdenv; };
linuxPackages_rpi4 = super.linuxPackagesFor (super.${namespace}.linux-rpi.override { stdenv = super.ccacheStdenv; rpiVersion = 4; });
linuxPackages_rpi5 = super.linuxPackagesFor (super.${namespace}.linux-rpi.override { stdenv = super.ccacheStdenv; }); linuxPackages_rpi5 = super.linuxPackagesFor (super.${namespace}.linux-rpi.override { stdenv = super.ccacheStdenv; });
libraspberrypi = super.${namespace}.libraspberrypi.override { stdenv = super.ccacheStdenv; }; linuxPackages_rpi4 = super.linuxPackagesFor (super.${namespace}.linux-rpi.override { stdenv = super.ccacheStdenv; rpiVersion = 4; });
raspberrypi-utils = super.${namespace}.raspberrypi-utils.override { stdenv = super.ccacheStdenv; };
}; };
}) })

View File

@@ -1,6 +1,6 @@
{ inputs, self, ... }: { inputs, self, namespace, ... }:
final: _prev: final: prev:
let let
cachyosPackages = final.callPackage ../../packages/linux-cachyos { cachyosPackages = final.callPackage ../../packages/linux-cachyos {
pkgs = final; pkgs = final;
@@ -9,6 +9,7 @@ let
}; };
in in
{ {
${namespace} = prev.${namespace} // {
# GCC Kernels # GCC Kernels
# Latest # Latest
linuxPackages_cachyos = cachyosPackages.cachyos-gcc; linuxPackages_cachyos = cachyosPackages.cachyos-gcc;
@@ -32,4 +33,5 @@ in
# RC # RC
linuxPackages_cachyos-rc-lto = cachyosPackages.cachyos-rc-lto; linuxPackages_cachyos-rc-lto = cachyosPackages.cachyos-rc-lto;
linuxPackages_cachyos-rc-lto-znver4 = cachyosPackages.cachyos-rc-lto-znver4; linuxPackages_cachyos-rc-lto-znver4 = cachyosPackages.cachyos-rc-lto-znver4;
};
} }

View File

@@ -1,22 +0,0 @@
{ inputs, self, namespace, ... }:
final: _prev:
let
pi5 = final.callPackage ../../packages/raspberrypi/linux-rpi/default.nix {
pkgs = final;
nixpkgs = inputs.nixpkgs;
inherit self;
};
pi4 = final.callPackage ../../packages/raspberrypi/linux-rpi/default.nix {
pkgs = final;
nixpkgs = inputs.nixpkgs;
rpiVersion = 4;
inherit self;
};
in
{
# ${namespace} = final.${namespace} // {
# linuxPackages_rpi5 = final.linuxPackagesFor pi5;
linuxPackages_rpi4 = final.linuxPackagesFor pi4;
# };
}

View File

@@ -1,13 +1,10 @@
{ {
lib, lib,
ccacheStdenv, stdenv,
fetchFromGitHub, fetchFromGitHub,
cmake, cmake,
pkg-config, pkg-config,
}: }:
let
stdenv = ccacheStdenv;
in
stdenv.mkDerivation (_finalAttrs: { stdenv.mkDerivation (_finalAttrs: {
pname = "libraspberrypi"; pname = "libraspberrypi";
version = "unstable-2024-12-23"; version = "unstable-2024-12-23";

View File

@@ -1,5 +1,6 @@
{ {
ccacheStdenv, # ccacheStdenv,
stdenv,
lib, lib,
fetchFromGitHub, fetchFromGitHub,
buildLinux, buildLinux,
@@ -8,7 +9,7 @@
}@args: }@args:
let let
stdenv = ccacheStdenv; # stdenv = ccacheStdenv;
modDirVersion = "6.12.47"; modDirVersion = "6.12.47";
tag = "stable_20250916"; tag = "stable_20250916";
hash = "sha256-HG8Oc04V2t54l0SOn4gKmNJWQUrZfjWusgKcWvx74H0=="; hash = "sha256-HG8Oc04V2t54l0SOn4gKmNJWQUrZfjWusgKcWvx74H0==";

View File

@@ -2,14 +2,11 @@
# because libraspberrypi is outdated and deprecated # because libraspberrypi is outdated and deprecated
{ {
lib, lib,
ccacheStdenv, stdenv,
fetchFromGitHub, fetchFromGitHub,
cmake, cmake,
dtc, dtc,
}: }:
let
stdenv = ccacheStdenv;
in
stdenv.mkDerivation (_finalAttrs: { stdenv.mkDerivation (_finalAttrs: {
pname = "raspberrypi-utils"; pname = "raspberrypi-utils";
version = "unstable-2025-12-26"; version = "unstable-2025-12-26";

View File

@@ -4,54 +4,54 @@ let
in in
{ {
boot = { boot = {
loader.raspberry-pi = { # loader.raspberry-pi = {
bootloader = "kernel"; # bootloader = "kernel";
firmwarePackage = pkgs.raspberrypifw; # firmwarePackage = pkgs.raspberrypifw;
}; # };
kernelPackages = pkgs.linuxPackages_rpi5; kernelPackages = pkgs.${namespace}.linuxPackages_rpi5;
supportedFilesystems = lib.mkForce [ ]; supportedFilesystems = lib.mkForce [ ];
}; };
hardware.raspberry-pi.config = { # hardware.raspberry-pi.config = {
all = { # all = {
# [all] conditional filter, https://www.raspberrypi.com/documentation/computers/config_txt.html#conditional-filters # # [all] conditional filter, https://www.raspberrypi.com/documentation/computers/config_txt.html#conditional-filters
options = { # options = {
# https://www.raspberrypi.com/documentation/computers/config_txt.html#enable_uart # # https://www.raspberrypi.com/documentation/computers/config_txt.html#enable_uart
# in conjunction with `console=serial0,115200` in kernel command line (`cmdline.txt`) # # in conjunction with `console=serial0,115200` in kernel command line (`cmdline.txt`)
# creates a serial console, accessible using GPIOs 14 and 15 (pins # # creates a serial console, accessible using GPIOs 14 and 15 (pins
# 8 and 10 on the 40-pin header) # # 8 and 10 on the 40-pin header)
enable_uart = { # enable_uart = {
enable = true; # enable = true;
value = true; # value = true;
}; # };
# https://www.raspberrypi.com/documentation/computers/config_txt.html#uart_2ndstage # # https://www.raspberrypi.com/documentation/computers/config_txt.html#uart_2ndstage
# enable debug logging to the UART, also automatically enables # # enable debug logging to the UART, also automatically enables
# UART logging in `start.elf` # # UART logging in `start.elf`
uart_2ndstage = { # uart_2ndstage = {
enable = true; # enable = true;
value = true; # value = true;
}; # };
}; # };
# Base DTB parameters # # Base DTB parameters
# https://github.com/raspberrypi/linux/blob/a1d3defcca200077e1e382fe049ca613d16efd2b/arch/arm/boot/dts/overlays/README#L132 # # https://github.com/raspberrypi/linux/blob/a1d3defcca200077e1e382fe049ca613d16efd2b/arch/arm/boot/dts/overlays/README#L132
base-dt-params = { # base-dt-params = {
# https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#enable-pcie # # https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#enable-pcie
pciex1 = { # pciex1 = {
enable = true; # enable = true;
value = "on"; # value = "on";
}; # };
# PCIe Gen 3.0 # # PCIe Gen 3.0
# https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#pcie-gen-3-0 # # https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#pcie-gen-3-0
pciex1_gen = { # pciex1_gen = {
enable = true; # enable = true;
value = "3"; # value = "3";
}; # };
}; # };
}; # };
}; # };
} }

View File

@@ -5,7 +5,7 @@
... ...
}: }:
let let
kernel = pkgs.linuxPackages_cachyos-server-lto-znver4; kernel = pkgs.${namespace}.linuxPackages_cachyos-server-lto-znver4;
in in
{ {
# Configure bootloader with lanzaboot and secureboot # Configure bootloader with lanzaboot and secureboot

View File

@@ -1,6 +1,6 @@
{ config, pkgs, ... }: { config, pkgs, namespace, ... }:
let let
kernel = pkgs.linuxPackages_cachyos-lto-znver4; kernel = pkgs.${namespace}.linuxPackages_cachyos-lto-znver4;
pkgsVersion = pkgs; # .unstable; pkgsVersion = pkgs; # .unstable;
in in
{ {

View File

@@ -101,6 +101,6 @@
# # Boot # # # # Boot # #
# ################################################### # ###################################################
boot.kernelPackages = pkgs.linuxPackages_cachyos-server-lto-znver4; boot.kernelPackages = pkgs.${namespace}.linuxPackages_cachyos-server-lto-znver4;
} }

View File

@@ -1,6 +1,6 @@
{ pkgs, ... }: { pkgs, ... }:
let let
kernel = pkgs.linuxPackages_cachyos-lto; kernel = pkgs.${namespace}.linuxPackages_cachyos-lto;
in in
{ {
# Configure bootloader with lanzaboot and secureboot # Configure bootloader with lanzaboot and secureboot