darwin.mkAppleDerivation: use lib.extendMkDerivation (#453094)

This commit is contained in:
Emily 2025-10-23 00:19:23 +00:00 committed by GitHub
commit 8cf6f340f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 51 additions and 69 deletions

View file

@ -19,8 +19,6 @@ mkAppleDerivation (finalAttrs: {
./patches/0001-Support-setting-an-upper-bound-on-versions.patch
];
noCC = true;
nativeBuildInputs = [ unifdef ];
buildPhase = ''

View file

@ -8,45 +8,31 @@ in
fetchFromGitHub,
meson,
ninja,
stdenv,
stdenvNoCC,
xcodeProjectCheckHook,
}:
let
hasBasenamePrefix = prefix: file: lib.hasPrefix prefix (baseNameOf file);
in
lib.makeOverridable (
attrs:
lib.extendMkDerivation {
constructDrv = bootstrapStdenv.mkDerivation;
extendDrvArgs =
finalAttrs: args:
assert args ? releaseName;
let
attrs' = if lib.isFunction attrs then attrs else _: attrs;
attrsFixed = lib.fix attrs';
stdenv' =
if attrsFixed.noCC or false then
stdenvNoCC
else if attrsFixed.noBootstrap or false then
stdenv
else
bootstrapStdenv;
in
stdenv'.mkDerivation (
lib.extends (
self: super:
assert super ? releaseName;
let
inherit (super) releaseName;
inherit (args) releaseName;
info = versions.${releaseName};
files = lib.filesystem.listFilesRecursive (lib.path.append ./. releaseName);
mesonFiles = lib.filter (hasBasenamePrefix "meson") files;
in
# You have to have at least `meson.build.in` when using xcodeHash to trigger the Meson
# build support in `mkAppleDerivation`.
assert super ? xcodeHash -> lib.length mesonFiles > 0;
assert args ? xcodeHash -> lib.length mesonFiles > 0;
{
pname = super.pname or releaseName;
pname = args.pname or releaseName;
inherit (info) version;
src = super.src or fetchFromGitHub {
src = args.src or fetchFromGitHub {
owner = "apple-oss-distributions";
repo = releaseName;
rev = info.rev or "${releaseName}-${info.version}";
@ -62,11 +48,11 @@ lib.makeOverridable (
teams = [ lib.teams.darwin ];
platforms = lib.platforms.darwin;
}
// super.meta or { };
// args.meta or { };
}
// lib.optionalAttrs (super ? xcodeHash) {
// lib.optionalAttrs (args ? xcodeHash) {
postUnpack =
super.postUnpack or ""
args.postUnpack or ""
+ lib.concatMapStrings (
file:
if baseNameOf file == "meson.build.in" then
@ -75,16 +61,14 @@ lib.makeOverridable (
"cp ${lib.escapeShellArg "${file}"} \"$sourceRoot/\"${lib.escapeShellArg (baseNameOf file)}\n"
) mesonFiles;
xcodeProject = super.xcodeProject or "${releaseName}.xcodeproj";
xcodeProject = args.xcodeProject or "${releaseName}.xcodeproj";
nativeBuildInputs = super.nativeBuildInputs or [ ] ++ [
nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [
meson
ninja
xcodeProjectCheckHook
];
mesonBuildType = "release";
}
) attrs'
)
)
};
}