summary refs log tree commit diff
path: root/modules/klipperscreen.nix
blob: d4d9bfa3e9eb2663f5b3b0854fcfb9500e5130a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{ config, pkgs, ... }:

let
  inherit (pkgs) writeText klipperscreen;

  ksConfig =
    let
      inherit (config.services.moonraker) address port;
    in
    writeText "KlipperScreen.conf" ''
      [printer fourmi]
      moonraker_host: ${address}
      moonraker_port: ${toString port}
    '';
in
{
  # avoid conflict between console and cage.
  console.enable = false;

  # without this the kiosk doesn't even want to get loaded :)
  systemd.defaultUnit = "graphical.target";

  services.cage = {
    enable = true;

    program = "${klipperscreen}/bin/KlipperScreen -c ${ksConfig}";
    extraArguments = [ "-d" ];

    environment = {
      # don't fail with no devices found.
      "WLR_LIBINPUT_NO_DEVICES" = "1";

      # render onto the SPI panel (see modules/hardware/ili9486.nix), not
      # the firmware/HDMI framebuffer. by-path is stable across boots,
      # unlike cardN numbering.
      "WLR_DRM_DEVICES" = "/dev/dri/by-path/platform-fe204000.spi-cs-0-card";

      # the SPI panel has no GPU render node, so GLES cannot initialize;
      # software rendering into dumb buffers works fine at 480x320.
      "WLR_RENDERER" = "pixman";
    };
    user = "klipper";
  };

  # auto-restart cage.
  systemd.services."cage-tty1" = {
    startLimitBurst = 5;
    startLimitIntervalSec = 500;

    serviceConfig = {
      RestartSec = 5;
      Restart = "on-failure";
    };
  };
}