Skip to content

Commit cd60a2f

Browse files
committed
Use pkgsStatic instead of pkgsCross.musl64 for static builds
pkgsStatic explicitly sets isStatic=true, which means packages like postgresql automatically disable optional features (jit, perl, python, tcl) that are guarded by !isStatic. This removes the need for 4 explicit override flags. pkgsStatic also handles both x86_64 and aarch64 automatically (via makeMuslParsedPlatform), simplifying the static-pkgs definition.
1 parent 16f0128 commit cd60a2f

1 file changed

Lines changed: 15 additions & 44 deletions

File tree

flake.nix

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -56,69 +56,42 @@
5656
cddl = final.callPackage ./pkgs/cddl { };
5757
});
5858

59+
# Fixes for static (musl) builds. pkgsStatic sets isStatic=true,
60+
# so most optional features (jit, perl, python, tcl) already
61+
# default to false. Only cross-compilation quirks remain.
5962
musl = (final: prev: prev.lib.optionalAttrs prev.stdenv.hostPlatform.isMusl {
60-
# We don't need a ruby static build. We're only interested in producing static
61-
# outputs, not necessarily build tools.
63+
# Use build-platform ruby instead of building a static one.
6264
ruby = prev.pkgsBuildBuild.ruby;
6365

64-
# OpenSSL 3.6.0 test 82-test_ocsp_cert_chain.t fails in the nix sandbox
65-
# because the OCSP stapling test requires network/timing conditions that
66-
# aren't reliably available during cross-compilation builds. Only 1 of 3888
67-
# tests fails, and it's unrelated to the actual crypto functionality.
66+
# OpenSSL OCSP stapling test is flaky in the nix sandbox.
6867
openssl = prev.openssl.overrideAttrs (old: {
6968
preCheck = (old.preCheck or "") + ''
7069
rm -f test/recipes/82-test_ocsp_cert_chain.t
7170
'';
7271
});
7372

74-
# PostgreSQL fixes for musl cross-compilation:
75-
#
76-
# nixpkgs-2511 postgresql/generic.nix has multiple issues with
77-
# musl64 because pkgsCross.musl64 doesn't set isStatic=true:
78-
#
79-
# 1. jitSupport defaults true → pulls in LLVM build inputs.
80-
# 2. perlSupport defaults true → musl perl lacks shared libperl.
81-
# 3. pythonSupport/tclSupport default true → adds plpython3/pltcl
82-
# outputs. These are unnecessary for musl cross-builds and
83-
# each extra output widens the nix-copy window, exacerbating
84-
# the min-free GC race on darwin builders.
85-
# 4. generic.nix switches to LLVM stdenv+bintools for LTO when
86-
# GCC is used. Cross-compiled LLVM 20 OOMs on darwin builders.
87-
# We override llvmPackages_20 to prevent the switch (avoids
88-
# LLVM dependency), then explicitly disable LTO with -fno-lto
89-
# since GCC LTO + GNU ld is broken for postgresql (.ltrans
90-
# link failures). Can't use hardeningDisable=["lto"] because
91-
# "lto" is not a recognized hardening flag on musl cross.
92-
# 5. outputChecks unconditionally reference llvmPackages.llvm.
73+
# PostgreSQL cross-compilation fixes:
74+
# - generic.nix switches to LLVM stdenv for LTO when GCC is
75+
# used. Cross-compiled LLVM 20 OOMs on darwin builders.
76+
# Override llvmPackages_20 to prevent the switch.
77+
# - GCC LTO + GNU ld produces .ltrans link failures; disable.
78+
# - outputChecks unconditionally reference llvmPackages.llvm.
79+
# - disallowedReferences fails for cross (cc refs in .pc/.la).
80+
# - Multi-output reference cycles (dev↔out, lib↔out) must be
81+
# broken or Nix refuses to register the outputs.
9382
postgresql = (prev.postgresql.override {
94-
jitSupport = false;
95-
perlSupport = false;
96-
pythonSupport = false;
97-
tclSupport = false;
98-
# Prevent the LTO stdenv switch: provide normal GCC-based
99-
# musl stdenv as llvmPackages_20, making the switch a no-op.
10083
llvmPackages_20 = prev.llvmPackages_20 // {
10184
inherit (prev) stdenv;
10285
bintools = prev.stdenv.cc.bintools;
10386
};
10487
}).overrideAttrs (old: {
105-
# Explicitly disable LTO since we're using GCC + GNU ld
106-
# (not the LLVM bintools the stdenv switch would provide).
10788
env = (old.env or {}) // {
10889
NIX_CFLAGS_COMPILE = (old.env.NIX_CFLAGS_COMPILE or "") + " -fno-lto";
10990
};
11091
doCheck = false;
11192
outputChecks = {};
11293
separateDebugInfo = false;
11394
disallowedReferences = [];
114-
# Break multi-output reference cycles. Nix refuses to register
115-
# outputs that form cycles. The cycles are:
116-
# dev ↔ out: dev has .pc files referencing out; out has
117-
# baked-in dev paths from configure
118-
# lib ↔ out: lib has embedded out paths (share/locale refs
119-
# in libpq); out links against lib
120-
# Fix: strip dev refs from out+lib, strip out refs from lib.
121-
# out→lib is the only legitimate runtime dependency.
12295
postFixup = (old.postFixup or "") + ''
12396
find "$out" -name '*.la' -delete
12497
find "$out" -type f -exec remove-references-to -t "$dev" {} +
@@ -150,9 +123,7 @@
150123
# nix develop github:input-output-hk/devx#ghc96 --no-write-lock-file -c cabal build
151124
#
152125
static-pkgs = if pkgs.stdenv.hostPlatform.isLinux
153-
then if pkgs.stdenv.hostPlatform.isAarch64
154-
then pkgs.pkgsCross.aarch64-multiplatform-musl
155-
else pkgs.pkgsCross.musl64
126+
then pkgs.pkgsStatic
156127
else pkgs;
157128
js-pkgs = pkgs.pkgsCross.ghcjs;
158129
windows-pkgs = pkgs.pkgsCross.mingwW64;

0 commit comments

Comments
 (0)