Jump to content

NixOS on ARM/Raspberry Pi 4: Difference between revisions

Added instructions for getting bluetooth atleast usable
imported>Christoph-heiss
m (fix angle brackets in code sample)
(Added instructions for getting bluetooth atleast usable)
 
(3 intermediate revisions by 3 users not shown)
Line 138: Line 138:
   hardware.pulseaudio.enable = true;
   hardware.pulseaudio.enable = true;
   hardware.raspberry-pi."4".audio.enable = true;
   hardware.raspberry-pi."4".audio.enable = true;
</nowiki>}}
For audio through hdmi:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
  sound.enable = true;
  hardware.pulseaudio.enable = true;
  boot.kernelParams = [
"snd_bcm2835.enable_hdmi=1"];
</nowiki>}}
</nowiki>}}


Line 173: Line 182:


To enable the SPI, you would normally add <code>dtparam=spi=on</code> to <code>/boot/config.txt</code>.
To enable the SPI, you would normally add <code>dtparam=spi=on</code> to <code>/boot/config.txt</code>.
This is not possbible on NixOS, and instead you have to apply a device tree overlay.
This is not possible on NixOS, and instead you have to apply a device tree overlay.
For this we use the <code>hardware.deviceTree.overlays</code> option.
For this we use the <code>hardware.deviceTree.overlays</code> option.
After applying the overlay, we add an <code>spi</code> group and change the owner of the <code>spidev</code> device to it, similarly to [[#Using GPIO pins as non root |GPIO]].
After applying the overlay, we add an <code>spi</code> group and change the owner of the <code>spidev</code> device to it, similarly to [[#Using GPIO pins as non root |GPIO]].
Line 229: Line 238:


   # optional: attach a persisted cec-client to `/run/cec.fifo`, to avoid the CEC ~1s startup delay per command
   # optional: attach a persisted cec-client to `/run/cec.fifo`, to avoid the CEC ~1s startup delay per command
   # scan for devices: `echo 'scan' > /run/cec.fifo ; journalctl -u cec-client.service`
   # scan for devices: `echo 'scan' </nowiki>><nowiki> /run/cec.fifo ; journalctl -u cec-client.service`
   # set pi as active source: `echo 'as' > /run/cec.fifo`
   # set pi as active source: `echo 'as' </nowiki>><nowiki> /run/cec.fifo`
   systemd.sockets."cec-client" = {
   systemd.sockets."cec-client" = {
     after = [ "dev-vchiq.device" ];
     after = [ "dev-vchiq.device" ];
Line 247: Line 256:
     serviceConfig = {
     serviceConfig = {
       ExecStart = ''${pkgs.libcec}/bin/cec-client -d 1'';
       ExecStart = ''${pkgs.libcec}/bin/cec-client -d 1'';
       ExecStop = ''/bin/sh -c "echo q > /run/cec.fifo"'';
       ExecStop = ''/bin/sh -c "echo q </nowiki>><nowiki> /run/cec.fifo"'';
       StandardInput = "socket";
       StandardInput = "socket";
       StandardOutput = "journal";
       StandardOutput = "journal";
Line 253: Line 262:
   };
   };
}
}
</nowiki>}}
=== Enabling Bluetooth ===
One might get bluetooth to work with this in the configuration file:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
  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>}}
</nowiki>}}


Line 272: Line 295:


On the Raspberry Pi kernel, the jack may never play audio, and no Bluetooth devices may ever be found. To get this to work, it is recommended to switch to the mainline kernel. See [https://github.com/NixOS/nixpkgs/issues/123725 nixpkgs#123725] for more info.
On the Raspberry Pi kernel, the jack may never play audio, and no Bluetooth devices may ever be found. To get this to work, it is recommended to switch to the mainline kernel. See [https://github.com/NixOS/nixpkgs/issues/123725 nixpkgs#123725] for more info.
=== Touch screen not working ===
You have to declare this in your <code>configuration.nix</code><ref>https://discourse.nixos.org/t/cant-get-nixos-x-to-work-on-a-raspberry-pi-with-dsi-display/44532/3</ref>:<syntaxhighlight lang="nix">
hardware.raspberry-pi."4" = {
  touch-ft5406.enable = true;
};
</syntaxhighlight>
2

edits