btrbk: add mainProgram
[NixPkgs.git] / pkgs / by-name / st / steamos-devkit / package.nix
blobed0e41b5f84a94e4509f96d0187e4d4846df18f9
1 { lib
2 , fetchFromGitHub
3 , fetchFromGitLab
4 , python3
5 , copyDesktopItems
6 , makeDesktopItem
7 , pkg-config
8 , SDL2
9 }:
10 let
11   # steamos-devkit requires a build of the unreleased pyimgui 2.0 branch, move to pythonPackages when 2.0 is released.
12   pyimgui = python3.pkgs.buildPythonPackage {
13     pname = "pyimgui";
14     version = "2.0.0";
16     src = fetchFromGitHub {
17       owner = "pyimgui";
18       repo = "pyimgui";
19       rev = "2.0.0";
20       fetchSubmodules = true;
21       sha256 = "sha256-sw/bLTdrnPhBhrnk5yyXCbEK4kMo+PdEvoMJ9aaZbsE=";
22     };
24     nativeBuildInputs = with python3.pkgs; [
25       cython_0
26       pkg-config
27       SDL2
28     ];
30     propagatedBuildInputs = with python3.pkgs; [
31       click
32       pyopengl
33       pysdl2
34     ];
36     # Requires OpenGL acceleration
37     doCheck = false;
38     pythonImportsCheck = [ "imgui" ];
39   };
40   steamos-devkit-script = ''
41     #!${python3.interpreter}
42     import os
44     # Change the cwd to avoid imgui using cwd which often is ~ to store the state, use the same location as the settings
45     path = os.path.expanduser(os.path.join("~", ".devkit-client-gui"))
46     os.makedirs(path, exist_ok=True)
47     os.chdir(path)
49     # Workaround to get pysdl to work on wayland, remove when https://gitlab.steamos.cloud/devkit/steamos-devkit/-/issues/1 is solved.
50     if os.environ.get("XDG_SESSION_TYPE") == "wayland":
51       os.environ["SDL_VIDEODRIVER"] = "wayland"
53     import devkit_client.gui2
54     devkit_client.gui2.main()
55   '';
57 python3.pkgs.buildPythonPackage rec {
58   pname = "steamos-devkit";
59   version = "0.20240216.0";
61   src = fetchFromGitLab {
62     domain = "gitlab.steamos.cloud";
63     owner = "devkit";
64     repo = "steamos-devkit";
65     rev = "v${version}";
66     sha256 = "sha256-eOtESkGMIjcijAFITOcYKPsXH6xH/Xcj9D+OItMqebM=";
67   };
69   propagatedBuildInputs = with python3.pkgs; [
70     appdirs
71     bcrypt
72     cffi
73     cryptography
74     idna
75     ifaddr
76     netifaces
77     numpy
78     paramiko
79     pycparser
80     pyimgui
81     pynacl
82     pysdl2
83     signalslot
84     six
85   ];
87   nativeBuildInputs = [
88     copyDesktopItems
89   ];
91   postUnpack = ''
92     # Find the absolute source root to link correctly to the previous root
93     prevRoot=$(realpath $sourceRoot)
95     # Update the source root to the devkit_client package
96     sourceRoot="$sourceRoot/client"
98     # Link the setup script into the new source root
99     ln -s $prevRoot/setup/shiv-linux-setup.py $sourceRoot/setup.py
100   '';
102   postInstall = ''
103     mkdir -p $out/bin
105     # These are various assets like scripts that steamos-devkit will copy to the remote device
106     cp -R ./devkit-utils $out/${python3.sitePackages}/devkit-utils
108     # writeScript + symlink will be ignored by wrapPythonPrograms
109     # Copying it is undesirable too, just write it directly to a script instead
110     cat << EOF > $out/bin/steamos-devkit
111     ${steamos-devkit-script}
112     EOF
113     chmod +x $out/bin/steamos-devkit
114   '';
116   # There are no checks for steamos-devkit
117   doCheck = false;
118   pythonImportsCheck = [ "devkit_client" ];
120   desktopItems = [
121     (makeDesktopItem {
122       name = "SteamOS-Devkit";
123       exec = "steamos-devkit";
124       desktopName = "SteamOS Devkit Client";
125     })
126   ];
128   meta = with lib; {
129     description = "SteamOS Devkit Client";
130     mainProgram = "steamos-devkit";
131     homepage = "https://gitlab.steamos.cloud/devkit/steamos-devkit";
132     license = licenses.mit;
133     maintainers = with maintainers; [ myaats ];
134   };