Difference between revisions of "NixOS on ARM/Raspberry Pi"

From NixOS Wiki
Jump to: navigation, search
(Begin scrubbing the Pi 3 parts out)
m (rollback unauthorized mass edits)
Tag: Rollback
 
(22 intermediate revisions by 12 users not shown)
Line 1: Line 1:
{{ARM/breadcrumb}}
+
This page has been moved to the official NixOS Wiki:
<div class="infobox">
 
{|class="table"
 
!colspan="2" class="title"|Raspberry Pi Family
 
|-
 
|colspan="2"|[[File:raspberry_pi_3_glamour.jpg|frameless|256px|A Raspberry Pi 3 with enclosure.]]
 
|-
 
!colspan="2" class="title"|Raspberry Pi
 
|-
 
!Architecture
 
|ARMv6
 
|-
 
!colspan="2" class="title"|Raspberry Pi 2
 
|-
 
!Architecture
 
|ARMv7
 
|-
 
!colspan="2" class="title"|Raspberry Pi 3
 
|-
 
!Architecture
 
|AArch64 + ARMv7
 
|-
 
!colspan="2" class="title"|Raspberry Pi 4
 
|-
 
!Architecture
 
|AArch64 + ARMv7
 
|}
 
</div>
 
The Raspberry Pi family of devices is a series of single-board computers made by the Raspberry Pi Foundation. They are all based on Broadcom System-on-a-chip (SOCs).
 
  
== Status ==
+
    ⇒ '''[https://wiki.nixos.org/wiki/NixOS_on_ARM/Raspberry_Pi NixOS on ARM/Raspberry Pi]'''
  
Only the ''Raspberry Pi 3 Family'' is supported upstream, with the AArch64 effort.
+
''— samueldr, Lead of NixOS on ARM.''
 
 
The Raspberry Pi 4B is not <em>supported</em> by NixOS, though a beta-quality disk image specific for it is produced. It will be supported the same as the Pi 3 family once the mainline kernel and mainline U-Boot boot fine through the generic mainline image.
 
 
 
Other Raspberry Pis (0, 1, and 2) are part of diverse community porting efforts to ARMv6 and ARMv7.
 
 
 
The Linux kernel in use, except for the Raspberry Pi 1 family, is the mainline Linux kernel, and not the Raspberry Pi Foundation's fork. This could reduce compatibility with some add-on boards or third-party libraries<sup>[expanded explanation needed]</sup>.
 
 
 
