Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkgsStatic shouldn't imply musl. #196329

Open
uri-canva opened this issue Oct 16, 2022 · 5 comments
Open

pkgsStatic shouldn't imply musl. #196329

uri-canva opened this issue Oct 16, 2022 · 5 comments
Labels
0.kind: bug Something is broken 6.topic: musl Running or building packages with musl libc 6.topic: static

Comments

@uri-canva
Copy link
Contributor

Describe the bug

pkgsStatic switches the libc from the default glibc to musl. But musl has its own pkgs overlay, that should compose with pkgsStatic. Currently it does not: #114510.

See also #136549 (comment):

The fact pkgsStatic is using musl is an accident: glibc static build was broken at the time and musl was used instead. Ideally pkgsStatic should differ from pkgs in just having -static kind of flags.

Nowadays glibc.static is working and I was actually thinking about changing pkgsStatic back to using it.

@r-burns
Copy link
Contributor

r-burns commented Oct 16, 2022

It looks like this is all that should be needed to make the pkgsStatic package set use static glibc.

--- a/pkgs/top-level/stage.nix
+++ b/pkgs/top-level/stage.nix
@@ -250,7 +250,6 @@ let
     extend = f: self.appendOverlays [f];
 
     # Fully static packages.
-    # Currently uses Musl on Linux (couldn’t get static glibc to work).
     pkgsStatic = nixpkgsFun ({
       overlays = [ (self': super': {
         pkgsStatic = super';
@@ -258,9 +257,7 @@ let
     } // lib.optionalAttrs stdenv.hostPlatform.isLinux {
       crossSystem = {
         isStatic = true;
-        parsed = makeMuslParsedPlatform stdenv.hostPlatform.parsed;
-      } // lib.optionalAttrs (stdenv.hostPlatform.system == "powerpc64-linux") {
-        gcc.abi = "elfv2";
+        parsed = stdenv.hostPlatform.parsed;
       };
     });
   };

This currently fails to build static glibc during stdenv bootstrap.

@panicgh
Copy link
Contributor

panicgh commented Oct 17, 2022

Note that static linking the glibc can lead to various weird bugs and is generally discouraged, see https://stackoverflow.com/a/57478728, and look through the libc manual for "statically link" and "static link". The wiki also has a FAQ about this.

musl seems a better choice for static linking.

@r-burns
Copy link
Contributor

r-burns commented Oct 17, 2022

I don't see any language discouraging static linking in the libc manual. The caveats of static linking mentioned in that stackoverflow post are noted, but they aren't major IMO and don't seem like showstoppers for someone desiring a static distribution.

@uri-canva
Copy link
Contributor Author

Yeah that's a good point, in practice static binaries using glibc tend to be statically linked against their libraries except for glibc. It's still a usecase that is covered better by having a package set, rather than overriding the specific package you want to have static binaries for.

@uri-canva
Copy link
Contributor Author

cc @NixOS/static

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken 6.topic: musl Running or building packages with musl libc 6.topic: static
Projects
None yet
Development

No branches or pull requests

5 participants