core/pkgs/build-support/php/build-composer-repository.nix

122 lines
3.5 KiB
Nix
Raw Normal View History

2024-06-30 08:16:52 +00:00
{
callPackage,
stdenvNoCC,
lib,
writeTextDir,
fetchFromGitHub,
php,
}:
2024-05-02 00:46:19 +00:00
let
mkComposerRepositoryOverride =
/*
We cannot destruct finalAttrs since the attrset below is used to construct it
and Nix currently does not support lazy attribute names.
{
php ? null,
composer ? null,
composerLock ? "composer.lock",
src,
vendorHash,
...
}@finalAttrs:
*/
finalAttrs: previousAttrs:
let
phpDrv = finalAttrs.php or php;
composer = finalAttrs.composer or phpDrv.packages.composer;
composer-local-repo-plugin = callPackage ./pkgs/composer-local-repo-plugin.nix { };
in
assert (lib.assertMsg (previousAttrs ? src) "mkComposerRepository expects src argument.");
2024-06-30 08:16:52 +00:00
assert (
lib.assertMsg (previousAttrs ? vendorHash) "mkComposerRepository expects vendorHash argument."
);
2024-05-02 00:46:19 +00:00
assert (lib.assertMsg (previousAttrs ? version) "mkComposerRepository expects version argument.");
assert (lib.assertMsg (previousAttrs ? pname) "mkComposerRepository expects pname argument.");
2024-06-30 08:16:52 +00:00
assert (
lib.assertMsg (previousAttrs ? composerNoDev) "mkComposerRepository expects composerNoDev argument."
);
assert (
lib.assertMsg (
previousAttrs ? composerNoPlugins
) "mkComposerRepository expects composerNoPlugins argument."
);
assert (
lib.assertMsg (
previousAttrs ? composerNoScripts
) "mkComposerRepository expects composerNoScripts argument."
);
2024-05-02 00:46:19 +00:00
{
composerNoDev = previousAttrs.composerNoDev or true;
composerNoPlugins = previousAttrs.composerNoPlugins or true;
composerNoScripts = previousAttrs.composerNoScripts or true;
composerStrictValidation = previousAttrs.composerStrictValidation or true;
name = "${previousAttrs.pname}-${previousAttrs.version}-composer-repository";
# See https://github.com/NixOS/nix/issues/6660
dontPatchShebangs = previousAttrs.dontPatchShebangs or true;
nativeBuildInputs = (previousAttrs.nativeBuildInputs or [ ]) ++ [
composer
composer-local-repo-plugin
phpDrv
phpDrv.composerHooks.composerRepositoryHook
];
buildInputs = previousAttrs.buildInputs or [ ];
strictDeps = previousAttrs.strictDeps or true;
# Should we keep these empty phases?
2024-06-30 08:16:52 +00:00
configurePhase =
previousAttrs.configurePhase or ''
runHook preConfigure
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
runHook postConfigure
'';
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
buildPhase =
previousAttrs.buildPhase or ''
runHook preBuild
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
runHook postBuild
'';
2024-05-02 00:46:19 +00:00
doCheck = previousAttrs.doCheck or true;
2024-06-30 08:16:52 +00:00
checkPhase =
previousAttrs.checkPhase or ''
runHook preCheck
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
runHook postCheck
'';
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
installPhase =
previousAttrs.installPhase or ''
runHook preInstall
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
runHook postInstall
'';
2024-05-02 00:46:19 +00:00
doInstallCheck = previousAttrs.doInstallCheck or false;
2024-06-30 08:16:52 +00:00
installCheckPhase =
previousAttrs.installCheckPhase or ''
runHook preInstallCheck
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
runHook postInstallCheck
'';
2024-05-02 00:46:19 +00:00
COMPOSER_CACHE_DIR = "/dev/null";
COMPOSER_MIRROR_PATH_REPOS = "1";
COMPOSER_HTACCESS_PROTECT = "0";
COMPOSER_DISABLE_NETWORK = "0";
outputHashMode = "recursive";
2024-06-30 08:16:52 +00:00
outputHashAlgo =
if (finalAttrs ? vendorHash && finalAttrs.vendorHash != "") then null else "sha256";
2024-05-02 00:46:19 +00:00
outputHash = finalAttrs.vendorHash or "";
};
in
args: (stdenvNoCC.mkDerivation args).overrideAttrs mkComposerRepositoryOverride