-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
Suggestion: allow mostly-static builds targeting Darwin #214611
Comments
Currently attempting to override builds on the basis that gcc actually discards My overlay for reference: self: super:
{ stdenv = super.stdenv //
{ hostPlatform = super.stdenv.hostPlatform // { isStatic = true; };
targetPlatform = super.stdenv.targetPlatform // { isStatic = true; };
};
targetPackages = super.targetPackages //
{ darwin = super.targetPackages.darwin //
{ LibsystemCross = super.targetPackages.darwin.Libsystem;
};
};
} |
Okay, I have a working Nixpkgs expression for building "static" executables targeting Darwin (on Darwin only). let sys = "x86_64-darwin";
in import <nixpkgs> {
localSystem = sys;
crossSystem = {
isStatic = true;
system = sys;
};
overlays = [
(self: super: {
darwin = super.darwin // {
Libsystem = super.buildPackages.darwin.Libsystem;
LibsystemCross = super.buildPackages.darwin.Libsystem;
};
libcCross = super.buildPackages.darwin.Libsystem;
targetPackages = self;
})
];
} |
|
I'm fixing
|
This overlay produces a completely freestanding Nix binary for macOS nixie-dev/nixie:static-bins/nixpkgs-darwin-static.nix but I'd appreciate an upstreamed solution |
FYI I have also seen people use Zig to compile C programs statically on macOS. |
Good point, I've only thought about it in the context of cross compiling, see https://discourse.nixos.org/t/poc-zig-based-cross-compiling/22844 for example. |
Fixed by #235990 |
Should this be closed when static builds still don’t work on x86_64-darwin? |
Agreed, let's keep this open till all supported Darwin platforms have working static builds. |
Fortunately, that should be coming pretty soon. I have a branch with working x86_64-darwin cross-compilation, which includes mostly-static builds. I need to make sure I didn’t break the stdenv or aarch64-darwin cross-compilation, so it’ll probably be a few days before I can open the PR. |
Describe the bug
I understand that purely static binaries are not supported under Darwin, due to the unstable system call ABI. My suggestion is that
pkgsStatic
, on Darwinor cross-compiling to Darwin, should produce static libraries, which would result in dynamic binaries which only depend onlibSystem.dylib
. This would be useful for single-file software for embedding, as well as simplifying distribution of Nix-built binaries on systems without Nix.Steps To Reproduce
Steps to reproduce the behavior:
nixpkgs#legacyPackages.x86_64-darwin.pkgsStatic.nix
llvm-otool -L result/bin/nix
Expected behavior
Resulting executable would only depend on
/usr/lib/libSystem.B.dylib
Notify maintainers
@NixOS/darwin-maintainers
The text was updated successfully, but these errors were encountered: