Skip to content

Commit bbb7fa7

Browse files
committed
Fix postgresql-musl: merge dev into out to eliminate dev↔lib cycle
The postgresql musl cross-build fails with: error: cycle detected in build of '...-postgresql-musl-17.7.drv' in the references of output 'dev' from output 'lib' The lib output (shared libraries) contains baked-in references to the dev output path, while dev naturally references lib. The remove-references-to approach didn't resolve it (references may be in ELF sections or .rodata that survive stripping). Instead, merge dev into out by removing "dev" from outputs. When "dev" is absent from outputs, $dev defaults to $out, so headers and pkgconfig files end up in $out. Downstream packages using postgresql.dev get postgresql.out (default output for missing output names). This eliminates the cycle entirely.
1 parent b02056a commit bbb7fa7

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

flake.nix

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -170,32 +170,15 @@
170170
NIX_CFLAGS_COMPILE = (old.env.NIX_CFLAGS_COMPILE or "") + " -fno-lto";
171171
};
172172
doCheck = false;
173+
# Merge dev into out to eliminate the dev↔lib reference cycle.
174+
# When "dev" is removed from outputs, $dev defaults to $out,
175+
# so all headers/pkgconfig files end up in $out. Downstream
176+
# packages using postgresql.dev get postgresql.out (default
177+
# output behavior for missing outputs).
178+
outputs = prev.lib.remove "dev" (old.outputs or [ "out" ]);
173179
outputChecks = {};
174180
separateDebugInfo = false;
175181
disallowedReferences = [];
176-
# Break the dev↔lib reference cycle: dev naturally references
177-
# lib (via .pc -L flags), but lib also picks up dev references
178-
# through .la files and baked-in paths. Strip dev refs from lib
179-
# since lib is a runtime output that doesn't need dev at runtime.
180-
postFixup = (old.postFixup or "") + ''
181-
echo "=== postFixup: stripping dev refs from lib ==="
182-
echo "lib=$lib"
183-
echo "dev=$dev"
184-
echo "Files in lib:"
185-
find "$lib" -type f | head -20
186-
# Delete .la files from lib — libtool archives embed absolute
187-
# paths to dev headers/libs and are unnecessary for runtime.
188-
find "$lib" -name '*.la' -delete
189-
# Check which files in lib reference dev before stripping.
190-
echo "Files in lib referencing dev hash:"
191-
DEV_HASH=$(echo "$dev" | sed 's|/nix/store/||; s|-.*||')
192-
grep -rl "$DEV_HASH" "$lib" 2>/dev/null || echo " (none found)"
193-
# Strip any remaining references to $dev from the lib output.
194-
find "$lib" -type f -exec remove-references-to -t "$dev" {} +
195-
echo "After stripping, files referencing dev hash:"
196-
grep -rl "$DEV_HASH" "$lib" 2>/dev/null || echo " (none found)"
197-
echo "=== postFixup done ==="
198-
'';
199182
});
200183
});
201184
};

0 commit comments

Comments
 (0)