1 { lib, stdenv, fetchFromGitLab, fetchFromGitHub, fetchpatch
2 , file, libxslt, docbook_xml_dtd_412, docbook_xsl, xmlto
3 , w3m, gnugrep, gnused, coreutils, xset, perlPackages
4 , mimiSupport ? false, gawk
6 , withXdgOpenUsePortalPatch ? true }:
9 # A much better xdg-open
10 mimisrc = fetchFromGitHub {
11 owner = "march-linux";
13 rev = "8e0070f17bcd3612ee83cb84e663e7c7fabcca3d";
14 sha256 = "15gw2nyrqmdsdin8gzxihpn77grhk9l97jp7s7pr7sl4n9ya2rpj";
17 perlPath = with perlPackages; makePerlPath [
18 NetDBus XMLTwig XMLParser X11Protocol
23 stdenv.mkDerivation rec {
25 version = "unstable-2020-10-21";
27 src = fetchFromGitLab {
28 domain = "gitlab.freedesktop.org";
31 rev = "d11b33ec7f24cfb1546f6b459611d440013bdc72";
32 sha256 = "sha256-8PtXfI8hRneEpnUvIV3M+6ACjlkx0w/NEiJFdGbbHnQ=";
35 patches = lib.optionals withXdgOpenUsePortalPatch [
36 # Allow forcing the use of XDG portals using NIXOS_XDG_OPEN_USE_PORTAL environment variable.
37 # Upstream PR: https://github.com/freedesktop/xdg-utils/pull/12
38 ./allow-forcing-portal-use.patch
39 # Allow opening files when using portal with xdg-open.
40 # Upstream PR: https://gitlab.freedesktop.org/xdg/xdg-utils/-/merge_requests/65
42 name = "support-openfile-with-portal.patch";
43 url = "https://gitlab.freedesktop.org/xdg/xdg-utils/-/commit/5cd8c38f58d9db03240f4bc67267fe3853b66ec7.diff";
44 hash = "sha256-snkhxwGF9hpqEh5NGG8xixTi/ydAk5apXRtgYrVgNY8=";
48 # just needed when built from git
49 nativeBuildInputs = [ libxslt docbook_xml_dtd_412 docbook_xsl xmlto w3m ];
51 postInstall = lib.optionalString mimiSupport ''
52 cp ${mimisrc}/xdg-open $out/bin/xdg-open
55 sed() { ${gnused}/bin/sed "$@"; }\
56 grep() { ${gnugrep}/bin/grep "$@"; }\
57 egrep() { ${gnugrep}/bin/egrep "$@"; }\
58 file() { ${file}/bin/file "$@"; }\
59 awk() { ${gawk}/bin/awk "$@"; }\
60 xset() { ${xset}/bin/xset "$@"; }\
61 perl() { PERL5LIB=${perlPath} ${perlPackages.perl}/bin/perl "$@"; }\
62 mimetype() { ${perlPackages.FileMimeInfo}/bin/mimetype "$@"; }\
63 PATH=$PATH:'$out'/bin:${coreutils}/bin\
66 substituteInPlace $out/bin/xdg-open \
67 --replace "/usr/bin/printf" "${coreutils}/bin/printf" \
68 --replace "gdbus" "${glib}/bin/gdbus"
70 substituteInPlace $out/bin/xdg-mime \
71 --replace "/usr/bin/file" "${file}/bin/file"
73 substituteInPlace $out/bin/xdg-email \
74 --replace "/bin/echo" "${coreutils}/bin/echo" \
75 --replace "gdbus" "${glib}/bin/gdbus"
77 sed 's|\bwhich\b|type -P|g' -i "$out"/bin/*
81 homepage = "https://www.freedesktop.org/wiki/Software/xdg-utils/";
82 description = "A set of command line tools that assist applications with a variety of desktop integration tasks";
83 license = if mimiSupport then licenses.gpl2 else licenses.free;
84 maintainers = [ maintainers.eelco ];
85 platforms = platforms.all;