Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qgis, qgis-ltr: fix dependencies on darwin #157862

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions pkgs/applications/gis/qgis/default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
{ lib, makeWrapper, symlinkJoin
{ lib
, makeWrapper
, symlinkJoin
, extraPythonPackages ? (ps: [ ])
, darwin
, libsForQt5
}:

with lib;

let
qgis-unwrapped = libsForQt5.callPackage ./unwrapped.nix { };

qgis-unwrapped = libsForQt5.callPackage ./unwrapped.nix {
inherit (darwin.apple_sdk.libs) utmp;
};

in symlinkJoin rec {

inherit (qgis-unwrapped) version;
Expand Down
13 changes: 11 additions & 2 deletions pkgs/applications/gis/qgis/ltr.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
{ lib, makeWrapper, symlinkJoin
{ lib
, makeWrapper
, symlinkJoin
, extraPythonPackages ? (ps: [ ])
, darwin
, libsForQt5
}:

with lib;

let
qgis-ltr-unwrapped = libsForQt5.callPackage ./unwrapped-ltr.nix { };

qgis-ltr-unwrapped = libsForQt5.callPackage ./unwrapped-ltr.nix {
inherit (darwin.apple_sdk.libs) utmp;
};

in symlinkJoin rec {

inherit (qgis-ltr-unwrapped) version;
Expand Down
57 changes: 53 additions & 4 deletions pkgs/applications/gis/qgis/unwrapped-ltr.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{ lib
, stdenv
, mkDerivation
, fetchFromGitHub
, cmake
Expand All @@ -18,6 +19,8 @@
, txt2tags
, openssl
, libzip
, libtasn1
, utmp
, hdf5
, netcdf
, exiv2
Expand Down Expand Up @@ -103,6 +106,7 @@ in mkDerivation rec {
postgresql
txt2tags
libzip
libtasn1
hdf5
netcdf
qtbase
Expand All @@ -114,10 +118,11 @@ in mkDerivation rec {
qtserialport
qtxmlpatterns
qt3d
pdal
zstd
] ++ lib.optional withGrass grass
++ lib.optional withWebKit qtwebkit
++ lib.optional stdenv.isLinux pdal
++ lib.optional stdenv.isDarwin utmp
++ pythonBuildInputs;

nativeBuildInputs = [ makeWrapper wrapGAppsHook cmake flex bison ninja ];
Expand All @@ -132,31 +137,75 @@ in mkDerivation rec {

cmakeFlags = [
"-DWITH_3D=True"
"-DWITH_PDAL=TRUE"
] ++ lib.optional (!withWebKit) "-DWITH_QTWEBKIT=OFF"
++ lib.optional stdenv.isLinux "-DWITH_PDAL=TRUE"
++ lib.optional withGrass (let
gmajor = lib.versions.major grass.version;
gminor = lib.versions.minor grass.version;
in "-DGRASS_PREFIX${gmajor}=${grass}/grass${gmajor}${gminor}"
);

dontWrapGApps = true; # wrapper params passed below
dontWrapQtApps = stdenv.isDarwin;

postFixup = lib.optionalString withGrass ''
postFixup = lib.optionalString (withGrass && stdenv.isLinux) ''
# grass has to be availble on the command line even though we baked in
# the path at build time using GRASS_PREFIX.
# using wrapGAppsHook also prevents file dialogs from crashing the program
# on non-NixOS
wrapProgram $out/bin/qgis \
"''${gappsWrapperArgs[@]}" \
--prefix PATH : ${lib.makeBinPath [ grass ]}
'' + lib.optionalString stdenv.isDarwin ''
mkdir -p $out/Applications
mkdir -p $out/bin
mv $out/QGIS.app $out/Applications/
ln -s $out/Applications/QGIS.app/Contents/MacOS/QGIS $out/bin/qgis
export SHORT_VERSION=$(echo "${version}" | awk 'BEGIN{FS=OFS="."} NF--')
echo "Short version: $SHORT_VERSION"
for f in $out/Applications/QGIS.app/Contents/MacOS/lib/libqgis_app.${version}.dylib \
$out/Applications/QGIS.app/Contents/MacOS/lib/libqgispython.${version}.dylib \
$out/Applications/QGIS.app/Contents/MacOS/QGIS \
$out/Applications/QGIS.app/Contents/Frameworks/qgis_3d.framework/Versions/$SHORT_VERSION/qgis_3d \
$out/Applications/QGIS.app/Contents/Frameworks/qgis_analysis.framework/Versions/$SHORT_VERSION/qgis_analysis \
$out/Applications/QGIS.app/Contents/Frameworks/qgis_core.framework/Versions/$SHORT_VERSION/qgis_core \
$out/Applications/QGIS.app/Contents/Frameworks/qgis_gui.framework/Versions/$SHORT_VERSION/qgis_gui \
$out/Applications/QGIS.app/Contents/Frameworks/qgis_native.framework/Versions/$SHORT_VERSION/qgis_native \
$out/Applications/QGIS.app/Contents/Frameworks/qgisgrass8.framework/Versions/$SHORT_VERSION/qgisgrass8 \
$out/Applications/QGIS.app/Contents/Frameworks/qgis_3d.framework/qgis_3d \
$out/Applications/QGIS.app/Contents/Frameworks/qgis_analysis.framework/qgis_analysis \
$out/Applications/QGIS.app/Contents/Frameworks/qgis_core.framework/qgis_core \
$out/Applications/QGIS.app/Contents/Frameworks/qgis_gui.framework/qgis_gui \
$out/Applications/QGIS.app/Contents/Frameworks/qgis_native.framework/qgis_native \
$out/Applications/QGIS.app/Contents/Frameworks/qgisgrass8.framework/qgisgrass8
do
echo "Manually running install_name_tool on $f"
install_name_tool -change "@loader_path/../lib/libqscintilla2_qt5.dylib" "${qscintilla}/lib/libqscintilla2_qt5.dylib" $f
install_name_tool -change "@loader_path/../lib/libqt5keychain.dylib" "${qtkeychain}/lib/libqt5keychain.dylib" $f
install_name_tool -change "@loader_path/../lib/libqwt.dylib" "${qwt}/lib/libqwt.dylib" $f
install_name_tool -change "@loader_path/../../Frameworks/qca-qt5.framework/qca-qt5" "${qca-qt5}/lib/qca-qt5.framework/qca-qt5" $f
install_name_tool -change "@loader_path/../../../qca-qt5.framework/qca-qt5" "${qca-qt5}/lib/qca-qt5.framework/qca-qt5" $f
install_name_tool -change "@loader_path/../../../../MacOS/lib/libqscintilla2_qt5.dylib" "${qscintilla}/lib/libqscintilla2_qt5.dylib" $f
install_name_tool -change "@loader_path/../../../../MacOS/lib/libqt5keychain.dylib" "${qtkeychain}/lib/libqt5keychain.dylib" $f
install_name_tool -change "@loader_path/../../../../MacOS/lib/libqwt.dylib" "${qwt}/lib/libqwt.dylib" $f
install_name_tool -change "@loader_path/../../../qgis_3d.framework/qgis_core" "$out/Applications/QGIS.app/Contents/Frameworks/qgis_core.framework/Versions/$SHORT_VERSION/qgis_core" $f
install_name_tool -change "@loader_path/../../../qgis_analysis.framework/qgis_analysis" "$out/Applications/QGIS.app/Contents/Frameworks/qgis_analysis.framework/Versions/$SHORT_VERSION/qgis_analysis" $f
install_name_tool -change "@loader_path/../../../qgis_core.framework/qgis_core" "$out/Applications/QGIS.app/Contents/Frameworks/qgis_core.framework/Versions/$SHORT_VERSION/qgis_core" $f
install_name_tool -change "@loader_path/../../../qgis_gui.framework/qgis_gui" "$out/Applications/QGIS.app/Contents/Frameworks/qgis_gui.framework/Versions/$SHORT_VERSION/qgis_gui" $f
install_name_tool -change "@loader_path/../../../qgis_native.framework/qgis_native" "$out/Applications/QGIS.app/Contents/Frameworks/qgis_native.framework/Versions/$SHORT_VERSION/qgis_native" $f
install_name_tool -change "@loader_path/../../../qgisgrass8.framework/qgisgrass8" "$out/Applications/QGIS.app/Contents/Frameworks/qgisgrass8.framework/Versions/$SHORT_VERSION/qgisgrass8" $f
install_name_tool -change "@executable_path/lib/libqwt.dylib" "${qwt}/lib/libqwt.dylib" $f
install_name_tool -change "@executable_path/lib/libqscintilla2_qt5.dylib" "${qscintilla}/lib/libqscintilla2_qt5.dylib" $f
install_name_tool -change "@executable_path/lib/libqt5keychain.dylib" "${qtkeychain}/lib/libqt5keychain.dylib" $f
install_name_tool -change "@executable_path/../Frameworks/qca-qt5.framework/qca-qt5" "${qca-qt5}/lib/qca-qt5.framework/qca-qt5" $f
done
'';

meta = {
description = "A Free and Open Source Geographic Information System";
homepage = "https://www.qgis.org";
license = lib.licenses.gpl2Plus;
platforms = with lib.platforms; linux;
platforms = with lib.platforms; unix;
maintainers = with lib.maintainers; [ lsix sikmir erictapen willcohen ];
};
}
61 changes: 56 additions & 5 deletions pkgs/applications/gis/qgis/unwrapped.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{ lib
, stdenv
, mkDerivation
, fetchFromGitHub
, cmake
Expand All @@ -18,6 +19,8 @@
, txt2tags
, openssl
, libzip
, libtasn1
, utmp
, hdf5
, netcdf
, exiv2
Expand Down Expand Up @@ -103,6 +106,7 @@ in mkDerivation rec {
postgresql
txt2tags
libzip
libtasn1
hdf5
netcdf
qtbase
Expand All @@ -114,13 +118,15 @@ in mkDerivation rec {
qtserialport
qtxmlpatterns
qt3d
pdal
zstd
] ++ lib.optional withGrass grass
++ lib.optional withWebKit qtwebkit
++ lib.optional stdenv.isLinux pdal
++ lib.optional stdenv.isDarwin utmp
++ pythonBuildInputs;

nativeBuildInputs = [ makeWrapper wrapGAppsHook cmake flex bison ninja ];
nativeBuildInputs = [ wrapGAppsHook cmake flex bison ninja ]
++ lib.optional stdenv.isLinux [ makeWrapper ];

patches = [
(substituteAll {
Expand All @@ -132,31 +138,76 @@ in mkDerivation rec {

cmakeFlags = [
"-DWITH_3D=True"
"-DWITH_PDAL=TRUE"
] ++ lib.optional (!withWebKit) "-DWITH_QTWEBKIT=OFF"
++ lib.optional stdenv.isLinux "-DWITH_PDAL=TRUE"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change ? it seems to build fine on Mac with this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call -- it was broken a long time ago and I just assumed that was still true. Fixed since October with #195216. Will revise.

++ lib.optional withGrass (let
gmajor = lib.versions.major grass.version;
gminor = lib.versions.minor grass.version;
in "-DGRASS_PREFIX${gmajor}=${grass}/grass${gmajor}${gminor}"
);

dontWrapGApps = true; # wrapper params passed below
dontWrapQtApps = stdenv.isDarwin;

postFixup = lib.optionalString withGrass ''
postFixup = lib.optionalString (withGrass && stdenv.isLinux) ''
# grass has to be availble on the command line even though we baked in
# the path at build time using GRASS_PREFIX.
# using wrapGAppsHook also prevents file dialogs from crashing the program
# on non-NixOS
wrapProgram $out/bin/qgis \
"''${gappsWrapperArgs[@]}" \
--prefix PATH : ${lib.makeBinPath [ grass ]}
'' + lib.optionalString stdenv.isDarwin ''
mkdir -p $out/Applications
mkdir -p $out/bin
mv $out/QGIS.app $out/Applications/
ln -s $out/Applications/QGIS.app/Contents/MacOS/QGIS $out/bin/qgis
export SHORT_VERSION=$(echo "${version}" | awk 'BEGIN{FS=OFS="."} NF--')
echo "Short version: $SHORT_VERSION"
for f in $out/Applications/QGIS.app/Contents/MacOS/lib/libqgis_app.${version}.dylib \
$out/Applications/QGIS.app/Contents/MacOS/lib/libqgispython.${version}.dylib \
$out/Applications/QGIS.app/Contents/MacOS/QGIS \
$out/Applications/QGIS.app/Contents/Frameworks/qgis_3d.framework/Versions/$SHORT_VERSION/qgis_3d \
$out/Applications/QGIS.app/Contents/Frameworks/qgis_analysis.framework/Versions/$SHORT_VERSION/qgis_analysis \
$out/Applications/QGIS.app/Contents/Frameworks/qgis_core.framework/Versions/$SHORT_VERSION/qgis_core \
$out/Applications/QGIS.app/Contents/Frameworks/qgis_gui.framework/Versions/$SHORT_VERSION/qgis_gui \
$out/Applications/QGIS.app/Contents/Frameworks/qgis_native.framework/Versions/$SHORT_VERSION/qgis_native \
$out/Applications/QGIS.app/Contents/Frameworks/qgisgrass8.framework/Versions/$SHORT_VERSION/qgisgrass8 \
$out/Applications/QGIS.app/Contents/Frameworks/qgis_3d.framework/qgis_3d \
$out/Applications/QGIS.app/Contents/Frameworks/qgis_analysis.framework/qgis_analysis \
$out/Applications/QGIS.app/Contents/Frameworks/qgis_core.framework/qgis_core \
$out/Applications/QGIS.app/Contents/Frameworks/qgis_gui.framework/qgis_gui \
$out/Applications/QGIS.app/Contents/Frameworks/qgis_native.framework/qgis_native \
$out/Applications/QGIS.app/Contents/Frameworks/qgisgrass8.framework/qgisgrass8
do
echo "Manually running install_name_tool on $f"
install_name_tool -change "@loader_path/../lib/libqscintilla2_qt5.dylib" "${qscintilla}/lib/libqscintilla2_qt5.dylib" $f
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how did you get this list ? can it be parsed and looped over ? it should be more resistant to future upgrade

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was, unfortunately, done by me repeatedly building and running the .app, having it crash due to a linking error, and repeating over and over. I did at least simplify it so it can loop over the dylibs I know about. It seems like the original build script does it with a little less targeting, but it's true that this is moderately fragile. I'm open to suggestions for how to improve it -- fixDarwinDylib names was too blunt an instrument and tried to operate on lots of files in $out, and wasn't able to deal with the Frameworks, so I ended up just doing this manually.

install_name_tool -change "@loader_path/../lib/libqt5keychain.dylib" "${qtkeychain}/lib/libqt5keychain.dylib" $f
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
install_name_tool -change "@loader_path/../lib/libqt5keychain.dylib" "${qtkeychain}/lib/libqt5keychain.dylib" $f
install_name_tool -change "@loader_path/../lib/libqt5keychain.dylib" "${qtkeychain}/lib/libqt5keychain.dylib" "$f"

same for all other

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch -- will revise.

install_name_tool -change "@loader_path/../lib/libqwt.dylib" "${qwt}/lib/libqwt.dylib" $f
install_name_tool -change "@loader_path/../../Frameworks/qca-qt5.framework/qca-qt5" "${qca-qt5}/lib/qca-qt5.framework/qca-qt5" $f
install_name_tool -change "@loader_path/../../../qca-qt5.framework/qca-qt5" "${qca-qt5}/lib/qca-qt5.framework/qca-qt5" $f
install_name_tool -change "@loader_path/../../../../MacOS/lib/libqscintilla2_qt5.dylib" "${qscintilla}/lib/libqscintilla2_qt5.dylib" $f
install_name_tool -change "@loader_path/../../../../MacOS/lib/libqt5keychain.dylib" "${qtkeychain}/lib/libqt5keychain.dylib" $f
install_name_tool -change "@loader_path/../../../../MacOS/lib/libqwt.dylib" "${qwt}/lib/libqwt.dylib" $f
install_name_tool -change "@loader_path/../../../qgis_3d.framework/qgis_core" "$out/Applications/QGIS.app/Contents/Frameworks/qgis_core.framework/Versions/$SHORT_VERSION/qgis_core" $f
install_name_tool -change "@loader_path/../../../qgis_analysis.framework/qgis_analysis" "$out/Applications/QGIS.app/Contents/Frameworks/qgis_analysis.framework/Versions/$SHORT_VERSION/qgis_analysis" $f
install_name_tool -change "@loader_path/../../../qgis_core.framework/qgis_core" "$out/Applications/QGIS.app/Contents/Frameworks/qgis_core.framework/Versions/$SHORT_VERSION/qgis_core" $f
install_name_tool -change "@loader_path/../../../qgis_gui.framework/qgis_gui" "$out/Applications/QGIS.app/Contents/Frameworks/qgis_gui.framework/Versions/$SHORT_VERSION/qgis_gui" $f
install_name_tool -change "@loader_path/../../../qgis_native.framework/qgis_native" "$out/Applications/QGIS.app/Contents/Frameworks/qgis_native.framework/Versions/$SHORT_VERSION/qgis_native" $f
install_name_tool -change "@loader_path/../../../qgisgrass8.framework/qgisgrass8" "$out/Applications/QGIS.app/Contents/Frameworks/qgisgrass8.framework/Versions/$SHORT_VERSION/qgisgrass8" $f
install_name_tool -change "@executable_path/lib/libqwt.dylib" "${qwt}/lib/libqwt.dylib" $f
install_name_tool -change "@executable_path/lib/libqscintilla2_qt5.dylib" "${qscintilla}/lib/libqscintilla2_qt5.dylib" $f
install_name_tool -change "@executable_path/lib/libqt5keychain.dylib" "${qtkeychain}/lib/libqt5keychain.dylib" $f
install_name_tool -change "@executable_path/../Frameworks/qca-qt5.framework/qca-qt5" "${qca-qt5}/lib/qca-qt5.framework/qca-qt5" $f
done

'';

meta = {
description = "A Free and Open Source Geographic Information System";
homepage = "https://www.qgis.org";
license = lib.licenses.gpl2Plus;
platforms = with lib.platforms; linux;
platforms = with lib.platforms; unix;
maintainers = with lib.maintainers; [ lsix sikmir erictapen willcohen ];
};
}