The following table is intended to be updated by the NixOS contributors with the current status of the boards. For a list of products, [https://www.raspberrypi.org/products/ see the ''Products Archive]''.
 
 
 
{|class="wikitable"
 
|-
 
! Board name
 
! Architecture
 
! Support
 
|-
 
!colspan="3" style="text-align: left;"|Raspberry Pi 1
 
|-
 
| Raspberry Pi 1 Model B
 
|rowspan="5" style="vertical-align: middle;"| armv6
 
| C
 
|-
 
| Raspberry Pi 1 Model A+
 
| C*
 
|-
 
| Raspberry Pi 1 Model B+
 
| C
 
|-
 
| Raspberry Pi Zero
 
| C*
 
|-
 
| Raspberry Pi Zero W
 
| C
 
|-
 
!colspan="3" style="text-align: left;"|Raspberry Pi 2
 
|-
 
| Raspberry Pi 2 Model B
 
| armv7
 
| C
 
|-
 
!colspan="3" style="text-align: left;"|Raspberry Pi 3
 
|-
 
| [[NixOS on ARM/Raspberry Pi 3|Raspberry Pi 3 Model B]]
 
|rowspan="3" style="vertical-align: middle;"| AArch64<br /> ''+ armv7''
 
| YES
 
|-
 
| [[NixOS on ARM/Raspberry Pi 3|Raspberry Pi 3 Model B+]]
 
| YES
 
|-
 
| [[NixOS on ARM/Raspberry Pi 3|Raspberry Pi 3 Model A+]]
 
| ?
 
|-
 
!colspan="3" style="text-align: left;"|Raspberry Pi 4
 
|-
 
| [[NixOS on ARM/Raspberry Pi 4|Raspberry Pi 4 Model B]]
 
| AArch64<br /> ''+ armv7''
 
| YES* ([https://github.com/NixOS/nixpkgs/issues/63720 GitHub issue])
 
|}
 
 
 
''Support''
 
* YES: Supported architecture by Nixpkgs downstream and tested to be working.
 
* YES*: Available in Nixpkgs downstream but experimental.
 
* C: Community supported, and tested to be working.
 
* C*: Community supported, unverified but should be working.
 
* ? : Unverified, unknown if it will work.
 
 
 
The Raspberry Pi 3 Family is only supported as '''AArch64'''. Use as armv7 is community supported.
 
 
 
== Board-specific installation notes ==
 
 
 
First follow the [[NixOS_on_ARM#Installation|generic installation steps]] to get the installer image and install using the [[NixOS_on_ARM#NixOS_installation_.26_configuration|installation and configuration steps]].
 
 
 
=== Raspberry Pi (1) ===
 
 
 
The ARMv6 image boots out-of-the-box.
 
 
 
=== Raspberry Pi 2 ===
 
 
 
The ARMv7 image should boot out-of-the-box, though the author hasn't personally tested this.
 
 
 
=== Raspberry Pi 3 / 3B+ ===
 
 
 
[[NixOS_on_ARM/Raspberry_Pi_3#Board-specific_installation_notes|Raspberry Pi 3#Board-specific installation notes]]
 
 
 
=== Raspberry Pi 4B ===
 
Support for the Pi 4 in nixpkgs is still experimental. These configurations will boot (from [https://github.com/NixOS/nixpkgs/pull/68265#issuecomment-532040372 this PR comment]):
 
 
 
Until the generic image works, a [https://hydra.nixos.org/job/nixos/trunk-combined/nixos.sd_image_raspberrypi4.aarch64-linux temporary device-specific image is build on Hydra]. Note that this image is not using u-boot, but rather the Raspberry Pi specific bootloader configuration.
 
 
 
The following configuration samples are built on the assumption that they are added to a configuration generated using <code>nixos-generate-config</code>.
 
 
 
==== Without GPU ====
 
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
 
{ pkgs, ... }:
 
 
 
{
 
  networking.wireless.enable = false;
 
  services.xserver = {
 
    enable = true;
 
    displayManager.slim.enable = true;
 
    desktopManager.gnome3.enable = true;
 
    videoDrivers = [ "fbdev" ];
 
  };
 
}
 
</nowiki>}}
 
 
 
==== With GPU ====
 
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
 
{ pkgs, ... }:
 
 
 
{
 
  networking.wireless.enable = false;
 
  hardware.opengl = {
 
    enable = true;
 
    setLdLibraryPath = true;
 
    package = pkgs.mesa_drivers;
 
  };
 
  hardware.deviceTree = {
 
    base = pkgs.device-tree_rpi;
 
    overlays = [ "${pkgs.device-tree_rpi.overlays}/vc4-fkms-v3d.dtbo" ];
 
  };
 
  services.xserver = {
 
    enable = true;
 
    displayManager.slim.enable = true;
 
    desktopManager.gnome3.enable = true;
 
    videoDrivers = [ "modesetting" ];
 
  };
 
 
 
  boot.loader.raspberryPi.firmwareConfig = ''
 
    gpu_mem=192
 
  '';
 
}
 
</nowiki>}}
 
 
 
==== Tools ====
 
 
 
The raspberry tools are available in the <code>raspberrypi-tools</code> package and include commands like <code>vcgencmd</code> to measure temperature and CPU frequency.
 
 
 
==== Audio ====
 
 
 
In addition to the usual config, you will need to enable audio support explicitly in the firmwareConfig.
 
 
 
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
 
  sound.enable = true;
 
  hardware.pulseaudio.enable = true;
 
 
 
  boot.loader.raspberryPi.firmwareConfig = ''
 
    dtparam=audio=on
 
  '';
 
</nowiki>}}
 
 
 
== Serial console==
 
 
 
Your <code>configuration.nix</code> will need to add <code>console=ttyS1,115200n8</code> to the <code>boot.kernelParams</code> configuration to use the serial console.
 
 
 
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
 
{ config, pkgs, lib, ... }:
 
{
 
  boot.kernelParams = [
 
    "console=ttyS1,115200n8"
 
  ];
 
}
 
</nowiki>}}
 
 
 
If the Raspberry Pi downstream kernel is used the serial interface is named <code>serial0</code> instead.
 
 
 
== Bluetooth ==
 
 
 
The bluetooth controller is by default connected to the UART device at <code>/dev/ttyAMA0</code> and needs to be enabled through <code>btattach</code>:
 
 
 
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
 
{ pkgs, ... }:
 
{
 
  systemd.services.btattach = {
 
    before = [ "bluetooth.service" ];
 
    after = [ "dev-ttyAMA0.device" ];
 
    wantedBy = [ "multi-user.target" ];
 
    serviceConfig = {
 
      ExecStart = "${pkgs.bluez}/bin/btattach -B /dev/ttyAMA0 -P bcm -S 3000000";
 
    };
 
  };
 
}
 
</nowiki>}}
 
 
 
== Camera ==
 
 
 
For the camera to work, you will need to add the following code to your configuration.nix:
 
 
 
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
 
{ config, pkgs, lib, ... }:
 
{
 
  boot.loader.raspberryPi.enable = true;
 
  # Set the version depending on your raspberry pi.
 
  boot.loader.raspberryPi.version = 3;
 
  # We need uboot
 
  boot.loader.raspberryPi.uboot.enable = true;
 
  # These two parameters are the important ones to get the
 
  # camera working. These will be appended to /boot/config.txt.
 
  boot.loader.raspberryPi.firmwareConfig = ''
 
    start_x=1
 
    gpu_mem=256
 
  '';
 
}
 
