Skip to content

rpi4: Introduce raspberry-pi."4".enable #1515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions raspberry-pi/4/cpu-revision.nix
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
{
hardware.deviceTree.overlays = [
{
name = "rpi4-cpu-revision";
dtsText = ''
/dts-v1/;
/plugin/;
{ config, lib, ... }:
lib.mkIf config.hardware.raspberry-pi."4".enable {
hardware.deviceTree.overlays = [{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we do this in NixOS but for nixos-hardware users usually expect that an import is enough, so I would like to task why this option is necessary. Are overlays not needed to make the machine boot? An alternative would be also to have an enable option that defaults to true.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditional imports are not possible with the nixpkgs module system. So for example if you want to make a vm of your RPi 4 NixOS system (e.g. nix build .#nixosConfigurations.thepi.config.system.build.vm) it will fail because the nixos-hardware module hard-sets a kernel and other stuff. So either an enable flag is introduced which you can then nicely auto-disable for VMs (e.g. via options.virtualisation ? qemu, which is only true when building a vm) or you make an entirely separate nixosConfiguration only for the vm, which is uncool.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nixos-hardware users usually expect that an import is enough

Well all the "sub"modules for the rpi4 for example to have enable flags and users are not supposed to include them for activation. There's a reason nixpkgs does all the enable guarding. But yeah, if this is how nixos-hardware does it, then I guess an enable flag that's on by default could work to keep backwards-compatibility. Not very elegant though in my opinion.

name = "rpi4-cpu-revision";
dtsText = ''
/dts-v1/;
/plugin/;

/ {
compatible = "raspberrypi,4-model-b";
/ {
compatible = "raspberrypi,4-model-b";

fragment@0 {
target-path = "/";
__overlay__ {
system {
linux,revision = <0x00d03114>;
};
fragment@0 {
target-path = "/";
__overlay__ {
system {
linux,revision = <0x00d03114>;
};
};
};
'';
}
];
};
'';
}];
}
54 changes: 32 additions & 22 deletions raspberry-pi/4/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,41 @@
./xhci.nix
];

boot = {
kernelPackages = lib.mkDefault pkgs.linuxKernel.packages.linux_rpi4;
initrd.availableKernelModules = [
"usbhid"
"usb_storage"
"vc4"
"pcie_brcmstb" # required for the pcie bus to work
"reset-raspberrypi" # required for vl805 firmware to load
];

loader = {
grub.enable = lib.mkDefault false;
generic-extlinux-compatible.enable = lib.mkDefault true;
options = {
hardware.raspberry-pi."4" = {
enable = lib.mkEnableOption "basic config for a RaspberryPi 4";
};
};

hardware.deviceTree.filter = lib.mkDefault "bcm2711-rpi-*.dtb";
config = lib.mkIf config.hardware.raspberry-pi."4".enable {


assertions = [
{
assertion = (lib.versionAtLeast config.boot.kernelPackages.kernel.version "6.1");
message = "This version of raspberry pi 4 dts overlays requires a newer kernel version (>=6.1). Please upgrade nixpkgs for this system.";
}
];
boot = {
kernelPackages = lib.mkDefault pkgs.linuxKernel.packages.linux_rpi4;
initrd.availableKernelModules = [
"usbhid"
"usb_storage"
"vc4"
"pcie_brcmstb" # required for the pcie bus to work
"reset-raspberrypi" # required for vl805 firmware to load
];

loader = {
grub.enable = lib.mkDefault false;
generic-extlinux-compatible.enable = lib.mkDefault true;
};
};

hardware.deviceTree.filter = lib.mkDefault "bcm2711-rpi-*.dtb";

# Required for the Wireless firmware
hardware.enableRedistributableFirmware = true;
assertions = [{
assertion =
(lib.versionAtLeast config.boot.kernelPackages.kernel.version "6.1");
message =
"This version of raspberry pi 4 dts overlays requires a newer kernel version (>=6.1). Please upgrade nixpkgs for this system.";
}];

# Required for the Wireless firmware
hardware.enableRedistributableFirmware = true;
};
}
Loading