Skip to content

Commit 32c03bc

Browse files
committed
build(nix): Swap postgresql->libpq for static builds
1 parent 7c2ce85 commit 32c03bc

File tree

2 files changed

+61
-58
lines changed

2 files changed

+61
-58
lines changed

flake.lock

Lines changed: 29 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
url = "github:IntersectMBO/cardano-haskell-packages?ref=repo";
2525
flake = false;
2626
};
27-
# Note[PostgreSQL 17]: This is a workaround to get postgresql_17 from nixpkgs. It's
28-
# available in nixpkgs unstable, but has not been updated in haskell.nix yet. Remove
29-
# this after the next time haskell.nix updates nixpkgs.
30-
nixpkgsUpstream.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
3127
};
3228

3329
outputs = { self, ... }@inputs:
@@ -40,12 +36,6 @@
4036
in
4137
inputs.utils.lib.eachSystem supportedSystems (system:
4238
let
43-
# TODO: Remove me (See Note[PostgreSQL 17]).
44-
nixpkgsUpstream = import inputs.nixpkgsUpstream {
45-
inherit system;
46-
inherit (inputs.haskellNix) config;
47-
};
48-
4939
nixpkgs = import inputs.nixpkgs {
5040
inherit system;
5141
inherit (inputs.haskellNix) config;
@@ -54,6 +44,14 @@
5444
builtins.attrValues inputs.iohkNix.overlays ++
5545
[ inputs.haskellNix.overlay
5646

47+
(final: prev: {
48+
haskell-nix = prev.haskell-nix // {
49+
extraPkgconfigMappings = prev.haskell-nix.extraPkgconfigMappings // {
50+
"libpq" = [ "libpq" ];
51+
};
52+
};
53+
})
54+
5755
(final: prev: {
5856
inherit (project.hsPkgs.cardano-node.components.exes) cardano-node;
5957
inherit (project.hsPkgs.cardano-cli.components.exes) cardano-cli;
@@ -88,18 +86,23 @@
8886
})
8987

9088
(final: prev: {
91-
postgresql = prev.postgresql.overrideAttrs (_:
92-
final.lib.optionalAttrs (final.stdenv.hostPlatform.isMusl) {
93-
NIX_LDFLAGS = "--push-state --as-needed -lstdc++ --pop-state";
94-
LC_CTYPE = "C";
95-
96-
doCheck = false;
97-
});
98-
})
99-
100-
# TODO: Remove me (See Note[PostgreSQL 17])
101-
(final: prev: {
102-
postgresql_17 = nixpkgsUpstream.postgresql_17;
89+
libpq =
90+
final.lib.pipe prev.libpq [
91+
(p: p.override {
92+
gssSupport = false;
93+
})
94+
95+
(p: p.overrideAttrs (old:
96+
final.lib.optionalAttrs (final.stdenv.hostPlatform.isMusl) {
97+
dontDisableStatic = true;
98+
NIX_LDFLAGS = "--push-state --as-needed -lstdc++ --pop-state";
99+
# without this collate.icu.utf8, and foreign_data will fail.
100+
LC_CTYPE = "C";
101+
# libpq from nixpkgs will either remove static or dynamic
102+
# libs, but we need to keep them both
103+
postInstall = "";
104+
}))
105+
];
103106
})
104107
];
105108
};
@@ -165,7 +168,7 @@
165168
crossPlatforms = p:
166169
lib.optional (system == "x86_64-linux") p.musl64 ++
167170
lib.optional
168-
(system == "x86_64-linux" && config.compiler-nix-name == "ghc966")
171+
(system == "x86_64-linux" && config.compiler-nix-name == "ghc967")
169172
p.aarch64-multiplatform-musl;
170173

171174
inputMap = {
@@ -179,7 +182,7 @@
179182
src = nixpkgs.haskell-nix.sources."hls-2.11";
180183
};
181184
hlint = "latest";
182-
} // lib.optionalAttrs (config.compiler-nix-name == "ghc966") {
185+
} // lib.optionalAttrs (config.compiler-nix-name == "ghc967") {
183186
weeder = "latest";
184187
};
185188
# Now we use pkgsBuildBuild, to make sure that even in the cross
@@ -242,14 +245,14 @@
242245
(pkgs.lib.mkIf pkgs.hostPlatform.isMusl
243246
(let
244247
ghcOptions = [
245-
# Postgresql static is pretty broken in nixpkgs. We can't rely on the
248+
# libpq static is pretty broken in nixpkgs. We can't rely on the
246249
# pkg-config, so we have to add the correct libraries ourselves
247-
"-L${pkgs.postgresql}/lib"
248-
"-optl-Wl,-lpgport"
249250
"-optl-Wl,-lpgcommon"
251+
"-optl-Wl,-lpgport"
252+
"-optl-Wl,-lm"
250253

251-
# Since we aren't using the postgresql pkg-config, it won't
252-
# automatically include OpenSSL
254+
# Since we aren't using pkg-config, it won't automatically include
255+
# OpenSSL
253256
"-L${pkgs.openssl.out}/lib"
254257

255258
# The ordering of -lssl and -lcrypto below is important. Otherwise,

0 commit comments

Comments
 (0)