Skip to content

Instantly share code, notes, and snippets.

@theoparis
Created June 2, 2025 02:52
Show Gist options
  • Save theoparis/c290bdc071de670ffefa2683c73d13c9 to your computer and use it in GitHub Desktop.
Save theoparis/c290bdc071de670ffefa2683c73d13c9 to your computer and use it in GitHub Desktop.
useWildLinker (WIP)
{
pkgs ? import ../nixpkgs { },
}:
let
lib = pkgs.lib;
# N.B. Keep in sync with default arg for stdenv/generic.
defaultMkDerivationFromStdenv =
stdenv:
(import ../nixpkgs/pkgs/stdenv/generic/make-derivation.nix {
inherit lib;
config = pkgs.config;
} stdenv).mkDerivation;
# Low level function to help with overriding `mkDerivationFromStdenv`. One
# gives it the old stdenv arguments and a "continuation" function, and
# underneath the final stdenv argument it yields to the continuation to do
# whatever it wants with old `mkDerivation` (old `mkDerivationFromStdenv`
# applied to the *new, final* stdenv) provided for convenience.
withOldMkDerivation =
stdenvSuperArgs: k: stdenvSelf:
let
mkDerivationFromStdenv-super =
stdenvSuperArgs.mkDerivationFromStdenv or defaultMkDerivationFromStdenv;
mkDerivationSuper = mkDerivationFromStdenv-super stdenvSelf;
in
k stdenvSelf mkDerivationSuper;
# Wrap the original `mkDerivation` providing extra args to it.
extendMkDerivationArgs =
old: f:
withOldMkDerivation old (
_: mkDerivationSuper: args:
(mkDerivationSuper args).overrideAttrs f
);
wild = pkgs.buildPackages.wild.overrideAttrs (old: {
doCheck = false;
});
useWildLinker =
stdenv:
if !stdenv.targetPlatform.isLinux then
throw "Wild cannot be used outside of Linux"
else
stdenv.override (
old:
{
allowedRequisites = null;
cc = stdenv.cc;
}
//
lib.optionalAttrs
(stdenv.cc.isClang || (stdenv.cc.isGNU && lib.versionAtLeast stdenv.cc.version "12"))
{
mkDerivationFromStdenv = extendMkDerivationArgs old (args: {
NIX_CFLAGS_LINK = toString (args.NIX_CFLAGS_LINK or "") + " --ld-path=${wild}/bin/wild";
});
}
);
stdenv = useWildLinker pkgs.clangStdenv;
in
pkgs.hello.override {
inherit stdenv;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment