1{ lib
2, stdenv
3, fetchurl
4, acl
5, cyrus_sasl
6, docbook_xsl
7, libepoxy
8, gettext
9, gobject-introspection
10, gst_all_1
11, gtk-doc
12, gtk3
13, hwdata
14, json-glib
15, libcacard
16, libcap_ng
17, libdrm
18, libjpeg_turbo
19, libopus
20, libsoup_3
21, libusb1
22, lz4
23, meson
24, mesonEmulatorHook
25, ninja
26, openssl
27, perl
28, phodav
29, pixman
30, pkg-config
31, polkit
32, python3
33, spice-protocol
34, usbredir
35, vala
36, wayland-protocols
37, wayland-scanner
38, zlib
39, withPolkit ? stdenv.isLinux
40}:
41
42# If this package is built with polkit support (withPolkit=true),
43# usb redirection requires spice-client-glib-usb-acl-helper to run setuid root.
44# The helper confirms via polkit that the user has an active session,
45# then adds a device acl entry for that user.
46# Example NixOS config to create a setuid wrapper for the helper:
47# security.wrappers.spice-client-glib-usb-acl-helper.source =
48# "${pkgs.spice-gtk}/bin/spice-client-glib-usb-acl-helper";
49# On non-NixOS installations, make a setuid copy of the helper
50# outside the store and adjust PATH to find the setuid version.
51
52# If this package is built without polkit support (withPolkit=false),
53# usb redirection requires read-write access to usb devices.
54# This can be granted by adding users to a custom group like "usb"
55# and using a udev rule to put all usb devices in that group.
56# Example NixOS config:
57# users.groups.usb = {};
58# users.users.dummy.extraGroups = [ "usb" ];
59# services.udev.extraRules = ''
60# KERNEL=="*", SUBSYSTEMS=="usb", MODE="0664", GROUP="usb"
61# '';
62
63stdenv.mkDerivation rec {
64 pname = "spice-gtk";
65 version = "0.42";
66
67 outputs = [ "out" "dev" "devdoc" "man" ];
68
69 src = fetchurl {
70 url = "https://www.spice-space.org/download/gtk/${pname}-${version}.tar.xz";
71 sha256 = "sha256-k4ARfxgRrR+qGBLLZgJHm2KQ1KDYzEQtREJ/f2wOelg=";
72 };
73
74 depsBuildBuild = [
75 pkg-config
76 ];
77
78 nativeBuildInputs = [
79 docbook_xsl
80 gettext
81 gobject-introspection
82 gtk-doc
83 meson
84 ninja
85 perl
86 pkg-config
87 python3
88 python3.pkgs.pyparsing
89 python3.pkgs.six
90 vala
91 ] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
92 mesonEmulatorHook
93 ] ++ lib.optionals stdenv.isLinux [
94 wayland-scanner
95 ];
96
97 propagatedBuildInputs = [
98 gst_all_1.gst-plugins-base
99 gst_all_1.gst-plugins-good
100 ];
101
102 buildInputs = [
103 cyrus_sasl
104 libepoxy
105 gtk3
106 json-glib
107 libcacard
108 libjpeg_turbo
109 libopus
110 libsoup_3
111 libusb1
112 lz4
113 openssl
114 phodav
115 pixman
116 spice-protocol
117 usbredir
118 vala
119 zlib
120 ] ++ lib.optionals withPolkit [
121 polkit
122 acl
123 ] ++ lib.optionals stdenv.isLinux [
124 libcap_ng
125 libdrm
126 wayland-protocols
127 ];
128
129 PKG_CONFIG_POLKIT_GOBJECT_1_POLICYDIR = "${placeholder "out"}/share/polkit-1/actions";
130
131 mesonFlags = [
132 "-Dusb-acl-helper-dir=${placeholder "out"}/bin"
133 "-Dusb-ids-path=${hwdata}/share/hwdata/usb.ids"
134 ] ++ lib.optionals (!withPolkit) [
135 "-Dpolkit=disabled"
136 ] ++ lib.optionals (!stdenv.isLinux) [
137 "-Dlibcap-ng=disabled"
138 "-Degl=disabled"
139 ] ++ lib.optionals stdenv.hostPlatform.isMusl [
140 "-Dcoroutine=gthread" # Fixes "Function missing:makecontext"
141 ];
142
143 postPatch = ''
144 # get rid of absolute path to helper in store so we can use a setuid wrapper
145 substituteInPlace src/usb-acl-helper.c \
146 --replace 'ACL_HELPER_PATH"/' '"'
147 # don't try to setcap/suid in a nix builder
148 substituteInPlace src/meson.build \
149 --replace "meson.add_install_script('../build-aux/setcap-or-suid'," \
150 "# meson.add_install_script('../build-aux/setcap-or-suid',"
151
152 patchShebangs subprojects/keycodemapdb/tools/keymap-gen
153 '';
154
155 meta = with lib; {
156 description = "GTK 3 SPICE widget";
157 longDescription = ''
158 spice-gtk is a GTK 3 SPICE widget. It features glib-based
159 objects for SPICE protocol parsing and a gtk widget for embedding
160 the SPICE display into other applications such as virt-manager.
161 Python bindings are available too.
162 '';
163
164 homepage = "https://www.spice-space.org/";
165 license = licenses.lgpl21;
166 maintainers = [ maintainers.xeji ];
167 platforms = platforms.unix;
168 };
169}