Skip to content

Commit

Permalink
xdg-utils: unstable-2022-11-06 -> 1.2.0, resholve
Browse files Browse the repository at this point in the history
  • Loading branch information
K900 committed Jan 31, 2024
1 parent a90ecd7 commit ee7b880
Show file tree
Hide file tree
Showing 2 changed files with 201 additions and 49 deletions.
246 changes: 200 additions & 46 deletions pkgs/tools/X11/xdg-utils/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{ lib, stdenv, fetchFromGitLab, fetchFromGitHub, fetchpatch
, file, libxslt, docbook_xml_dtd_412, docbook_xsl, xmlto
, w3m, gnugrep, gnused, coreutils, xset, perlPackages
, mimiSupport ? false, gawk
, bash
, glib
{ lib, stdenv, fetchFromGitLab, fetchFromGitHub, fetchpatch, writeText
# docs deps
, libxslt, docbook_xml_dtd_412, docbook_xml_dtd_43, docbook_xsl, xmlto
# runtime deps
, resholve, bash, coreutils, dbus, file, gawk, gnugrep, gnused, jq, nettools, procmail, procps
, perl, perlPackages
, mimiSupport ? false
, withXdgOpenUsePortalPatch ? true }:

let
Expand All @@ -15,73 +16,226 @@ let
sha256 = "15gw2nyrqmdsdin8gzxihpn77grhk9l97jp7s7pr7sl4n9ya2rpj";
};

perlPath = with perlPackages; makePerlPath [
NetDBus XMLTwig XMLParser X11Protocol
# Required by the common desktop detection code
commonDeps = [ dbus coreutils gnugrep gnused ];
commonFakes = [
"explorer.exe"
"gnome-default-applications-properties"
"kde-config"
"xprop"
];

# This is still required to work around the eval trickery some scripts do
commonPrologue = "${writeText "xdg-utils-prologue" ''
export PATH=$PATH:${coreutils}/bin
''}";

solutions = [
{
scripts = [ "bin/xdg-desktop-icon" ];
interpreter = "${bash}/bin/bash";
inputs = commonDeps;
fake.external = commonFakes ++ [
"gconftool-2"
"xdg-user-dir"
];
keep."$KDE_SESSION_VERSION" = true;
prologue = commonPrologue;
}

{
scripts = [ "bin/xdg-desktop-menu" ];
interpreter = "${bash}/bin/bash";
inputs = commonDeps ++ [ gawk ];
fake.external = commonFakes;
keep."$KDE_SESSION_VERSION" = true;
prologue = commonPrologue;
}

{
scripts = [ "bin/xdg-email" ];
interpreter = "${bash}/bin/bash";
inputs = commonDeps ++ [ gawk "${placeholder "out"}/bin" ];
execer = [
"cannot:${placeholder "out"}/bin/xdg-mime"
"cannot:${placeholder "out"}/bin/xdg-open"
];
fake.external = commonFakes ++ [
"exo-open"
"gconftool-2"
"gdbus"
"gio"
"gnome-open"
"gvfs-open"
"qtxdg-mat"
"xdg-email-hook.sh"
];
fix."/bin/echo" = true;
keep = {
"$command" = true;
"$kreadconfig" = true;
"$THUNDERBIRD" = true;
"$utf8" = true;
};
}

{
scripts = [ "bin/xdg-icon-resource" ];
interpreter = "${bash}/bin/bash";
inputs = commonDeps;
fake.external = commonFakes;
keep."$KDE_SESSION_VERSION" = true;
prologue = commonPrologue;
}

{
scripts = [ "bin/xdg-mime" ];
interpreter = "${bash}/bin/bash";
inputs = commonDeps ++ [ file gawk ];
fake.external = commonFakes ++ [
"gio"
"gnomevfs-info"
"gvfs-info"
"kde4-config"
"kfile"
"kmimetypefinder"
"kmimetypefinder5"
"ktraderclient"
"ktradertest"
"mimetype"
"qtpaths"
"qtxdg-mat"
];
fix."/usr/bin/file" = true;
keep = {
"$KDE_SESSION_VERSION" = true;
"$KTRADER" = true;
};
}

{
scripts = [ "bin/xdg-open" ];
interpreter = "${bash}/bin/bash";
inputs = commonDeps ++ [ nettools "${placeholder "out"}/bin" ];
execer = [
"cannot:${placeholder "out"}/bin/xdg-mime"
];
fake.external = commonFakes ++ [
"cygstart"
"dde-open"
"enlightenment_open"
"env"
"exo-open"
"gdbus"
"gio"
"gnome-open"
"gvfs-open"
"kde-open"
"kfmclient"
"mate-open"
"mimeopen"
"open"
"pcmanfm"
"qtxdg-mat"
"run-mailcap"
"rundll32.exe"
"wslpath"

# actually part of a doc string, resholve bug?
"troublesome"
];
keep = {
"$browser" = true;
"$KDE_SESSION_VERSION" = true;
"$printf" = true;
};
}

{
scripts = [ "bin/xdg-screensaver" ];
interpreter = "${bash}/bin/bash";
inputs = commonDeps ++ [ nettools perl procmail procps ];
fake.external = commonFakes ++ [
"dcop"
"mate-screensaver-command"
"xautolock"
"xscreensaver-command"
"xset"
];
keep = {
"$lockfile_command" = true;
"$MV" = true;
"$XPROP" = true;
};
prologue = "${writeText "xdg-screensaver-prologue" ''
export PERL5LIB=${with perlPackages; makePerlPath [ NetDBus XMLTwig XMLParser X11Protocol ]}
export PATH=$PATH:${coreutils}/bin
''}";
}

