diff --git a/impure.nix b/impure.nix index 9f403e6e7..15df2177a 100644 --- a/impure.nix +++ b/impure.nix @@ -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 ] diff --git a/overlays/all.nix b/overlays/all.nix index 8e9887f96..96683828e 100644 --- a/overlays/all.nix +++ b/overlays/all.nix @@ -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 ] diff --git a/overlays/static.nix b/overlays/static.nix new file mode 100644 index 000000000..b8d7dbac4 --- /dev/null +++ b/overlays/static.nix @@ -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. + # + 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; + # }; +} diff --git a/pkgs/by-name/nixpkgs-bootstrap/mkNixpkgs.nix b/pkgs/by-name/nixpkgs-bootstrap/mkNixpkgs.nix index 56c947bbf..2978e2e97 100644 --- a/pkgs/by-name/nixpkgs-bootstrap/mkNixpkgs.nix +++ b/pkgs/by-name/nixpkgs-bootstrap/mkNixpkgs.nix @@ -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 diff --git a/pkgs/by-name/nixpkgs-bootstrap/patches.nix b/pkgs/by-name/nixpkgs-bootstrap/patches.nix index b79b33f57..b29355f93 100644 --- a/pkgs/by-name/nixpkgs-bootstrap/patches.nix +++ b/pkgs/by-name/nixpkgs-bootstrap/patches.nix @@ -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";