NixOS on ARM/Raspberry Pi 4: Difference between revisions

imported>Samueldr
m Add detail about 5.10 LTS
imported>Samueldr
m Remove outdated and wrong information, mark some other as outdated
Line 151: Line 151:
=== USB boot ===
=== USB boot ===


For USB booting to work properly, firmware update might be needed:
For USB booting to work properly, a firmware update might be needed:


{{commands|<nowiki>
{{commands|<nowiki>
nix-shell -p raspberrypi-eeprom
$ nix-shell -p raspberrypi-eeprom
rpi-eeprom-update -d -a
$ rpi-eeprom-update -d -a
</nowiki>}}
</nowiki>}}


Line 162: Line 162:
When running from USB device without SD card present, kernel spams log about missing SD card, workaround for this is to set:
When running from USB device without SD card present, kernel spams log about missing SD card, workaround for this is to set:


{{commands|<nowiki>
{{outdated|This will only work when not using U-Boot. Configuring through an overlay will be required.}}
boot.loader.raspberryPi.firmwareConfig = "dtparam=sd_poll_once=on";
 
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{
  boot.loader.raspberryPi.firmwareConfig = "dtparam=sd_poll_once=on";
}
</nowiki>}}
</nowiki>}}
=== GPU support ===
=== GPU support ===


Line 182: Line 185:
</nowiki>}}
</nowiki>}}
==== With GPU ====
==== With GPU ====
Warning: The device tree overlays provided with the RaspberryPi Kernel don't seem to be compatible with dtc. We might need to add support for the `dtmerge` tool as an alternative, or ask upstream to fix their overlays (or dtc).


See https://github.com/NixOS/nixpkgs/pull/107637#issuecomment-752635965 for details.
In [https://github.com/NixOS/nixos-hardware/pull/261 nixos-hardware#261] a new option has been added to use the <code>fkms-3d</code> overlay. This will only work with the vendor kernel.
 
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{ pkgs, ... }:
{ pkgs, ... }:


{
{
   hardware.opengl = {
   imports = [
     enable = true;
     .../nixos-hardware/raspberry-pi/4
    setLdLibraryPath = true;
   ];
    package = pkgs.mesa_drivers;
 
   };
   hardware.raspberry-pi."4".fkms-3d.enable = true;
   hardware.deviceTree = {
 
    kernelPackage = pkgs.linux_rpi4;
    overlays = [ "${pkgs.device-tree_rpi.overlays}/vc4-fkms-v3d.dtbo" ];
  };
   services.xserver = {
   services.xserver = {
     enable = true;
     enable = true;
     displayManager.lightdm.enable = true;
     displayManager.lightdm.enable = true;
     desktopManager.gnome3.enable = true;
     desktopManager.gnome3.enable = true;
    videoDrivers = [ "modesetting" ];
   };
   };
  boot.loader.raspberryPi.firmwareConfig = ''
    gpu_mem=192
  '';
}
}
</nowiki>}}
</nowiki>}}
Line 214: Line 210:


==== Audio ====
==== Audio ====
{{outdated|An equivalent change that works with U-Boot through <code>hardware.deviceTree</code> is needed.}}


In addition to the usual config, you will need to enable audio support explicitly in the firmwareConfig.
In addition to the usual config, you will need to enable audio support explicitly in the firmwareConfig.
Line 239: Line 237:


Note that the Type-C USB receptacle for the Raspberry Pi 4B '''does not implement Power Delivery (USB PD)'''. This means that it is limited to whatever the power supply will provide when not negotiating power, which is most likely 5V at some undetermined power level.
Note that the Type-C USB receptacle for the Raspberry Pi 4B '''does not implement Power Delivery (USB PD)'''. This means that it is limited to whatever the power supply will provide when not negotiating power, which is most likely 5V at some undetermined power level.
===First Install Issues===
Make sure that you resize the <code>NIXOS_SD</code> partition and expand the filesystem so that the initial install will have enough space for the <code>/nix/store</code>. Assuming you only have the SD card plugged in:
<nowiki>
$ sudo parted resizepart 2 100%
$ sudo resize2fs /dev/disk/by-label/NIXOS_SD</nowiki>
You might also have to add the nix channels manually.
<nowiki>
$ sudo mkdir -p /nix/var/nix/profiles/per-user/root/channels/
$ nix-channel --add https://nixos.org/channels/nixos-unstable nixpkgs
$ nix-channel --update</nowiki>
Finally, the <code>nixos-install</code> program might fail to copy your <code>configuration.nix</code> and <code>hardware-configuration.nix</code> files automatically to <code>/etc/nixos/</code>. You can do this yourself by <code>sudo cp /mnt/etc/nixos/* /etc/nixos/</code>.


<hr />
<hr />