1 { lib, stdenv, fetchurl, fetchFromGitLab, fetchFromGitHub, runCommand, writeText
3 , libxslt, docbook_xml_dtd_412, docbook_xml_dtd_43, docbook_xsl, xmlto
5 , resholve, bash, coreutils, dbus, file, gawk, glib, gnugrep, gnused, jq, nettools, procmail, procps, which, xdg-user-dirs
8 , withXdgOpenUsePortalPatch ? true }:
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.
18 "gnome-default-applications-properties"
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 ]}
30 scripts = [ "bin/xdg-desktop-icon" ];
31 interpreter = "${bash}/bin/bash";
32 inputs = commonDeps ++ [ xdg-user-dirs ];
34 "cannot:${xdg-user-dirs}/bin/xdg-user-dir"
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
41 keep."$KDE_SESSION_VERSION" = true;
42 prologue = commonPrologue;
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;
55 scripts = [ "bin/xdg-email" ];
56 interpreter = "${bash}/bin/bash";
57 inputs = commonDeps ++ [ gawk glib.bin "${placeholder "out"}/bin" ];
59 "cannot:${placeholder "out"}/bin/xdg-mime"
60 "cannot:${placeholder "out"}/bin/xdg-open"
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 ++ [
68 "gnome-open" # GNOME (very old)
69 "gvfs-open" # GNOME (old)
71 "xdg-email-hook.sh" # user-defined hook that may be available ambiently
73 fix."/bin/echo" = true;
76 "$kreadconfig" = true;
77 "$THUNDERBIRD" = true;
83 scripts = [ "bin/xdg-icon-resource" ];
84 interpreter = "${bash}/bin/bash";
86 fake.external = commonFakes;
87 keep."$KDE_SESSION_VERSION" = true;
88 prologue = commonPrologue;
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 ++ [
99 "gnomevfs-info" # GNOME (very old)
100 "gvfs-info" # GNOME (old)
101 "kde4-config" # Plasma 4
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
111 fix."/usr/bin/file" = true;
113 "$KDE_SESSION_VERSION" = true;
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 ]}
124 scripts = [ "bin/xdg-open" ];
125 interpreter = "${bash}/bin/bash";
126 inputs = commonDeps ++ [ nettools glib.bin "${placeholder "out"}/bin" ];
128 "cannot:${placeholder "out"}/bin/xdg-mime"
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 ++ [
135 "enlightenment_open" # Enlightenment
138 "gnome-open" # GNOME (very old)
139 "gvfs-open" # GNOME (old)
143 "mimeopen" # alternative tool for file, pulls in perl, avoid
147 "run-mailcap" # generic
151 fix."$printf" = [ "printf" ];
153 "env:$command" = true;
155 "$KDE_SESSION_VERSION" = true;
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 ++ [
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
178 "$lockfile_command" = true;
181 "cannot:${perl}/bin/perl"
183 prologue = "${writeText "xdg-screensaver-prologue" ''
184 export PERL5LIB=${with perlPackages; makePerlPath [ NetDBus XMLTwig XMLParser X11Protocol ]}
185 export PATH=$PATH:${coreutils}/bin
190 scripts = [ "bin/xdg-settings" ];
191 interpreter = "${bash}/bin/bash";
192 inputs = commonDeps ++ [ jq "${placeholder "out"}/bin" ];
194 "cannot:${placeholder "out"}/bin/xdg-mime"
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
204 "kwriteconfig" # Plasma (generic)
205 "kwriteconfig5" # Plasma 5
206 "kwriteconfig6" # Plasma 6
210 "$KDE_SESSION_VERSION" = true;
211 # get_browser_$handler
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
225 "terminology" # Englightenment
229 "$kreadconfig" = true;
230 "$terminal_exec" = true;
232 prologue = commonPrologue;
237 stdenv.mkDerivation (self: {
241 src = fetchFromGitLab {
242 domain = "gitlab.freedesktop.org";
245 rev = "v${self.version}";
246 hash = "sha256-58ElbrVlk+13DUODSEHBPcDDt9H+Kuee8Rz9CIcoy0I=";
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
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"
273 "sha256-Si9AtB7J9o6rK/oftv+saST77CNaeWomWU5ECfbRioM=" = [
274 "https://static1.e621.net/data/25/3d/253dc77fbc60d7214bc60e4a647d1c32.jpg"
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"
284 type="$(xdg-mime query filetype $x)"
285 [ $? -eq 0 ] && [ "$type" = "image/''${ext/jpg/jpeg}" ] || {
286 echo "Incorrect MIME type '$type' for '$x'" >&2
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;
298 platforms = platforms.all;