Build portable Linux binaries with musl static linking#17
Open
rgarcia wants to merge 1 commit intotobi:masterfrom
Open
Build portable Linux binaries with musl static linking#17rgarcia wants to merge 1 commit intotobi:masterfrom
rgarcia wants to merge 1 commit intotobi:masterfrom
Conversation
The release binaries were dynamically linked against Nix's glibc, making them non-portable to systems with older or different glibc versions. Users would see errors like: /lib/x86_64-linux-gnu/libc.so.6: version 'GLIBC_2.38' not found This changes the Linux cross-compilation packages to use musl-based static linking: - x86_64-linux: Use pkgsStatic for musl static linking - aarch64-linux: Use aarch64-multiplatform-musl for cross-compiled musl static linking - Both builds now pass LDFLAGS="-static" to ensure fully static binaries The resulting binaries are fully self-contained with no runtime dependencies, matching the README's claim of "zero dependencies" and "single statically-linked binary". Tested with: nix build .#packages.x86_64-linux.x86_64-linux file ./result/bin/try # Shows "statically linked" nix build .#packages.x86_64-linux.aarch64-linux file ./result/bin/try # Shows "statically linked"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Problem
The release binaries were dynamically linked against Nix's glibc 2.40, making them non-portable to systems with older glibc versions:
This contradicts the README's claim of "zero dependencies" and "single statically-linked binary".
Solution
pkgs.pkgsStaticfor x86_64-linux (musl-based static toolchain)pkgs.pkgsCross.aarch64-multiplatform-muslfor aarch64-linuxLDFLAGS="-static"to ensure fully static binariesBinary size comparison
The ~2x size increase is a reasonable tradeoff for true portability.
Test plan
Verified locally with Nix: