about summary refs log tree commit diff
path: root/pkgs/by-name/st/streamdeck-ui/package.nix
blob: 4af7ad66c789828a1d3c0b1937e9d10d2753991f (plain) (blame)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
{
  copyDesktopItems,
  fetchFromGitHub,
  fetchPypi,
  lib,
  makeDesktopItem,
  python3Packages,
  qt6,
  wrapGAppsHook3,
  writeText,
  xvfb-run,
}:

let
  # There are breaking changes between 6 and 7
  importlib-metadata_6 = python3Packages.importlib-metadata.overrideAttrs (_: rec {
    version = "6.9.0";
    src = fetchPypi {
      pname = "importlib_metadata";
      inherit version;
      hash = "sha256-6Ky1I8M1qRgiZ04Um0bAOZ7E0yjE0fbknCc9pf8CAbk=";
    };
  });
in

python3Packages.buildPythonApplication rec {
  pname = "streamdeck-ui";
  version = "4.1.2";

  src = fetchFromGitHub {
    repo = "streamdeck-linux-gui";
    owner = "streamdeck-linux-gui";
    rev = "v${version}";
    hash = "sha256-CSsFPGnKVQUCND6YOA9kfO41KS85C57YL9LcrWlQRKo=";
  };

  format = "pyproject";

  pythonRelaxDeps = [ "pillow" ];

  nativeBuildInputs = [
    python3Packages.poetry-core
    python3Packages.pythonRelaxDepsHook
    copyDesktopItems
    qt6.wrapQtAppsHook
    wrapGAppsHook3
  ];

  propagatedBuildInputs =
    with python3Packages;
    [
      setuptools
      filetype
      cairosvg
      pillow
      pynput
      pyside6
      streamdeck
      xlib
      importlib-metadata_6
      evdev
    ]
    ++ lib.optionals stdenv.isLinux [ qt6.qtwayland ];

  nativeCheckInputs =
    [ xvfb-run ]
    ++ (with python3Packages; [
      pytest
      pytest-qt
      pytest-mock
    ]);

  checkPhase = ''
    runHook preCheck

    # The tests needs to find the log file
    export STREAMDECK_UI_LOG_FILE=$(pwd)/.streamdeck_ui.log
    xvfb-run pytest tests

    runHook preCheck
  '';

  postInstall =
    let
      udevRules = ''
        SUBSYSTEM=="usb", ATTRS{idVendor}=="0fd9", TAG+="uaccess"
      '';
    in
    ''
      mkdir -p $out/lib/systemd/user
      substitute scripts/streamdeck.service $out/lib/systemd/user/streamdeck.service \
        --replace '<path to streamdeck>' $out/bin/streamdeck

      mkdir -p "$out/etc/udev/rules.d"
      cp ${writeText "70-streamdeck.rules" udevRules} $out/etc/udev/rules.d/70-streamdeck.rules

      mkdir -p "$out/share/pixmaps"
      cp streamdeck_ui/logo.png $out/share/pixmaps/streamdeck-ui.png
    '';

  desktopItems =
    let
      common = {
        name = "streamdeck-ui";
        desktopName = "Stream Deck UI";
        icon = "streamdeck-ui";
        exec = "streamdeck";
        comment = "UI for the Elgato Stream Deck";
        categories = [ "Utility" ];
      };
    in
    builtins.map makeDesktopItem [
      common
      (
        common
        // {
          name = "${common.name}-noui";
          exec = "${common.exec} --no-ui";
          noDisplay = true;
        }
      )
    ];

  dontWrapQtApps = true;
  dontWrapGApps = true;
  makeWrapperArgs = [
    "\${qtWrapperArgs[@]}"
    "\${gappsWrapperArgs[@]}"
  ];

  meta = {
    description = "Linux compatible UI for the Elgato Stream Deck";
    downloadPage = "https://github.com/streamdeck-linux-gui/streamdeck-linux-gui/";
    homepage = "https://streamdeck-linux-gui.github.io/streamdeck-linux-gui/";
    license = lib.licenses.mit;
    mainProgram = "streamdeck";
    maintainers = with lib.maintainers; [ majiir ];
  };
}