-
Notifications
You must be signed in to change notification settings - Fork 1
/
default.nix
188 lines (159 loc) · 4.76 KB
/
default.nix
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
{ stdenv, lib, pkgs, fetchurl
# Native build inputs
, autoPatchelfHook, wrapGAppsHook, makeWrapper
# Build inputs
, zlib, xorg, alsa-lib, libbsd, libopus, openssl, libva, pango, cairo, libuuid, nspr
, nss, cups, expat, atk, at-spi2-atk, gtk3, gdk-pixbuf, libsecret, systemd
, pulseaudio, libGL, dbus, libnghttp2, libidn2, libpsl, libkrb5, openldap
, rtmpdump, libinput, mesa, libpulseaudio, libvdpau, curl
# Which distribution channel to use.
, channel ? "prod"
# Whether to enable debug mode.
, enableDiagnostics ? false
# Which additional parameters to pass to the Shadow executable.
, extraClientParameters ? []
# Whether to provide the desktop file to launch Shadow.
, enableDesktopLauncher ? true
}:
let
# Import tools
debug = (import ./debug.nix { inherit lib pkgs; });
# Latest release information
upstream-info = (lib.importJSON ./upstream-info.json).${channel};
iconName = (if channel == "prod" then "shadow" else "shadow-${channel}");
in stdenv.mkDerivation rec {
pname = "shadow-${channel}";
version = upstream-info.version;
src = fetchurl {
url = "https://update.shadow.tech/launcher/${channel}/linux/ubuntu_18.04/${upstream-info.path}";
hash = "sha512-${upstream-info.sha512}";
};
# Add all hooks
nativeBuildInputs = [
autoPatchelfHook
wrapGAppsHook
makeWrapper
];
# Useful libraries to build the package
buildInputs = [
stdenv.cc.cc.lib
xorg.libX11
xorg.libxcb
xorg.libXrandr
xorg.libXcomposite
xorg.libXdamage
xorg.libXScrnSaver
xorg.libXcursor
xorg.libXfixes
xorg.libXi
xorg.libXtst
xorg.xcbutilimage
xorg.xcbutilrenderutil
xorg.libxshmfence
cairo
pango
alsa-lib
libbsd
libopus
libinput
openssl
libva
zlib
libuuid
nspr
nss
cups
expat
atk
at-spi2-atk
gtk3
gdk-pixbuf
libnghttp2
libidn2
libpsl
libkrb5
openldap
rtmpdump
mesa
libpulseaudio
libvdpau
curl
];
# Mandatory libraries for the runtime
runtimeDependencies = [
stdenv.cc.cc.lib
systemd
libinput
pulseaudio
libGL
dbus
libsecret
xorg.libXinerama
libva
];
# Unpack the AppImage
unpackPhase = ''
cp $src ./Shadow.AppImage
chmod 777 ./Shadow.AppImage
patchelf \
--set-interpreter ${stdenv.cc.bintools.dynamicLinker} \
--replace-needed libz.so.1 ${zlib}/lib/libz.so.1 \
./Shadow.AppImage
./Shadow.AppImage --appimage-extract
rm ./Shadow.AppImage
'';
# Create the package
installPhase =
''
mkdir -p $out/opt
mkdir -p $out/lib
mv ./squashfs-root/usr/share $out/
mkdir -p $out/share/applications
ln -s ${lib.getLib systemd}/lib/libudev.so.1 $out/lib/libudev.so.1
rm -r ./squashfs-root/usr/lib
rm ./squashfs-root/AppRun
mv ./squashfs-root $out/opt/shadow-${channel}
'' +
# Add debug wrapper
lib.optionalString enableDiagnostics (debug.wrapRenderer channel) +
# Wrap renderer
''
wrapProgram $out/opt/shadow-${channel}/resources/app.asar.unpacked/release/native/ShadowPCDisplay \
--run "cd $out/opt/shadow-${channel}/resources/app.asar.unpacked/release/native/" \
--prefix LD_LIBRARY_PATH : "$out/opt/shadow-${channel}" \
--prefix LD_LIBRARY_PATH : "$out/lib" \
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath runtimeDependencies} \
--add-flags "--no-usb" \
--add-flags "--agent \"Linux;x64;Chrome 80.0.3987.165;latest\"" \
${lib.concatMapStrings (x: " --add-flags '" + x + "'") extraClientParameters}
''
# Wrap Renderer into binary
+ ''
makeWrapper \
$out/opt/shadow-${channel}/resources/app.asar.unpacked/release/native/ShadowPCDisplay \
$out/bin/shadow-${channel}-renderer \
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath runtimeDependencies}
''
# Wrap launcher
+ ''
makeWrapper $out/opt/shadow-${channel}/shadow-launcher $out/bin/shadow-${channel} \
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath runtimeDependencies}
''
# Add Desktop entry
+ lib.optionalString enableDesktopLauncher ''
substitute $out/opt/shadow-${channel}/shadow-launcher.desktop \
$out/share/applications/shadow-launcher.desktop \
--replace "Exec=AppRun" "Exec=$out/bin/shadow-${channel}" \
--replace "Icon=shadow-launcher" "Icon=$out/opt/shadow-${channel}/resources/app.asar.unpacked/release/main/assets/icons/${channel}/${iconName}.png"
'';
passthru = {
updateScript = ./update.py;
};
meta = with lib; {
description = "Client for the Shadow Cloud Gaming Computer";
homepage = "https://shadow.tech";
license = [ licenses.unfree ];
maintainers = with maintainers; [ anthonyroussel ];
platforms = platforms.linux;
};
}