1{
2 lib,
3 fetchFromGitHub,
4 flatpak,
5 fuse3,
6 bubblewrap,
7 docutils,
8 systemdMinimal,
9 geoclue2,
10 glib,
11 gsettings-desktop-schemas,
12 json-glib,
13 meson,
14 ninja,
15 nixosTests,
16 pipewire,
17 gdk-pixbuf,
18 librsvg,
19 gobject-introspection,
20 python3,
21 pkg-config,
22 stdenv,
23 runCommand,
24 wrapGAppsNoGuiHook,
25 bash,
26 dbus,
27 gst_all_1,
28 libgudev,
29 umockdev,
30 replaceVars,
31 enableGeoLocation ? true,
32 enableSystemd ? true,
33}:
34
35stdenv.mkDerivation (finalAttrs: {
36 pname = "xdg-desktop-portal";
37 version = "1.20.3";
38
39 outputs = [
40 "out"
41 "installedTests"
42 ];
43
44 src = fetchFromGitHub {
45 owner = "flatpak";
46 repo = "xdg-desktop-portal";
47 tag = finalAttrs.version;
48 hash = "sha256-ntTGEsk8GlXkp3i9RtF+T7jqnNdL2GVbu05d68WVTYc=";
49 };
50
51 patches = [
52 # The icon validator copied from Flatpak needs to access the gdk-pixbuf loaders
53 # in the Nix store and cannot bind FHS paths since those are not available on NixOS.
54 (replaceVars ./fix-icon-validation.patch {
55 inherit (builtins) storeDir;
56 })
57
58 # Same for the sound validator, except the gdk-pixbuf part.
59 (replaceVars ./fix-sound-validation.patch {
60 inherit (builtins) storeDir;
61 })
62
63 # Allow installing installed tests to a separate output.
64 ./installed-tests-path.patch
65
66 # Look for portal definitions under path from `NIX_XDG_DESKTOP_PORTAL_DIR` environment variable.
67 # While upstream has `XDG_DESKTOP_PORTAL_DIR`, it is meant for tests and actually blocks
68 # any configs from being loaded from anywhere else.
69 ./nix-pkgdatadir-env.patch
70
71 # test tries to read /proc/cmdline, which is not intended to be accessible in the sandbox
72 ./trash-test.patch
73 ];
74
75 nativeBuildInputs = [
76 docutils # for rst2man
77 glib
78 meson
79 ninja
80 pkg-config
81 wrapGAppsNoGuiHook
82 ];
83
84 buildInputs = [
85 flatpak
86 fuse3
87 bubblewrap
88 glib
89 gsettings-desktop-schemas
90 json-glib
91 pipewire
92 gst_all_1.gst-plugins-base
93 libgudev
94
95 # For icon validator
96 gdk-pixbuf
97 librsvg
98 bash
99 ]
100 ++ lib.optionals enableGeoLocation [
101 geoclue2
102 ]
103 ++ lib.optionals enableSystemd [
104 systemdMinimal # libsystemd
105 ];
106
107 nativeCheckInputs = [
108 dbus
109 gdk-pixbuf
110 gst_all_1.gstreamer
111 gst_all_1.gst-plugins-good
112 gobject-introspection
113
114 # NB: this Python is used both for build-time tests
115 # and for installed (VM) tests, so it includes dependencies
116 # for both
117 (python3.withPackages (ps: [
118 ps.pytest
119 ps.python-dbusmock
120 ps.pygobject3
121 ps.dbus-python
122 ]))
123 umockdev
124 ];
125
126 checkInputs = [ umockdev ];
127
128 mesonFlags = [
129 "--sysconfdir=/etc"
130 "-Dinstalled-tests=true"
131 "-Dinstalled_test_prefix=${placeholder "installedTests"}"
132 "-Ddocumentation=disabled" # pulls in a whole lot of extra stuff
133 (lib.mesonEnable "systemd" enableSystemd)
134 ]
135 ++ lib.optionals (!enableGeoLocation) [
136 "-Dgeoclue=disabled"
137 ]
138 ++ lib.optionals (!finalAttrs.finalPackage.doCheck) [
139 "-Dtests=disabled"
140 ];
141
142 strictDeps = true;
143
144 doCheck = true;
145
146 postPatch = ''
147 # until/unless bubblewrap ships a pkg-config file, meson has no way to find it when cross-compiling.
148 substituteInPlace meson.build \
149 --replace-fail "find_program('bwrap'" "find_program('${lib.getExe bubblewrap}'"
150
151 patchShebangs src/generate-method-info.py
152 patchShebangs tests/run-test.sh
153 '';
154
155 preCheck = lib.optionalString finalAttrs.finalPackage.doCheck ''
156 # For test_trash_file
157 export HOME=$(mktemp -d)
158
159 # Upstream disables a few tests in CI upstream as they are known to
160 # be flaky. Let's disable those downstream as hydra exhibits similar
161 # flakes:
162 # https://github.com/NixOS/nixpkgs/pull/270085#issuecomment-1840053951
163 export XDP_TEST_IN_CI=1
164
165 # need to set this ourselves, because the tests will set LD_PRELOAD=libumockdev-preload.so,
166 # which can't be found because it's not in default rpath
167 export LD_PRELOAD=${lib.getLib umockdev}/lib/libumockdev-preload.so
168 '';
169
170 # We can't disable the installedTests output when doCheck is disabled,
171 # because that produces an infinite recursion.
172 preFixup = lib.optionalString (!finalAttrs.finalPackage.doCheck) ''
173 mkdir $installedTests
174 '';
175
176 passthru = {
177 tests = {
178 installedTests = nixosTests.installed-tests.xdg-desktop-portal;
179
180 validate-icon = runCommand "test-icon-validation" { } ''
181 ${finalAttrs.finalPackage}/libexec/xdg-desktop-portal-validate-icon --ruleset=desktop --sandbox --path=${../../../applications/audio/zynaddsubfx/ZynLogo.svg} > "$out"
182 grep format=svg "$out"
183 '';
184 };
185 };
186
187 meta = {
188 description = "Desktop integration portals for sandboxed apps";
189 homepage = "https://flatpak.github.io/xdg-desktop-portal";
190 license = lib.licenses.lgpl2Plus;
191 maintainers = with lib.maintainers; [ jtojnar ];
192 platforms = lib.platforms.linux;
193 };
194})