idiosyn/overlay.nix
2024-07-29 18:21:13 +02:00

113 lines
3 KiB
Nix

{ nixpkgs, ... }: final: prev:
let
inherit (builtins) trace traceVerbose;
inherit (prev) lib fetchpatch;
inherit (final) hostPlatform addAttrsToDerivation;
inherit (lib.attrsets) optionalAttrs;
inherit (lib.lists)
intersectLists
mutuallyExclusive
subtractLists
toList;
pkgs = import nixpkgs {
inherit (final) overlays;
localSystem = final.buildPlatform;
crossSystem = final.hostPlatform;
config = removeAttrs final.config [
"replaceStdenv"
"replaceCrossStdenv"
];
};
idiosyn = import ./stdenv.nix pkgs;
pname = base:
if base ? pname
then "package ${base.pname}"
else "unknown package";
attrs = pkg: fun: pkg.overrideAttrs (base:
if base ? idiosynAttrGuard
then traceVerbose "Attribute override applied repeatedly on ${pname base}," { }
else { idiosynAttrGuard = null; } // (fun base));
patch = pkg: patches: attrs pkg (base:
if mutuallyExclusive (base.patches or [ ]) patches
then { patches = base.patches or [ ] ++ patches; }
else trace "Patches applied previously for ${pname base}: ${intersectLists base.patches patches}" {
patches = base.patches ++ subtractLists base.patches patches;
});
nocheck = pkg: attrs (base: { doCheck = false; });
alpine-patches = "https://git.alpinelinux.org/aports/plain";
gentoo-patches = "https://gitweb.gentoo.org/repo/gentoo.git/plain";
in optionalAttrs (!prev ? idiosyn) {
inherit idiosyn;
buildPackages = prev.buildPackages // {
stdenv = final.stdenv;
};
busybox = prev.busybox.override {
stdenv = final.gccStdenv;
};
efivar = attrs prev.efivar (base: {
buildFlags = base.buildFlags or [ ]
++ [ "CC=$(CC)" ];
});
icu = attrs prev.icu (base: {
configureFlags = base.configureFlags or [ ]
++ [ "ac_cv_c_bigendian=${if hostPlatform.isBigEndian then "yes" else "no"}" ];
});
keyutils = attrs prev.keyutils (base: {
LDFLAGS = base.LDFLAGS or [ ]
++ [ "-Wl,--undefined-version" ];
});
kexec-tools = prev.kexec-tools.override {
stdenv = final.gccStdenv;
};
libgcrypt = attrs prev.libgcrypt (base: {
configureFlags = base.configureFlags or [ ]
++ [ "--disable-jent-support" ];
});
mbrola = prev.mbrola.override {
stdenv = addAttrsToDerivation (base: {
env = base.env or { } // {
NIX_CFLAGS_COMPILE = toString (toList base.env.NIX_CFLAGS_COMPILE or [ ]
++ [ "-Wno-error=implicit-function-declaration" ]);
};
}) final.stdenv;
};
musl = attrs prev.musl (base: {
LDFLAGS = base.LDFLAGS or [ ]
++ [ "-Wl,-u,__dls2" ];
});
python3 = prev.python3.override {
packageOverrides = py-final: py-prev: {
psutil =
if hostPlatform.isRiscV
then nocheck py-prev.psutil
else py-prev.psutil;
};
};
python3Packages = final.python3.pkgs;
time = patch prev.time [
(fetchpatch {
url = "${gentoo-patches}/sys-process/time/files/time-1.9-implicit-func-decl-clang.patch";
hash = "sha256-Asz8mWxVh4y3In5NU1dDV7nrJO+XlIhmKIvVFuPH8QE=";
})
];
}