2023-03-02 09:17:44 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
# The unwrapped libreoffice derivation
|
|
|
|
, unwrapped
|
|
|
|
, makeWrapper
|
2023-03-26 13:09:20 +00:00
|
|
|
, xorg # for lndir
|
2023-03-02 09:17:44 +00:00
|
|
|
, runCommand
|
|
|
|
, substituteAll
|
|
|
|
# For Emulating wrapGAppsHook
|
|
|
|
, gsettings-desktop-schemas
|
|
|
|
, hicolor-icon-theme
|
|
|
|
, dconf
|
|
|
|
, librsvg
|
|
|
|
, gdk-pixbuf
|
|
|
|
# Configuration options for the wrapper
|
|
|
|
, extraMakeWrapperArgs ? []
|
|
|
|
, dbusVerify ? stdenv.isLinux
|
|
|
|
, dbus
|
2022-04-28 19:13:13 +00:00
|
|
|
}:
|
2023-03-02 09:17:44 +00:00
|
|
|
|
|
|
|
let
|
2023-03-11 12:30:00 +00:00
|
|
|
inherit (unwrapped.srcs.primary) major minor;
|
|
|
|
|
2023-03-02 09:17:44 +00:00
|
|
|
makeWrapperArgs = builtins.concatStringsSep " " ([
|
|
|
|
"--set" "GDK_PIXBUF_MODULE_FILE" "${librsvg}/${gdk-pixbuf.moduleDir}.cache"
|
|
|
|
"--prefix" "GIO_EXTRA_MODULES" ":" "${lib.getLib dconf}/lib/gio/modules"
|
|
|
|
"--prefix" "XDG_DATA_DIRS" ":" "${unwrapped.gtk3}/share/gsettings-schemas/${unwrapped.gtk3.name}"
|
|
|
|
"--prefix" "XDG_DATA_DIRS" ":" "$out/share"
|
|
|
|
"--prefix" "XDG_DATA_DIRS" ":" "${gsettings-desktop-schemas}/share/gsettings-schemas/${gsettings-desktop-schemas.name}"
|
|
|
|
"--prefix" "XDG_DATA_DIRS" ":" "${hicolor-icon-theme}/share"
|
|
|
|
"--prefix" "GST_PLUGIN_SYSTEM_PATH_1_0" ":"
|
|
|
|
"${lib.makeSearchPath "lib/girepository-1.0" unwrapped.gst_packages}"
|
|
|
|
] ++ lib.optionals unwrapped.kdeIntegration [
|
|
|
|
"--prefix" "QT_PLUGIN_PATH" ":" "${
|
|
|
|
lib.makeSearchPath
|
|
|
|
unwrapped.qtbase.qtPluginPrefix
|
|
|
|
(builtins.map lib.getBin unwrapped.qtPackages)
|
|
|
|
}"
|
|
|
|
"--prefix" "QML2_IMPORT_PATH" ":" "${
|
|
|
|
lib.makeSearchPath unwrapped.qtbase.qtQmlPrefix
|
|
|
|
(builtins.map lib.getBin unwrapped.qmlPackages)
|
|
|
|
}"
|
|
|
|
] ++ [
|
|
|
|
# Add dictionaries from all NIX_PROFILES
|
|
|
|
"--run" (lib.escapeShellArg ''
|
|
|
|
for PROFILE in $NIX_PROFILES; do
|
|
|
|
HDIR="$PROFILE/share/hunspell"
|
|
|
|
if [ -d "$HDIR" ]; then
|
|
|
|
export DICPATH=$DICPATH''${DICPATH:+:}$HDIR
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
'')
|
|
|
|
] ++ lib.optionals dbusVerify [
|
|
|
|
# If no dbus is running, start a dedicated dbus daemon
|
|
|
|
"--run" (lib.escapeShellArg ''
|
|
|
|
if ! ( test -n "$DBUS_SESSION_BUS_ADDRESS" ); then
|
|
|
|
dbus_tmp_dir="/run/user/$(id -u)/libreoffice-dbus"
|
|
|
|
if ! test -d "$dbus_tmp_dir" && test -d "/run"; then
|
|
|
|
mkdir -p "$dbus_tmp_dir"
|
|
|
|
fi
|
|
|
|
if ! test -d "$dbus_tmp_dir"; then
|
|
|
|
dbus_tmp_dir="/tmp/libreoffice-$(id -u)/libreoffice-dbus"
|
|
|
|
mkdir -p "$dbus_tmp_dir"
|
|
|
|
fi
|
|
|
|
dbus_socket_dir="$(mktemp -d -p "$dbus_tmp_dir")"
|
|
|
|
"${dbus}"/bin/dbus-daemon \
|
|
|
|
--nopidfile \
|
|
|
|
--nofork \
|
|
|
|
--config-file "${dbus}"/share/dbus-1/session.conf \
|
|
|
|
--address "unix:path=$dbus_socket_dir/session" &> /dev/null &
|
|
|
|
dbus_pid=$!
|
|
|
|
export DBUS_SESSION_BUS_ADDRESS="unix:path=$dbus_socket_dir/session"
|
|
|
|
fi
|
|
|
|
'')
|
|
|
|
] ++ [
|
|
|
|
"--inherit-argv0"
|
|
|
|
] ++ extraMakeWrapperArgs
|
|
|
|
);
|
|
|
|
in runCommand "${unwrapped.name}-wrapped" {
|
|
|
|
inherit (unwrapped) meta;
|
|
|
|
paths = [ unwrapped ];
|
2023-03-26 13:09:20 +00:00
|
|
|
nativeBuildInputs = [ makeWrapper xorg.lndir ];
|
2023-03-02 09:17:44 +00:00
|
|
|
passthru = {
|
|
|
|
inherit unwrapped;
|
|
|
|
# For backwards compatibility:
|
|
|
|
libreoffice = lib.warn "libreoffice: Use the unwrapped attributed, using libreoffice.libreoffice is deprecated." unwrapped;
|
|
|
|
inherit (unwrapped) kdeIntegration;
|
|
|
|
};
|
2022-04-28 19:13:13 +00:00
|
|
|
} (''
|
2023-03-26 13:09:20 +00:00
|
|
|
mkdir -p $out/share
|
2023-03-14 10:53:31 +00:00
|
|
|
for dir in ${unwrapped}/share/*; do
|
|
|
|
dirname="''${dir##*/}"
|
|
|
|
if [[ $dirname == "applications" ]]; then
|
|
|
|
cp -r $dir/ $out/share/
|
|
|
|
else
|
|
|
|
ln -s $dir $out/share/
|
|
|
|
fi
|
|
|
|
done
|
2023-03-11 12:30:00 +00:00
|
|
|
for f in $out/share/applications/*.desktop; do
|
|
|
|
substituteInPlace "$f" \
|
|
|
|
--replace "Exec=libreoffice${major}.${minor}" "Exec=soffice"
|
|
|
|
done
|
|
|
|
|
2023-03-26 13:09:20 +00:00
|
|
|
mkdir -p $out/bin
|
|
|
|
mkdir -p $out/lib/libreoffice/program
|
|
|
|
lndir -silent ${unwrapped}/lib/libreoffice/program $out/lib/libreoffice/program
|
2023-03-02 09:17:44 +00:00
|
|
|
for i in sbase scalc sdraw smath swriter simpress soffice unopkg; do
|
2023-03-26 13:09:20 +00:00
|
|
|
# Delete the symlink created by lndir, and replace it by our wrapper
|
|
|
|
rm $out/lib/libreoffice/program/$i
|
|
|
|
makeWrapper \
|
|
|
|
${unwrapped}/lib/libreoffice/program/$i \
|
|
|
|
$out/lib/libreoffice/program/$i \
|
|
|
|
${makeWrapperArgs}
|
2023-03-02 09:17:44 +00:00
|
|
|
'' + lib.optionalString dbusVerify ''
|
|
|
|
# Delete the dbus socket directory after libreoffice quits
|
2023-03-26 13:09:20 +00:00
|
|
|
sed -i 's/^exec -a "$0" //g' $out/lib/libreoffice/program/$i
|
|
|
|
echo 'code="$?"' >> $out/lib/libreoffice/program/$i
|
|
|
|
echo 'test -n "$dbus_socket_dir" && { rm -rf "$dbus_socket_dir"; kill $dbus_pid; }' >> $out/lib/libreoffice/program/$i
|
|
|
|
echo 'exit "$code"' >> $out/lib/libreoffice/program/$i
|
2023-03-02 09:17:44 +00:00
|
|
|
'' + ''
|
2023-03-26 13:09:20 +00:00
|
|
|
ln -s $out/lib/libreoffice/program/$i $out/bin/$i
|
2018-03-27 17:18:49 +00:00
|
|
|
done
|
2023-03-26 13:09:20 +00:00
|
|
|
# A symlink many users rely upon
|
|
|
|
ln -s $out/bin/soffice $out/bin/libreoffice
|
2022-04-28 19:13:13 +00:00
|
|
|
'')
|