NixOS on ARM/Raspberry Pi 4: Difference between revisions

imported>Fuu0
m removed unrelated config, updated infos based on a long debugging session...
imported>Valodim
add some usage info on HDMI-CEC
Line 205: Line 205:


</nowiki>}}
</nowiki>}}
=== HDMI-CEC ===
A few bits and pieces for using HDMI-CEC on the Pi4:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{ pkgs, ... }:
{
  # an overlay to enable raspberrypi support in libcec, and thus cec-client
  nixpkgs.overlays = [
    (self: super: { libcec = super.libcec.override { inherit (self) libraspberrypi; }; })
  ];
  # install libcec, which includes cec-client (requires root or "video" group, see udev rule below)
  # scan for devices: `echo 'scan' | cec-client -s -d 1`
  # set pi as active source: `echo 'as' | cec-client -s -d 1`
  environment.systemPackages = with pkgs; [
    libcec
  ];
  services.udev.extraRules = ''
    # allow access to raspi cec device for video group (and optionally register it as a systemd device, used below)
    SUBSYSTEM=="vchiq", GROUP="video", MODE="0660", TAG+="systemd"
  '';
  # 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`
  # set pi as active source: `echo 'as' > /run/cec.fifo`
  systemd.sockets."cec-client" = {
    after = [ "sys-devices-platform-soc-fe00b840.mailbox-vchiq-vchiq.device" ];
    bindsTo = [ "sys-devices-platform-soc-fe00b840.mailbox-vchiq-vchiq.device" ];
    wantedBy = [ "sockets.target" ];
    socketConfig = {
      ListenFIFO = "/run/cec.fifo";
      SocketGroup = "video";
      SocketMode = "0660";
    };
  };
  systemd.services."cec-client" = {
    after = [ "sys-devices-platform-soc-fe00b840.mailbox-vchiq-vchiq.device" ];
    bindsTo = [ "sys-devices-platform-soc-fe00b840.mailbox-vchiq-vchiq.device" ];
    wantedBy = [ "multi-user.target" ];
    serviceConfig = {
      ExecStart = ''${pkgs.libcec}/bin/cec-client -d 1'';
      ExecStop = ''/bin/sh -c "echo q > /run/cec.fifo"'';
      StandardInput = "socket";
      StandardOutput = "journal";
      Restart="no";
  };
}
</nowiki>}}
== Notes about the boot process ==
== Notes about the boot process ==