toplevel: define a "static-x86_64" and "static-aarch64" host, to experiment with static linking

progress is early, and it's unclear if the work the make gtk, opengl, etc compatible with such a system will ever be feasible
This commit is contained in:
2025-06-28 11:54:47 +00:00
parent 4ceab76cd1
commit 58ab12310a
5 changed files with 109 additions and 19 deletions

View File

@@ -57,11 +57,27 @@ let
# but i want these a little more normalized, which is possible either here, or
# by assigning `boot.kernelPackages`.
# elaborate = system: system;
elaborate = system: let
e = lib.systems.elaborate system;
elaborate = system: { static ? false }: let
abi = if static then "musl" else "gnu";
e = lib.systems.elaborate {
# N.B.: "static" can mean a few things:
# 1. binaries should be linked statically (stdenv.hostPlatform.isStatic == true).
# 2. host libc doesn't support dlopen (stdenv.hostPlatform.hasSharedLibraries == false).
#
# nixpkgs' `pkgsStatic` is the stricter meaning of "static": no `.so` files, period.
# this means plugin-heavy frameworks like `gobject-introspection` probably just cannot ever work (?).
# TODO: i'd _prefer_ to use the weaker kind of "static", and support all the traditional packages,
# but for now that actually results in fewer working packages (e.g. `xdg-dbus-proxy`).
system = "${system}-${abi}";
isStatic = static;
# hasSharedLibraries = true;
};
in
{
inherit system;
e // {
extensions = e.extensions // {
# when `hasSharedLibraries` == false, need to explicitly set this here to fix eval of many packages. this is not a long-term fix.
sharedLibrary = ".so";
};
linux-kernel = {
inherit (e.linux-kernel) name baseConfig target;
} // (lib.optionalAttrs (e.linux-kernel ? DTB) { inherit (e.linux-kernel) DTB; }) // {
@@ -86,22 +102,24 @@ let
hosts = builtins.foldl'
# XXX: i `elaborate` localSystem the same as i do `system` because otherwise nixpkgs
# sees they're (slightly) different and forces everything down the (expensive) cross-compilation path.
(acc: host: acc // mkHost ({ localSystem = elaborate localSystem; } // host))
(acc: host: acc // mkHost ({ localSystem = elaborate localSystem {}; } // host))
{}
[
# real hosts:
# { name = "crappy"; system = "armv7l-linux"; }
{ name = "cadey"; system = elaborate "aarch64-linux"; }
{ name = "desko"; system = elaborate "x86_64-linux"; }
{ name = "flowy"; system = elaborate "x86_64-linux"; }
{ name = "lappy"; system = elaborate "x86_64-linux"; }
{ name = "moby"; system = elaborate "aarch64-linux"; }
{ name = "servo"; system = elaborate "x86_64-linux"; }
{ name = "cadey"; system = elaborate "aarch64-linux" {}; }
{ name = "desko"; system = elaborate "x86_64-linux" {}; }
{ name = "flowy"; system = elaborate "x86_64-linux" {}; }
{ name = "lappy"; system = elaborate "x86_64-linux" {}; }
{ name = "moby"; system = elaborate "aarch64-linux" {}; }
{ name = "servo"; system = elaborate "x86_64-linux" {}; }
{ name = "rescue"; system = elaborate "x86_64-linux"; }
{ name = "rescue"; system = elaborate "x86_64-linux" {}; }
# pseudo hosts used for debugging
{ name = "baseline-x86_64"; system = elaborate "x86_64-linux"; }
{ name = "baseline-aarch64"; system = elaborate "aarch64-linux"; }
{ name = "baseline-x86_64"; system = elaborate "x86_64-linux" {}; }
{ name = "baseline-aarch64"; system = elaborate "aarch64-linux" {}; }
{ name = "static-x86_64"; system = elaborate "x86_64-linux" { static = true; }; }
{ name = "static-aarch64"; system = elaborate "aarch64-linux" { static = true; }; }
];
# subAttrNames :: AttrSet -> [ String ]

View File

@@ -5,14 +5,16 @@ let
pkgs = import ./pkgs.nix;
preferences = import ./preferences.nix;
cross = import ./cross.nix;
static = import ./static.nix;
pkgs-ccache = import ./pkgs-ccache.nix;
pkgs-debug = import ./pkgs-debug.nix;
in
final: prev:
let
optional = cond: overlay: if cond then overlay else (_: _: {});
isCross = prev.stdenv.hostPlatform != prev.stdenv.buildPlatform;
ifCross = overlay: if isCross then overlay else (_: _: {});
# isCross = !(prev.stdenv.buildPlatform.canExecute prev.stdenv.hostPlatform);
isStatic = prev.stdenv.hostPlatform.isStatic;
renderOverlays = overlays: builtins.foldl'
(acc: thisOverlay: acc // (thisOverlay final acc))
prev
@@ -21,7 +23,8 @@ in
renderOverlays [
pkgs
preferences
(ifCross cross)
(optional isCross cross)
(optional isStatic static)
pkgs-ccache
pkgs-debug
]

41
overlays/static.nix Normal file
View File

@@ -0,0 +1,41 @@
final: prev:
with final;
let
inherit (stdenv.hostPlatform) hasSharedLibraries;
in
{
# glibcLocales is null on musl, but some packages still refer to it.
# is this sensible? idk.
glibcLocales = final.pkgsCross.gnu64.glibcLocales;
# nixpkgs' gobject-introspection has all `isStatic` platforms as badPlatforms,
# but hopefully it's just `hasSharedLibraries == false` that's broken (untested)
# gobject-introspection = prev.gobject-introspection.overrideAttrs (upstream: {
# meta = upstream.meta // {
# badPlatforms = [];
# };
# });
# gobject-introspection = if hasSharedLibraries then prev.gobject-introspection else null;
libglvnd = prev.libglvnd.overrideAttrs (upstream: {
meta = upstream.meta // {
# mark as not bad, to unblock an assertion in SDL3.
#
# glvnd claims static linking isn't supported, but i think they're actually
# talking about the case of `dlopen` not being available. there's a different stdenv attr to check for that.
# <https://gitlab.freedesktop.org/glvnd/libglvnd/-/issues/212>
badPlatforms = [];
};
});
# networkmanager = prev.networkmanager.override {
# gobject-introspection = if hasSharedLibraries then gobject-introspection else null;
# };
# sdl3 = prev.sdl3.override {
# # ibusMinimal -> gobject-introspection -> doesn't eval.
# # TODO: upstream this fix, or a patch that build ibus w/o introspection.
# ibusSupport = !hasSharedLibraries;
# };
}

View File

@@ -142,15 +142,37 @@ let
'';
};
nixpkgsArgs = commonNixpkgsArgs // {
nativeNixpkgsArgs = commonNixpkgsArgs // {
config = {
allowUnfree = true; # NIXPKGS_ALLOW_UNFREE=1
allowBroken = true; # NIXPKGS_ALLOW_BROKEN=1
allowUnsupportedSystem = true; # NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1
};
} // optionalAttrs (system != localSystem) {
};
nixpkgsArgs = nativeNixpkgsArgs // optionalAttrs (system != localSystem) {
# XXX(2023/12/11): cache.nixos.org uses `system = ...` instead of `hostPlatform.system`, and that choice impacts the closure of every package.
# so avoid specifying hostPlatform.system on non-cross builds, so i can use upstream caches.
crossSystem = system;
# config = nativeNixpkgsArgs.config // optionalAttrs (system.isStatic && system.hasSharedLibraries) {
# # default nixpkgs' behavior when `isStatic` is to _never_ build shared objects.
# replaceCrossStdenv = { buildPackages, baseStdenv }: baseStdenv.override (old: {
# # mkDerivationFromStdenv = _stdenv: args: baseStdenv.mkDerivation (args // {
# # dontAddStaticConfigureFlags = args.dontAddStaticConfigureFlags or true;
# # });
# # mkDerivationFromStdenv = _stdenv: args: (baseStdenv.mkDerivation args).overrideAttrs (prev: {
# # dontAddStaticConfigureFlags = prev.dontAddStaticConfigureFlags or true;
# # # dontAddStaticConfigureFlags = args.dontAddStaticConfigureFlags or true;
# # });
# mkDerivationFromStdenv = _stdenv: args: (baseStdenv.mkDerivation args).overrideAttrs (prev: {
# # this is not wholly correct; goal is to undo some effects of pkgs/stdenv/adapters.nix' makeStatic
# # to build BOTH .a and .so files (but default to static)
# configureFlags = buildPackages.lib.remove "--disable-shared" (prev.configureFlags or args.configureFlags or []);
# # cmakeFlags = buildPackages.lib.remove "-DBUILD_SHARED_LIBS:BOOL=OFF" (
# # buildPackages.lib.remove "-DCMAKE_SKIP_INSTALL_RPATH=On" (prev.cmakeFlags or args.cmakeFlags or [])
# # );
# });
# });
# };
};
nixpkgs = import patchedSrc nixpkgsArgs;
in

View File

@@ -66,6 +66,12 @@ in
hash = "sha256-zfGymC2uUpq10tr4LHLv3vQUmDe8zbL3Qm7sV/AzsQY=";
})
(fetchpatch' {
name = "openssh: fix compilation to static hosts";
prUrl = "https://github.com/NixOS/nixpkgs/pull/420469";
hash = "sha256-mMJSb7Q+zFuTlCzwfGGaix17nitAK9Q9Syxxc2jqUy8=";
})
# (fetchpatch' {
# # XXX(2025-01-06): patch does not produce valid binaries for cross
# name = "lua-language-server: fix cross compiling";