From fccb8f0d8dd87637732058f5b7492d8f172b84e7 Mon Sep 17 00:00:00 2001 From: Rafael Garcia Date: Wed, 31 Dec 2025 14:45:13 -0500 Subject: [PATCH] Build portable Linux binaries with musl static linking 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" --- flake.nix | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/flake.nix b/flake.nix index 9ed09f7..cdc85b0 100644 --- a/flake.nix +++ b/flake.nix @@ -86,20 +86,21 @@ }; }; - # Cross-compilation packages - x86_64-linux = pkgs.stdenv.mkDerivation { + # Cross-compilation packages (statically linked with musl for portability) + x86_64-linux = pkgs.pkgsStatic.stdenv.mkDerivation { pname = "try"; version = builtins.replaceStrings ["\n"] [""] (builtins.readFile ./VERSION); src = inputs.self; - nativeBuildInputs = with pkgs; [ + nativeBuildInputs = with pkgs.pkgsStatic; [ gcc gnumake ]; + # Force static linking for portable binary buildPhase = '' - make + make LDFLAGS="-static" ''; installPhase = '' @@ -116,19 +117,20 @@ }; }; - aarch64-linux = pkgs.pkgsCross.aarch64-multiplatform.stdenv.mkDerivation { + aarch64-linux = pkgs.pkgsCross.aarch64-multiplatform-musl.stdenv.mkDerivation { pname = "try"; version = builtins.replaceStrings ["\n"] [""] (builtins.readFile ./VERSION); src = inputs.self; - nativeBuildInputs = with pkgs.pkgsCross.aarch64-multiplatform; [ + nativeBuildInputs = with pkgs.pkgsCross.aarch64-multiplatform-musl; [ gcc gnumake ]; + # Force static linking for portable binary buildPhase = '' - make + make LDFLAGS="-static" ''; installPhase = ''