on iko/ghcjs-patch-master help sign in
Fix for postgresql-libpg and musl (fixes #948) (#1056)

This combined with setting the `use-pkg-config` flag on `postgresql-libpq` should get it compiling. There is still a problem with `openssl` that requires a `module` to fix the linking of executables. Add the following to the `cabal.project` file or to `cabalProjectLocal`: ``` package postgresql-libpq flags: +use-pkg-config ``` Include a module like this one to include `openssl` in the linker arguments: ```nix { modules = [( {pkgs, ...}: final.lib.mkIf pkgs.stdenv.hostPlatform.isMusl { # The order of -lssl and -lcrypto is important here packages.postgrest.configureFlags = [ "--ghc-option=-optl=-lssl" "--ghc-option=-optl=-lcrypto" "--ghc-option=-optl=-L${pkgs.openssl.out}/lib" ]; })]; } ``` This PR also adds a "hackage quirk" for `postgrest` to that makes these changes for `postgrest` automatically when built it as a `tool` or with `hackage-package`. Unfortunately we do not have a good way to avoid the need make these changes.

commit583acc2219f4183dcb601688f82e21eadd5cce5b authorHamish Mackenzie <Hamish.Mackenzie@iohk.io> dateWed 24 Feb 2021, 22:49 (6 years ago) parentb82002e
3 files changed+26−2
lib/pkgconf-nixpkgs-map.nix+3−2 overlays/hackage-quirks.nix+18 overlays/musl.nix+5
lib/pkgconf-nixpkgs-map.nix+3−2
@@ -21,7 +21,6 @@ pkgs:
2121 "cairo-ps" = [ pkgs."cairo" ];
2222 "cairo-svg" = [ pkgs."cairo" ];
2323 "crypt" = []; # provided by glibc
24− "crypto" = [ pkgs."openssl" ];
2524 "curses" = [ pkgs."ncurses" ];
2625 "dbusmenu-glib-0.4" = [ pkgs."libdbusmenu" ];
2726 "dbusmenu-gtk3-0.4" = [ pkgs."libdbusmenu-gtk3" ]; # do we also need pkgs."gtk3"
@@ -80,6 +79,7 @@ pkgs:
8079 "lber" = [ pkgs."openldap" ];
8180 "ldap" = [ pkgs."openldap" ];
8281 "libavutil" = [ pkgs."ffmpeg" ];
82+ "libcrypto" = [ pkgs."openssl".dev ];
8383 "libgsasl" = [ pkgs."gsasl" ];
8484 "libpcre" = [ pkgs."pcre" ];
8585 "libqrencode" = [ pkgs."qrencode" ];
@@ -88,6 +88,7 @@ pkgs:
8888 "libsecp256k1" = [ pkgs."secp256k1" ];
8989 "libsoup-2.4" = [ pkgs."libsoup" ];
9090 "libsoup-gnome-2.4" = [ pkgs."libsoup" ];
91+ "libssl" = [ pkgs."openssl".dev ];
9192 "libsystemd" = [ pkgs."systemd" ];
9293 "libudev" = [ pkgs."systemd" ];
9394 "libusb-1.0" = [ pkgs."libusb1" ];
@@ -115,6 +116,7 @@ pkgs:
115116 "png" = [ pkgs."libpng" ];
116117 "poppler-glib" = [ pkgs."poppler" ];
117118 "pq" = [ pkgs."postgresql" ];
119+ "libpq" = [ pkgs."postgresql" ];
118120 "pthread" = [];
119121 "pulse" = [ pkgs."libpulseaudio" ];
120122 "pulse-simple" = [ pkgs."libpulseaudio" ];
@@ -136,7 +138,6 @@ pkgs:
136138 "sodium" = [ pkgs."libsodium" ];
137139 "sqlite3" = [ pkgs."sqlite" ];
138140 "ssh2" = [ pkgs."libssh2" ];
139− "ssl" = [ pkgs."openssl" ];
140141 "statgrab" = [ pkgs."libstatgrab" ];
141142 "stdc++" = []; # What is that?
142143 "stdc++.dll" = []; # What is that?
overlays/hackage-quirks.nix+18
@@ -73,6 +73,24 @@ in { haskell-nix = prev.haskell-nix // {
7373 '';
7474 };
7575
76+ # See https://github.com/input-output-hk/haskell.nix/issues/948
77+ postgrest = {
78+ cabalProject = ''
79+ packages: .
80+ package postgresql-libpq
81+ flags: +use-pkg-config
82+ '';
83+ modules = [(
84+ {pkgs, ...}: final.lib.mkIf pkgs.stdenv.hostPlatform.isMusl {
85+ # The order of -lssl and -lcrypto is important here
86+ packages.postgrest.configureFlags = [
87+ "--ghc-option=-optl=-lssl"
88+ "--ghc-option=-optl=-lcrypto"
89+ "--ghc-option=-optl=-L${pkgs.openssl.out}/lib"
90+ ];
91+ })];
92+ };
93+
7694 }."${name}" or {};
7795
7896}; }
overlays/musl.nix+5
@@ -15,6 +15,11 @@ final: prev: prev.lib.optionalAttrs prev.stdenv.hostPlatform.isMusl ({
1515
1616 numactl = prev.numactl.overrideAttrs (_: { configureFlags = "--enable-static"; });
1717
18+ # See https://github.com/input-output-hk/haskell.nix/issues/948
19+ postgresql = (prev.postgresql.overrideAttrs (old: { dontDisableStatic = true; }))
20+ .override { enableSystemd = false; };
21+ openssl = prev.openssl.override { static = true; };
22+
1823 # Fails on cross compile
1924 nix = prev.nix.overrideAttrs (_: { doInstallCheck = false; });
2025} // prev.lib.optionalAttrs (prev.lib.versionAtLeast prev.lib.trivial.release "20.03") {