</nowiki>}}
 
{{note| A reboot is required to load the new firmware configuration.}}
 
 
 
To make the camera available as v4l device under <code>/dev/video0</code> the <code>bcm2835-v4l2</code> kernel module need to be loaded. This can be done by adding the following code to your configuration.nix:
 
 
 
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
 
{ config, pkgs, lib, ... }:
 
{
 
  boot.kernelModules = [ "bcm2835-v4l2" ];
 
}
 
</nowiki>}}
 
== Binary Cache ==
 
 
 
Depending on the architecture used, binary caches availability varies. Binary caches instructions are on the main [[NixOS on ARM#Binary cache|NixOS on ARM]] page. The following table describes the architectures supported by each board.
 
 
 
{|class="wikitable"
 
|-
 
! Raspberry Pi 1
 
| armv6
 
|-
 
! Raspberry Pi 2
 
| armv7
 
|-
 
!rowspan="2" style="vertical-align: middle;"|Raspberry Pi 3
 
| armv7
 
|-
 
| AArch64
 
|-
 
!rowspan="2" style="vertical-align: middle;"|Raspberry Pi 4
 
| armv7
 
|-
 
| AArch64
 
|}
 
 
 
== Notes about the boot process ==
 
 
 
It takes approximately 1 minute to boot a Pi 3B.
 
 
 
=== Raspberry Pi (all versions) ===
 
 
 
USB keyboards and HDMI displays should work, though some issues have been reported (see Troubleshooting below).
 
 
 
Using the 3.3v serial port via the pin headers (exact location depends on hardware version) will get u-boot output and, when configured, a Linux kernel console.
 
 
 
== Troubleshooting ==
 
 
 
=== Power issues ===
 
 
 
Especially with the power-hungry Raspberry Pi 3, it is important to have a [https://www.raspberrypi.org/documentation/hardware/raspberrypi/power/README.md sufficient enough power supply] or ''weirdness'' may happen. Weirdness may include:
 
 
 
* Lightning bolt on HDMI output "breaking" the display.
 
* Screen switching back to u-boot text
 
** Fixable temporarily when power is sufficient by switching VT (alt+F2 / alt+F1)
 
* Random hangs
 
 
 
This problem is a hard problem. It is caused by the Raspberry Pi warning about power issues, but the current drivers (as of
 
Linux 4.14) have a hard time dealing with it properly. If the power supply is rated properly AND the cable is not incurring too much power losses, it may be required to disable the lightning bolt indicator so the display driver isn't messed up.<ref>https://logs.nix.samueldr.com/nixos/2017-12-20#1513784657-1513784714;</ref> The lightning bolt indicator can be disabled by adding the line <code>avoid_warnings=1</code> in config.txt<ref>https://www.raspberrypi.org/documentation/configuration/config-txt/README.md</ref>
 
 
 
{{note|A ''properly rated'' USB power supply, AND a good cable are necessary. The cable has to be short enough to not incur power losses through the length. Do note that thin and cheap cables usually have thinner copper wires, which in turn accentuates power losses.}}
 
 
 
===WiFi / WLAN===
 
For a possible solution to 802.11 wireless connectivity issues, see: https://github.com/NixOS/nixpkgs/issues/82462#issuecomment-604634627
 
 
 
===HDMI===
 
 
 
HDMI issues have been observed on the 18.09 AArch64 image. The display would hang on "Starting Kernel...", then act as if the HDMI cable was unplugged. Re-plugging the HDMI cable after boot fixed the issue, as did a different monitor and HDMI cable.
 
 
 
==== Early boot messages ====
 
 
 
To show boot messages from initrd with the mainline kernel, add this to <code>configuration.nix</code>.
 
 
 
<syntaxhighlight lang=nix>
 
{
 
  boot.initrd.kernelModules = [ "vc4" "bcm2835_dma" "i2c_bcm2835" ];
 
}
 
</syntaxhighlight>
 
 
 
=== Raspberry Pi 3B+ HDMI output issues ===
 
 
 
As of 2019/08/19, the u-boot build and kernel build can disagree about the name of the dtb file for the Raspberry Pi 3B+. This happens because the upstream filename has changed, and the built u-boot has hardcoded expectations for the filename to load.
 
 
 
For now, do not use <tt>linuxPackages_latest</tt>, use the default <tt>linuxPackages</tt> which is the latest LTS, 4.19, which is known to be compatible.
 
 
 
See {{issue|66960}}.
 
 
 
===Additional Troubleshooting===
 
 
 
Additional troubleshooting information may be found [https://elinux.org/R-Pi_Troubleshooting at elinux.org].
 
 
 
<hr />
 

Latest revision as of 10:56, 6 April 2024

This page has been moved to the official NixOS Wiki:

    ⇒ NixOS on ARM/Raspberry Pi

— samueldr, Lead of NixOS on ARM.