dotnet: improve language coverage of passthru.tests for dotnet sdks (#370789)
[NixPkgs.git] / pkgs / development / libraries / xdg-desktop-portal / default.nix
blob79c7633a5576be5bec0a0f804d088780f6e5417a
2   lib,
3   fetchFromGitHub,
4   flatpak,
5   fuse3,
6   bubblewrap,
7   docbook_xml_dtd_412,
8   docbook_xml_dtd_43,
9   docbook_xsl,
10   docutils,
11   systemdMinimal,
12   geoclue2,
13   glib,
14   gsettings-desktop-schemas,
15   json-glib,
16   libportal,
17   libxml2,
18   meson,
19   ninja,
20   nixosTests,
21   pipewire,
22   gdk-pixbuf,
23   librsvg,
24   gobject-introspection,
25   python3,
26   pkg-config,
27   stdenv,
28   runCommand,
29   wrapGAppsHook3,
30   xmlto,
31   bash,
32   enableGeoLocation ? true,
33   enableSystemd ? true,
36 stdenv.mkDerivation (finalAttrs: {
37   pname = "xdg-desktop-portal";
38   version = "1.18.4";
40   outputs = [
41     "out"
42     "installedTests"
43   ];
45   src = fetchFromGitHub {
46     owner = "flatpak";
47     repo = "xdg-desktop-portal";
48     rev = finalAttrs.version;
49     hash = "sha256-o+aO7uGewDPrtgOgmp/CE2uiqiBLyo07pVCFrtlORFQ=";
50   };
52   patches = [
53     # The icon validator copied from Flatpak needs to access the gdk-pixbuf loaders
54     # in the Nix store and cannot bind FHS paths since those are not available on NixOS.
55     (runCommand "icon-validator.patch" { } ''
56       # Flatpak uses a different path
57       substitute "${flatpak.icon-validator-patch}" "$out" \
58         --replace "/icon-validator/validate-icon.c" "/src/validate-icon.c"
59     '')
61     # Allow installing installed tests to a separate output.
62     ./installed-tests-path.patch
64     # Look for portal definitions under path from `NIX_XDG_DESKTOP_PORTAL_DIR` environment variable.
65     # While upstream has `XDG_DESKTOP_PORTAL_DIR`, it is meant for tests and actually blocks
66     # any configs from being loaded from anywhere else.
67     ./nix-pkgdatadir-env.patch
69     # test tries to read /proc/cmdline, which is not intended to be accessible in the sandbox
70     ./trash-test.patch
72     # Install files required to be in XDG_DATA_DIR of the installed tests
73     # Merged PR https://github.com/flatpak/xdg-desktop-portal/pull/1444
74     ./installed-tests-share.patch
75   ];
77   nativeBuildInputs = [
78     docbook_xml_dtd_412
79     docbook_xml_dtd_43
80     docbook_xsl
81     docutils # for rst2man
82     libxml2
83     meson
84     ninja
85     pkg-config
86     wrapGAppsHook3
87     xmlto
88   ];
90   buildInputs =
91     [
92       flatpak
93       fuse3
94       bubblewrap
95       glib
96       gsettings-desktop-schemas
97       json-glib
98       libportal
99       pipewire
101       # For icon validator
102       gdk-pixbuf
103       librsvg
105       # For document-fuse installed test.
106       (python3.withPackages (
107         pp: with pp; [
108           pygobject3
109         ]
110       ))
111       bash
112     ]
113     ++ lib.optionals enableGeoLocation [
114       geoclue2
115     ]
116     ++ lib.optionals enableSystemd [
117       systemdMinimal # libsystemd
118     ];
120   nativeCheckInputs = [
121     gobject-introspection
122     python3.pkgs.pytest
123     python3.pkgs.python-dbusmock
124     python3.pkgs.pygobject3
125     python3.pkgs.dbus-python
126   ];
128   mesonFlags =
129     [
130       "--sysconfdir=/etc"
131       "-Dinstalled-tests=true"
132       "-Dinstalled_test_prefix=${placeholder "installedTests"}"
133       (lib.mesonEnable "systemd" enableSystemd)
134     ]
135     ++ lib.optionals (!enableGeoLocation) [
136       "-Dgeoclue=disabled"
137     ]
138     ++ lib.optionals (!finalAttrs.finalPackage.doCheck) [
139       "-Dpytest=disabled"
140     ];
142   strictDeps = true;
144   doCheck = true;
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}'"
151     # Disable test failing with libportal 0.9.0
152     ${
153       assert (lib.versionOlder finalAttrs.version "1.20.0");
154       "# TODO: Remove when updating to x-d-p 1.20.0"
155     }
156     substituteInPlace tests/test-portals.c \
157       --replace-fail 'g_test_add_func ("/portal/notification/bad-arg", test_notification_bad_arg);' ""
158   '';
160   preCheck = ''
161     # For test_trash_file
162     export HOME=$(mktemp -d)
164     # Upstream disables a few tests in CI upstream as they are known to
165     # be flaky. Let's disable those downstream as hydra exhibits similar
166     # flakes:
167     #   https://github.com/NixOS/nixpkgs/pull/270085#issuecomment-1840053951
168     export TEST_IN_CI=1
169   '';
171   postFixup =
172     let
173       documentFuse = "${placeholder "installedTests"}/libexec/installed-tests/xdg-desktop-portal/test-document-fuse.py";
174       testPortals = "${placeholder "installedTests"}/libexec/installed-tests/xdg-desktop-portal/test-portals";
176     in
177     ''
178       if [ -x '${documentFuse}' ] ; then
179         wrapGApp '${documentFuse}'
180         wrapGApp '${testPortals}'
181         # (xdg-desktop-portal:995): xdg-desktop-portal-WARNING **: 21:21:55.673: Failed to get GeoClue client: Timeout was reached
182         # xdg-desktop-portal:ERROR:../tests/location.c:22:location_cb: 'res' should be TRUE
183         # https://github.com/flatpak/xdg-desktop-portal/blob/1d6dfb57067dec182b546dfb60c87aa3452c77ed/tests/location.c#L21
184         rm $installedTests/share/installed-tests/xdg-desktop-portal/test-portals-location.test
185       fi
186     '';
188   passthru = {
189     tests = {
190       installedTests = nixosTests.installed-tests.xdg-desktop-portal;
192       validate-icon = runCommand "test-icon-validation" { } ''
193         ${finalAttrs.finalPackage}/libexec/xdg-desktop-portal-validate-icon --sandbox 512 512 ${../../../applications/audio/zynaddsubfx/ZynLogo.svg} > "$out"
194         grep format=svg "$out"
195       '';
196     };
197   };
199   meta = with lib; {
200     description = "Desktop integration portals for sandboxed apps";
201     homepage = "https://flatpak.github.io/xdg-desktop-portal/";
202     license = licenses.lgpl2Plus;
203     maintainers = with maintainers; [ jtojnar ];
204     platforms = platforms.linux;
205   };