NixOS on ARM/Raspberry Pi 5: Difference between revisions

DoggoBit (talk | contribs)
No edit summary
 
(4 intermediate revisions by one other user not shown)
Line 78: Line 78:
=== Step 1: Building the SD Image ===
=== Step 1: Building the SD Image ===
{{Note|It might be possible to do the following steps via the official SD installer as well. If you manage to do it, please mark this section as optional and remove this notice.}}The project provides build images as well, which are modified versions of the nix-hardware ones. Before getting into building one, in order to make use of the community binary caches, and potentially avoid rebuilding the image, make sure you are added to the trusted users in your own nix configuration:
{{Note|It might be possible to do the following steps via the official SD installer as well. If you manage to do it, please mark this section as optional and remove this notice.}}The project provides build images as well, which are modified versions of the nix-hardware ones. Before getting into building one, in order to make use of the community binary caches, and potentially avoid rebuilding the image, make sure you are added to the trusted users in your own nix configuration:
{{File|filename=nix.conf|language=conf|contents=trusted-users = username}}
{{File|||3=trusted-users = username|name=nix.conf|lang=conf}}
Or, alternatively, in your nixos configuration:
Or, alternatively, in your nixos configuration:
{{File|filename=configuration.nix|language=nix|contents={
{{File|||3={
   nix.settings.trusted-users = [ "your-username" ];
   nix.settings.trusted-users = [ "your-username" ];
<nowiki>}</nowiki>}}
<nowiki>}</nowiki>|name=configuration.nix|lang=nix}}
Afterwards, you can build one of the SD images:<syntaxhighlight lang="shell">
Afterwards, you can build one of the SD images:<syntaxhighlight lang="console">
$ nix build github:nvmd/nixos-raspberrypi#installerImages.rpi5
$ nix build github:nvmd/nixos-raspberrypi#installerImages.rpi5
</syntaxhighlight>You can either [[Cross Compiling|cross-compile]] the image on your system, or alternatively, you can install the "normal" Raspberry Pi OS on your Raspberry Pi 5, then install Nix standalone (multi-user), and set it up as a [[distributed build]] machine.
</syntaxhighlight>You can either [[Cross Compiling|cross-compile]] the image on your system, or alternatively, you can install the "normal" Raspberry Pi OS on your Raspberry Pi 5, then install Nix standalone (multi-user), and set it up as a [[distributed build]] machine.


Finally, simply copy the image to the current directory from the <code>result</code> directory, extract it and write it to the SD card. You can find more information on the [[NixOS on ARM/Installation]] page.
Finally, simply copy the image to the current directory from the <code>result</code> directory, extract it and write it to a USB drive, and boot to this drive on the raspberry pi (by default the raspberry pi will first try to boot the SD card, then the USB drive, so just don't put any SD card when booting and plug it later. Note that since the installer will format the SD card, you cannot put the installer on the SD card itself). You can find more information on the [[NixOS on ARM/Installation]] page.


=== Step 2: Installing NixOS ===
=== Step 2: Installing NixOS ===


Once you're running an installer image, you can create a flake referencing the repository. For example:{{File|filename=flake.nix|language=nix|contents={
Once you're running an installer image, you can create a flake referencing the repository. For example:{{File|3={
   description = "Example Raspberry Pi 5 configuration flake";
   description = "Example Raspberry Pi 5 configuration flake";
     inputs = {
     inputs = {
Line 155: Line 155:
       };
       };
     };
     };
<nowiki>}</nowiki>
<nowiki>}</nowiki>|name=flake.nix|lang=nix}}Finally, simply <code>nixos-rebuild switch --flake .#yourHostname</code> the flake.
}}Finally, simply <code>nixos-rebuild switch --flake .#yourHostname</code> the flake.


== Other Solutions ==
== Other Solutions ==
Line 254: Line 253:
EDK2 enables booting a mainline kernel, but hardware support will be very limited. Notably, you'll need to perform the installation using Wi-Fi, as Ethernet is unsupported. Once the system is installed, you can switch to the vendor's modified kernel. This is not (yet?) available in Nixpkgs, so you'll need to get it from [https://gitlab.com/vriska/nix-rpi5 a flake]. If you're not using flakes, you can simply add this to your configuration:
EDK2 enables booting a mainline kernel, but hardware support will be very limited. Notably, you'll need to perform the installation using Wi-Fi, as Ethernet is unsupported. Once the system is installed, you can switch to the vendor's modified kernel. This is not (yet?) available in Nixpkgs, so you'll need to get it from [https://gitlab.com/vriska/nix-rpi5 a flake]. If you're not using flakes, you can simply add this to your configuration:


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|3=<nowiki>
{
{
   boot.kernelPackages = (import (builtins.fetchTarball https://gitlab.com/vriska/nix-rpi5/-/archive/main.tar.gz)).legacyPackages.aarch64-linux.linuxPackages_rpi5;
   boot.kernelPackages = (import (builtins.fetchTarball https://gitlab.com/vriska/nix-rpi5/-/archive/main.tar.gz)).legacyPackages.aarch64-linux.linuxPackages_rpi5;
}
}
</nowiki>}}
</nowiki>|name=configuration.nix|lang=nix}}


For the vendor kernel to boot properly, you must switch from ACPI to Device Tree in the UEFI settings (at Device Manager → Raspberry Pi Configuration → ACPI / Device Tree → System Table Mode). When using the vendor kernel (which provides full power management support), you may additionally wish to remove <code>force_turbo=1</code> from <code>/boot/config.txt</code>.
For the vendor kernel to boot properly, you must switch from ACPI to Device Tree in the UEFI settings (at Device Manager → Raspberry Pi Configuration → ACPI / Device Tree → System Table Mode). When using the vendor kernel (which provides full power management support), you may additionally wish to remove <code>force_turbo=1</code> from <code>/boot/config.txt</code>.


If you are using nixos-unstable, then you can also use the rpi4 kernel (which is a generic aarch64 kernel for Pi 3 and later models). Although, due to a smaller page size, this will have slightly worse performance:
If you are using nixos-unstable, then you can also use the rpi4 kernel (which is a generic aarch64 kernel for Pi 3 and later models). Although, due to a smaller page size, this will have slightly worse performance:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|||<nowiki>
{
{
   boot.kernelPackages = pkgs.linuxPackages_rpi4;
   boot.kernelPackages = pkgs.linuxPackages_rpi4;
}
}
</nowiki>}}
</nowiki>|name=configuration.nix|lang=nix}}


==== Troubleshooting ====
==== Troubleshooting ====
Line 278: Line 277:
===== Bluetooth =====
===== Bluetooth =====


If your Bluetooth doesn't show up, and you are getting errors in dmesg regarding the serial port at 107050c00, add the following to your NixOS configuration:{{file|/etc/nixos/configuration.nix|nix|<nowiki>
If your Bluetooth doesn't show up, and you are getting errors in dmesg regarding the serial port at 107050c00, add the following to your NixOS configuration:{{file|||<nowiki>
{
{
   boot.kernelParams = [ "8250.nr_uarts=11" "console=ttyAMA10,9600" "console=tty0"];
   boot.kernelParams = [ "8250.nr_uarts=11" "console=ttyAMA10,9600" "console=tty0"];
}
}
</nowiki>}}
</nowiki>|name=configuration.nix|lang=nix}}


==== Using the Pi 5 as a remote builder to build native ARM packages for the Pi 5 ====
==== Using the Pi 5 as a remote builder to build native ARM packages for the Pi 5 ====