biome: 1.9.2 -> 1.9.3
[NixPkgs.git] / pkgs / tools / X11 / xdg-utils / default.nix
blob5b3a1a5367c07bda211728198538b99967e39801
1 { lib, stdenv, fetchurl, fetchFromGitLab, fetchFromGitHub, runCommand, writeText
2 # docs deps
3 , libxslt, docbook_xml_dtd_412, docbook_xml_dtd_43, docbook_xsl, xmlto
4 # runtime deps
5 , resholve, bash, coreutils, dbus, file, gawk, glib, gnugrep, gnused, jq, nettools, procmail, procps, which, xdg-user-dirs
6 , shared-mime-info
7 , perl, perlPackages
8 , withXdgOpenUsePortalPatch ? true }:
10 let
12   # Required by the common desktop detection code
13   commonDeps = [ dbus coreutils gnugrep gnused ];
14   # These are all faked because the current desktop is detected
15   # based on their presence, so we want them to be missing by default.
16   commonFakes = [
17     "explorer.exe"
18     "gnome-default-applications-properties"
19     "kde-config"
20     "xprop"
21   ];
23   # This is still required to work around the eval trickery some scripts do
24   commonPrologue = "${writeText "xdg-utils-prologue" ''
25     export PATH=$PATH:${lib.makeBinPath [ coreutils ]}
26   ''}";
28   solutions = [
29     {
30       scripts = [ "bin/xdg-desktop-icon" ];
31       interpreter = "${bash}/bin/bash";
32       inputs = commonDeps ++ [ xdg-user-dirs ];
33       execer = [
34         "cannot:${xdg-user-dirs}/bin/xdg-user-dir"
35       ];
36       # These are desktop-specific, so we don't want xdg-utils to be able to
37       # call them when in a different setup.
38       fake.external = commonFakes ++ [
39         "gconftool-2"   # GNOME2
40       ];
41       keep."$KDE_SESSION_VERSION" = true;
42       prologue = commonPrologue;
43     }
45     {
46       scripts = [ "bin/xdg-desktop-menu" ];
47       interpreter = "${bash}/bin/bash";
48       inputs = commonDeps ++ [ gawk ];
49       fake.external = commonFakes;
50       keep."$KDE_SESSION_VERSION" = true;
51       prologue = commonPrologue;
52     }
54     {
55       scripts = [ "bin/xdg-email" ];
56       interpreter = "${bash}/bin/bash";
57       inputs = commonDeps ++ [ gawk glib.bin "${placeholder "out"}/bin" ];
58       execer = [
59         "cannot:${placeholder "out"}/bin/xdg-mime"
60         "cannot:${placeholder "out"}/bin/xdg-open"
61       ];
62       # These are desktop-specific, so we don't want xdg-utils to be able to
63       # call them when in a different setup.
64       fake.external = commonFakes ++ [
65         "exo-open"           # XFCE
66         "gconftool-2"        # GNOME
67         "gio"                # GNOME (new)
68         "gnome-open"         # GNOME (very old)
69         "gvfs-open"          # GNOME (old)
70         "qtxdg-mat"          # LXQT
71         "xdg-email-hook.sh"  # user-defined hook that may be available ambiently
72       ];
73       fix."/bin/echo" = true;
74       keep = {
75         "$command" = true;
76         "$kreadconfig" = true;
77         "$THUNDERBIRD" = true;
78         "$utf8" = true;
79       };
80     }
82     {
83       scripts = [ "bin/xdg-icon-resource" ];
84       interpreter = "${bash}/bin/bash";
85       inputs = commonDeps;
86       fake.external = commonFakes;
87       keep."$KDE_SESSION_VERSION" = true;
88       prologue = commonPrologue;
89     }
91     {
92       scripts = [ "bin/xdg-mime" ];
93       interpreter = "${bash}/bin/bash";
94       inputs = commonDeps ++ [ file gawk ];
95       # These are desktop-specific, so we don't want xdg-utils to be able to
96       # call them when in a different setup.
97       fake.external = commonFakes ++ [
98         "gio"                # GNOME (new)
99         "gnomevfs-info"      # GNOME (very old)
100         "gvfs-info"          # GNOME (old)
101         "kde4-config"        # Plasma 4
102         "kfile"              # KDE 3
103         "kmimetypefinder"    # Plasma (generic)
104         "kmimetypefinder5"   # Plasma 5
105         "ktraderclient"      # KDE 3
106         "ktradertest"        # KDE 3
107         "mimetype"           # alternative tool for file, pulls in perl, avoid
108         "qtpaths"            # Plasma
109         "qtxdg-mat"          # LXQT
110       ];
111       fix."/usr/bin/file" = true;
112       keep = {
113         "$KDE_SESSION_VERSION" = true;
114         "$KTRADER" = true;
115       };
116       prologue = "${writeText "xdg-mime-prologue" ''
117         export XDG_DATA_DIRS="$XDG_DATA_DIRS''${XDG_DATA_DIRS:+:}${shared-mime-info}/share"
118         export PERL5LIB=${with perlPackages; makePerlPath [ FileMimeInfo ]}
119         export PATH=$PATH:${lib.makeBinPath [ coreutils perlPackages.FileMimeInfo ]}
120       ''}";
121     }
123     {
124       scripts = [ "bin/xdg-open" ];
125       interpreter = "${bash}/bin/bash";
126       inputs = commonDeps ++ [ nettools glib.bin "${placeholder "out"}/bin" ];
127       execer = [
128         "cannot:${placeholder "out"}/bin/xdg-mime"
129       ];
130       # These are desktop-specific, so we don't want xdg-utils to be able to
131       # call them when in a different setup.
132       fake.external = commonFakes ++ [
133         "cygstart"            # Cygwin
134         "dde-open"            # Deepin
135         "enlightenment_open"  # Enlightenment
136         "exo-open"            # XFCE
137         "gio"                 # GNOME (new)
138         "gnome-open"          # GNOME (very old)
139         "gvfs-open"           # GNOME (old)
140         "kde-open"            # Plasma
141         "kfmclient"           # KDE3
142         "mate-open"           # MATE
143         "mimeopen"            # alternative tool for file, pulls in perl, avoid
144         "open"                # macOS
145         "pcmanfm"             # LXDE
146         "qtxdg-mat"           # LXQT
147         "run-mailcap"         # generic
148         "rundll32.exe"        # WSL
149         "wslpath"             # WSL
150       ];
151       fix."$printf" = [ "printf" ];
152       keep = {
153         "env:$command" = true;
154         "$browser" = true;
155         "$KDE_SESSION_VERSION" = true;
156       };
157     }
159     {
160       scripts = [ "bin/xdg-screensaver" ];
161       interpreter = "${bash}/bin/bash";
162       inputs = commonDeps ++ [ nettools perl procps ]
163         # procmail's funky build system is currently broken in cross-build.
164         # xdg-screensaver will gracefully degrade if it's not available.
165         ++ lib.optional (stdenv.hostPlatform == stdenv.buildPlatform) procmail;
166       # These are desktop-specific, so we don't want xdg-utils to be able to
167       # call them when in a different setup.
168       fake.external = commonFakes ++ [
169         "dcop"                      # KDE3
170         "mate-screensaver-command"  # MATE
171         "xautolock"                 # Xautolock
172         "xscreensaver-command"      # Xscreensaver
173         "xset"                      # generic-ish X
174       ] ++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) "lockfile"; # procmail
175       keep = {
176         "$MV" = true;
177         "$XPROP" = true;
178         "$lockfile_command" = true;
179       };
180       execer = [
181         "cannot:${perl}/bin/perl"
182       ];
183       prologue = "${writeText "xdg-screensaver-prologue" ''
184         export PERL5LIB=${with perlPackages; makePerlPath [ NetDBus XMLTwig XMLParser X11Protocol ]}
185         export PATH=$PATH:${coreutils}/bin
186       ''}";
187     }
189     {
190       scripts = [ "bin/xdg-settings" ];
191       interpreter = "${bash}/bin/bash";
192       inputs = commonDeps ++ [ jq "${placeholder "out"}/bin" ];
193       execer = [
194         "cannot:${placeholder "out"}/bin/xdg-mime"
195       ];
196       # These are desktop-specific, so we don't want xdg-utils to be able to
197       # call them when in a different setup.
198       fake.external = commonFakes ++ [
199         "gconftool-2"    # GNOME
200         "kreadconfig"    # Plasma (generic)
201         "kreadconfig5"   # Plasma 5
202         "kreadconfig6"   # Plasma 6
203         "ktradertest"    # KDE3
204         "kwriteconfig"   # Plasma (generic)
205         "kwriteconfig5"  # Plasma 5
206         "kwriteconfig6"  # Plasma 6
207         "qtxdg-mat"      # LXQT
208       ];
209       keep = {
210         "$KDE_SESSION_VERSION" = true;
211         # get_browser_$handler
212         "$handler" = true;
213       };
214     }
216     {
217       scripts = [ "bin/xdg-terminal" ];
218       interpreter = "${bash}/bin/bash";
219       inputs = commonDeps ++ [ bash glib.bin which ];
220       fake.external = commonFakes ++ [
221         "gconftool-2"    # GNOME
222         "exo-open"       # XFCE
223         "lxterminal"     # LXQT
224         "qterminal"      # LXQT
225         "terminology"    # Englightenment
226       ];
227       keep = {
228         "$command" = true;
229         "$kreadconfig" = true;
230         "$terminal_exec" = true;
231       };
232       prologue = commonPrologue;
233     }
234   ];
237 stdenv.mkDerivation (self: {
238   pname = "xdg-utils";
239   version = "1.2.1";
241   src = fetchFromGitLab {
242     domain = "gitlab.freedesktop.org";
243     owner = "xdg";
244     repo = "xdg-utils";
245     rev = "v${self.version}";
246     hash = "sha256-58ElbrVlk+13DUODSEHBPcDDt9H+Kuee8Rz9CIcoy0I=";
247   };
249   patches = lib.optionals withXdgOpenUsePortalPatch [
250     # Allow forcing the use of XDG portals using NIXOS_XDG_OPEN_USE_PORTAL environment variable.
251     # Upstream PR: https://github.com/freedesktop/xdg-utils/pull/12
252     ./allow-forcing-portal-use.patch
253     #  Enable build of xdg-terminal
254     ./enable-xdg-terminal.patch
255   ];
257   # just needed when built from git
258   nativeBuildInputs = [ libxslt docbook_xml_dtd_412 docbook_xml_dtd_43 docbook_xsl xmlto ];
260   # explicitly provide a runtime shell so patchShebangs is consistent across build platforms
261   buildInputs = [ bash ];
263   preFixup = lib.concatStringsSep "\n" (map (resholve.phraseSolution "xdg-utils-resholved") solutions);
265   passthru.tests.xdg-mime = runCommand "xdg-mime-test" {
266     nativeBuildInputs = [ self.finalPackage ];
267     preferLocalBuild = true;
268     xenias = lib.mapAttrsToList (hash: urls: fetchurl { inherit hash urls; }) {
269       "sha256-SL95tM1AjOi7vDnCyT10s0tvQvc+ZSZBbkNOYXfbOy0=" = [
270         "https://staging.cohostcdn.org/attachment/0f5d9832-0cda-4d07-b35f-832b287feb6c/kernelkisser.png"
271         "https://static1.e621.net/data/0e/76/0e7672980d48e48c2d1373eb2505db5a.png"
272       ];
273       "sha256-Si9AtB7J9o6rK/oftv+saST77CNaeWomWU5ECfbRioM=" = [
274         "https://static1.e621.net/data/25/3d/253dc77fbc60d7214bc60e4a647d1c32.jpg"
275       ];
276       "sha256-Z+onQRY5zlDWPp5/y4E6crLz3TaMCNipcxEEMSHuLkM=" = [
277         "https://d.furaffinity.net/art/neotheta/1691409857/1691409857.neotheta_quickmakeanentry_by_neotheta-sig.png"
278         "https://static1.e621.net/data/bf/e4/bfe43ba264ad68e5d8a101ecef69c03e.png"
279       ];
280     };
281   } ''
282     for x in $xenias; do
283       ext=''${x##*.}
284       type="$(xdg-mime query filetype $x)"
285       [ $? -eq 0 ] && [ "$type" = "image/''${ext/jpg/jpeg}" ] || {
286         echo "Incorrect MIME type '$type' for '$x'" >&2
287         exit 1
288       }
289     done
290     touch $out
291   '';
293   meta = with lib; {
294     homepage = "https://www.freedesktop.org/wiki/Software/xdg-utils/";
295     description = "Set of command line tools that assist applications with a variety of desktop integration tasks";
296     license = licenses.mit;
297     maintainers = [ ];
298     platforms = platforms.all;
299   };