{
scripts = [ "bin/xdg-settings" ];
interpreter = "${bash}/bin/bash";
inputs = commonDeps ++ [ jq "${placeholder "out"}/bin" ];
execer = [
"cannot:${placeholder "out"}/bin/xdg-mime"
];
fake.external = commonFakes ++ [
"gconftool-2"
"kreadconfig"
"kreadconfig5"
"kreadconfig6"
"ktradertest"
"kwriteconfig"
"kwriteconfig5"
"kwriteconfig6"
"qtxdg-mat"
];
keep = {
"$KDE_SESSION_VERSION" = true;
# get_browser_$handler
"$handler" = true;
};
}
];
in

stdenv.mkDerivation rec {
pname = "xdg-utils";
version = "unstable-2022-11-06";
version = "1.2.0";

src = fetchFromGitLab {
domain = "gitlab.freedesktop.org";
owner = "xdg";
repo = "xdg-utils";
rev = "8ae02631a9806da11b34cd6b274af02d28aee5da";
sha256 = "sha256-WdnnAiPYbREny633FnBi5tD9hDuF8NCVVbUaAVIKTxM=";
rev = "v${version}";
hash = "sha256-rjNIO4B9jHsBmPaugWTMqTGNpjiw0MTEmf9/ds2Mud4=";
};

patches = lib.optionals withXdgOpenUsePortalPatch [
patches = [
# Backport typo fix
(fetchpatch {
url = "https://gitlab.freedesktop.org/xdg/xdg-utils/-/commit/af2fe0d1dcbcd982d84ddf2bbd174afe90976ed9.patch";
hash = "sha256-HhQk06wWkyWjSxjXet+sADKf1irswKxDA8WuOknZKRs=";
})
] ++ lib.optionals withXdgOpenUsePortalPatch [
# Allow forcing the use of XDG portals using NIXOS_XDG_OPEN_USE_PORTAL environment variable.
# Upstream PR: https://github.com/freedesktop/xdg-utils/pull/12
./allow-forcing-portal-use.patch
# Allow opening files when using portal with xdg-open.
# Upstream PR: https://gitlab.freedesktop.org/xdg/xdg-utils/-/merge_requests/65
(fetchpatch {
name = "support-openfile-with-portal.patch";
url = "https://gitlab.freedesktop.org/xdg/xdg-utils/-/commit/5cd8c38f58d9db03240f4bc67267fe3853b66ec7.diff";
hash = "sha256-snkhxwGF9hpqEh5NGG8xixTi/ydAk5apXRtgYrVgNY8=";
})
];

# just needed when built from git
nativeBuildInputs = [ libxslt docbook_xml_dtd_412 docbook_xsl xmlto w3m ];
nativeBuildInputs = [ libxslt docbook_xml_dtd_412 docbook_xml_dtd_43 docbook_xsl xmlto ];

# explicitly provide a runtime shell so patchShebangs is consistent across build platforms
buildInputs = [ bash ];

postInstall = lib.optionalString mimiSupport ''
cp ${mimisrc}/xdg-open $out/bin/xdg-open
'' + ''
sed '2s#.#\
sed() { ${gnused}/bin/sed "$@"; }\
grep() { ${gnugrep}/bin/grep "$@"; }\
egrep() { ${gnugrep}/bin/egrep "$@"; }\
file() { ${file}/bin/file "$@"; }\
awk() { ${gawk}/bin/awk "$@"; }\
xset() { ${xset}/bin/xset "$@"; }\
perl() { PERL5LIB=${perlPath} ${perlPackages.perl}/bin/perl "$@"; }\
mimetype() { ${perlPackages.FileMimeInfo}/bin/mimetype "$@"; }\
PATH=$PATH:'$out'/bin:${coreutils}/bin\
&#' -i "$out"/bin/*
substituteInPlace $out/bin/xdg-open \
--replace "/usr/bin/printf" "${coreutils}/bin/printf" \
--replace "gdbus" "${glib}/bin/gdbus" \
--replace "mimeopen" "${perlPackages.FileMimeInfo}/bin/mimeopen"
substituteInPlace $out/bin/xdg-mime \
--replace "/usr/bin/file" "${file}/bin/file"
substituteInPlace $out/bin/xdg-email \
--replace "/bin/echo" "${coreutils}/bin/echo" \
--replace "gdbus" "${glib}/bin/gdbus"
sed 's|\bwhich\b|type -P|g' -i "$out"/bin/*
'';

preFixup = lib.concatStringsSep "\n" (map (resholve.phraseSolution "xdg-utils-resholved") solutions);

meta = with lib; {
homepage = "https://www.freedesktop.org/wiki/Software/xdg-utils/";
description = "A set of command line tools that assist applications with a variety of desktop integration tasks";
Expand Down
4 changes: 1 addition & 3 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36544,9 +36544,7 @@ with pkgs;

xdg-user-dirs = callPackage ../tools/X11/xdg-user-dirs { };

xdg-utils = callPackage ../tools/X11/xdg-utils {
w3m = buildPackages.w3m-batch;
};
xdg-utils = callPackage ../tools/X11/xdg-utils {};

xdgmenumaker = callPackage ../applications/misc/xdgmenumaker { };

Expand Down

0 comments on commit ee7b880

Please sign in to comment.