Skip to content

Commit

Permalink
copy buildComposerProject from NixOS/nixpkgs#225401 to ngipkgs for te…
Browse files Browse the repository at this point in the history
…sting
  • Loading branch information
albertchae committed Jul 25, 2023
1 parent dc7176e commit 45f433c
Show file tree
Hide file tree
Showing 8 changed files with 469 additions and 0 deletions.
3 changes: 3 additions & 0 deletions all-packages.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{ newScope, ... }:
let
self = rec {
composerHooks = callPackages ./pkgs/build-support/php/hooks { };
mkComposerRepository = callPackage ./pkgs/build-support/php/build-composer-repository.nix { };
buildComposerProject = callPackage ./pkgs/build-support/php/build-composer-project.nix { };
flarum = callPackage ./pkgs/flarum { };
gnunet-messenger-cli = callPackage ./pkgs/gnunet-messenger-cli { };
liberaforms = callPackage ./pkgs/liberaforms { };
Expand Down
61 changes: 61 additions & 0 deletions pkgs/build-support/php/build-composer-project.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{ stdenvNoCC, lib, writeTextDir, php, makeBinaryWrapper, fetchFromGitHub, fetchurl, composer-local-repo-plugin }:

let
buildComposerProjectOverride = finalAttrs: previousAttrs:

let
phpDrv = finalAttrs.php or php;
composer = finalAttrs.composer or phpDrv.packages.composer;
composerLock = finalAttrs.composerLock or null;
in
{
nativeBuildInputs = (previousAttrs.nativeBuildInputs or [ ]) ++ [
composer
composer-local-repo-plugin
phpDrv.composerHooks.composerInstallHook
];

buildInputs = (previousAttrs.buildInputs or [ ]) ++ [
phpDrv
];

patches = previousAttrs.patches or [ ];
strictDeps = previousAttrs.strictDeps or true;

# Should we keep these empty phases?
configurePhase = previousAttrs.configurePhase or ''
runHook preConfigure
runHook postConfigure
'';

buildPhase = previousAttrs.buildPhase or ''
runHook preBuild
runHook postBuild
'';

doCheck = previousAttrs.doCheck or true;
checkPhase = previousAttrs.checkPhase or ''
runHook preCheck
runHook postCheck
'';

installPhase = previousAttrs.installPhase or ''
runHook preInstall
runHook postInstall
'';

composerRepository = phpDrv.mkComposerRepository {
inherit composer composer-local-repo-plugin composerLock;
inherit (finalAttrs) patches pname src vendorHash version;
};

meta = previousAttrs.meta or { } // {
platforms = lib.platforms.all;
};
};
in
args: (stdenvNoCC.mkDerivation args).overrideAttrs buildComposerProjectOverride
79 changes: 79 additions & 0 deletions pkgs/build-support/php/build-composer-repository.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{ stdenvNoCC, lib, writeTextDir, fetchFromGitHub, php, composer-local-repo-plugin }:

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;
in
assert (lib.assertMsg (previousAttrs ? src) "mkComposerRepository expects src argument.");
assert (lib.assertMsg (previousAttrs ? vendorHash) "mkComposerRepository expects vendorHash argument.");
assert (lib.assertMsg (previousAttrs ? version) "mkComposerRepository expects version argument.");
assert (lib.assertMsg (previousAttrs ? pname) "mkComposerRepository expects pname argument.");
{
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.composerHooks.composerRepositoryHook
];

buildInputs = previousAttrs.buildInputs or [ ];

strictDeps = previousAttrs.strictDeps or true;

# Should we keep these empty phases?
configurePhase = previousAttrs.configurePhase or ''
runHook preConfigure
runHook postConfigure
'';

buildPhase = previousAttrs.buildPhase or ''
runHook preBuild
runHook postBuild
'';

doCheck = previousAttrs.doCheck or true;
checkPhase = previousAttrs.checkPhase or ''
runHook preCheck
runHook postCheck
'';

installPhase = previousAttrs.installPhase or ''
runHook preInstall
runHook postInstall
'';

COMPOSER_CACHE_DIR = "/dev/null";
COMPOSER_MIRROR_PATH_REPOS = "1";
COMPOSER_HTACCESS_PROTECT = "0";
COMPOSER_DISABLE_NETWORK = "0";

outputHashMode = "recursive";
outputHashAlgo = if (finalAttrs ? vendorHash && finalAttrs.vendorHash != "") then null else "sha256";
outputHash = finalAttrs.vendorHash or "";
};
in
args: (stdenvNoCC.mkDerivation args).overrideAttrs mkComposerRepositoryOverride
46 changes: 46 additions & 0 deletions pkgs/build-support/php/build-pecl.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{ stdenv, lib, php, autoreconfHook, fetchurl, re2c, nix-update-script }:

