mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-01-09 14:33:22 +00:00
39 lines
1.4 KiB
Nix
39 lines
1.4 KiB
Nix
# Overlay that builds static packages.
|
||
|
||
# Not all packages will build but support is done on a
|
||
# best effort basic.
|
||
#
|
||
# Note on Darwin/macOS: Apple does not provide a static libc
|
||
# so any attempts at static binaries are going to be very
|
||
# unsupported.
|
||
#
|
||
# Basic things like pkgsStatic.hello should work out of the box. More
|
||
# complicated things will need to be fixed with overrides.
|
||
|
||
self: super: let
|
||
inherit (super.stdenvAdapters) makeStaticBinaries
|
||
makeStaticLibraries
|
||
propagateBuildInputs
|
||
makeStaticDarwin;
|
||
inherit (super.lib) foldl optional flip id composeExtensions;
|
||
|
||
staticAdapters =
|
||
optional super.stdenv.hostPlatform.isDarwin makeStaticDarwin
|
||
|
||
++ [ makeStaticLibraries propagateBuildInputs ]
|
||
|
||
# Apple does not provide a static version of libSystem or crt0.o
|
||
# So we can’t build static binaries without extensive hacks.
|
||
++ optional (!super.stdenv.hostPlatform.isDarwin) makeStaticBinaries
|
||
|
||
# Glibc doesn’t come with static runtimes by default.
|
||
# ++ optional (super.stdenv.hostPlatform.libc == "glibc") ((flip overrideInStdenv) [ self.stdenv.glibc.static ])
|
||
;
|
||
|
||
in {
|
||
# Do not add new packages here! Instead use `stdenv.hostPlatform.isStatic` to
|
||
# write conditional code in the original package.
|
||
|
||
stdenv = foldl (flip id) super.stdenv staticAdapters;
|
||
}
|