{ pname
, version
, internalDeps ? [ ]
, peclDeps ? [ ]
, buildInputs ? [ ]
, nativeBuildInputs ? [ ]
, postPhpize ? ""
, makeFlags ? [ ]
, src ? fetchurl {
url = "https://pecl.php.net/get/${pname}-${version}.tgz";
inherit (args) sha256;
}
, passthru ? { }
, ...
}@args:

stdenv.mkDerivation (args // {
name = "php-${pname}-${version}";
extensionName = pname;

inherit src;

nativeBuildInputs = [ autoreconfHook re2c ] ++ nativeBuildInputs;
buildInputs = [ php ] ++ peclDeps ++ buildInputs;

makeFlags = [ "EXTENSION_DIR=$(out)/lib/php/extensions" ] ++ makeFlags;

autoreconfPhase = ''
phpize
${postPhpize}
${lib.concatMapStringsSep "\n"
(dep: "mkdir -p ext; ln -s ${dep.dev}/include ext/${dep.extensionName}")
internalDeps}
'';
checkPhase = "NO_INTERACTON=yes make test";

passthru = passthru // {
# Thes flags were introduced for `nix-update` so that it can update
# PHP extensions correctly.
# See the corresponding PR: https://github.com/Mic92/nix-update/pull/123
isPhpExtension = true;
updateScript = nix-update-script {};
};
})
111 changes: 111 additions & 0 deletions pkgs/build-support/php/composer-local-repo-plugin.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{ stdenvNoCC, lib, fetchFromGitHub, composer, makeBinaryWrapper }:

stdenvNoCC.mkDerivation (finalAttrs:
let
composerKeys = stdenvNoCC.mkDerivation (finalComposerKeysAttrs: {
pname = "composer-keys";
version = "fa5a62092f33e094073fbda23bbfc7188df3cbc5";

src = fetchFromGitHub {
owner = "composer";
repo = "composer.github.io";
rev = "${finalComposerKeysAttrs.version}";
hash = "sha256-3Sfn71LDG1jHwuEIU8iEnV3k6D6QTX7KVIKVaNSuCVE=";
};

installPhase = ''
runHook preInstall
mkdir -p $out
install releases.pub $out/keys.tags.pub
install snapshots.pub $out/keys.dev.pub
runHook postInstall
'';
});
in
{
pname = "composer-local-repo-plugin";
version = "ff33aaf5454888e2669f366639be9877dceb9599";

src = fetchFromGitHub {
owner = "drupol";
repo = "composer-local-repo-plugin";
rev = finalAttrs.version;
hash = "sha256-nSjAicyvStVoBFm7SJy4EYQIwrAaLjm72XMgsPF3CSg=";
};

COMPOSER_CACHE_DIR = "/dev/null";
COMPOSER_MIRROR_PATH_REPOS = "1";
COMPOSER_HTACCESS_PROTECT = "0";
COMPOSER_DISABLE_NETWORK = "1";

nativeBuildInputs = [
makeBinaryWrapper
];

buildInputs = [
composer
];

configurePhase = ''
runHook preConfigure
export COMPOSER_HOME=${placeholder "out"}
runHook postConfigure
'';

buildPhase = ''
runHook preBuild
# Configure composer globally
composer global init --quiet --no-interaction --no-ansi \
--name="nixos/composer" \
--homepage "https://nixos.org/" \
--description "Composer with drupol/composer-local-repo-plugin" \
--license "MIT"
composer global config --quiet minimum-stability dev
composer global config --quiet prefer-stable true
composer global config --quiet autoloader-suffix "nixPredictableAutoloaderSuffix"
composer global config --quiet apcu-autoloader false
composer global config --quiet allow-plugins.drupol/composer-local-repo-plugin true
composer global config --quiet repo.packagist false
composer global config --quiet repo.plugin path $src
# Install the local repository plugin
composer global require --quiet --no-ansi --no-interaction drupol/composer-local-repo-plugin
runHook postBuild
'';

checkPhase = ''
runHook preCheck
composer global validate --no-ansi
composer global show --no-ansi drupol/composer-local-repo-plugin
runHook postCheck
'';

installPhase = ''
runHook preInstall
mkdir -p $out
cp -ar ${composerKeys}/* $out/
makeWrapper ${composer}/bin/composer $out/bin/composer-local-repo-plugin \
--prefix COMPOSER_HOME : $out
runHook postInstall
'';

meta = {
description = "Composer local repo plugin for Composer";
license = lib.licenses.mit;
homepage = "https://github.com/drupol/composer-local-repo-plugin";
maintainers = lib.teams.php.members;
platforms = lib.platforms.all;
};
})
Loading

0 comments on commit 45f433c

Please sign in to comment.