2023-11-18 16:06:29 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, buildGoModule
|
|
|
|
, fetchFromGitHub
|
|
|
|
, php
|
|
|
|
, testers
|
|
|
|
, frankenphp
|
2023-12-02 14:16:29 +00:00
|
|
|
, darwin
|
|
|
|
, pkg-config
|
2023-12-10 16:17:43 +00:00
|
|
|
, makeBinaryWrapper
|
2023-11-18 16:06:29 +00:00
|
|
|
, runCommand
|
|
|
|
, writeText
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
phpEmbedWithZts = php.override {
|
|
|
|
embedSupport = true;
|
|
|
|
ztsSupport = true;
|
2023-12-02 14:16:29 +00:00
|
|
|
staticSupport = stdenv.isDarwin;
|
|
|
|
zendSignalsSupport = false;
|
|
|
|
zendMaxExecutionTimersSupport = stdenv.isLinux;
|
2023-11-18 16:06:29 +00:00
|
|
|
};
|
|
|
|
phpUnwrapped = phpEmbedWithZts.unwrapped;
|
|
|
|
phpConfig = "${phpUnwrapped.dev}/bin/php-config";
|
|
|
|
pieBuild = stdenv.hostPlatform.isMusl;
|
|
|
|
in buildGoModule rec {
|
|
|
|
pname = "frankenphp";
|
2024-01-06 13:51:13 +00:00
|
|
|
version = "1.0.3";
|
2023-11-18 16:06:29 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "dunglas";
|
|
|
|
repo = "frankenphp";
|
|
|
|
rev = "v${version}";
|
2024-01-06 13:51:13 +00:00
|
|
|
hash = "sha256-DNU127IZ+lw2+NqzrU07ioJKCjjCsnqgS+cqUlX7TUw=";
|
2023-11-18 16:06:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
sourceRoot = "source/caddy";
|
|
|
|
|
|
|
|
# frankenphp requires C code that would be removed with `go mod tidy`
|
|
|
|
# https://github.com/golang/go/issues/26366
|
|
|
|
proxyVendor = true;
|
2023-12-25 21:24:11 +00:00
|
|
|
vendorHash = "sha256-ZkbhpY8+BSTSdzQGsvXUfTBdTPUvQ8tHjbnr0lYho5I=";
|
2023-11-18 16:06:29 +00:00
|
|
|
|
|
|
|
buildInputs = [ phpUnwrapped ] ++ phpUnwrapped.buildInputs;
|
2023-12-10 16:17:43 +00:00
|
|
|
nativeBuildInputs = [ makeBinaryWrapper ] ++ lib.optionals stdenv.isDarwin [ pkg-config darwin.cctools darwin.autoSignDarwinBinariesHook ];
|
2023-11-18 16:06:29 +00:00
|
|
|
|
|
|
|
subPackages = [ "frankenphp" ];
|
|
|
|
|
|
|
|
tags = [ "cgo" "netgo" "ousergo" "static_build" ];
|
|
|
|
|
|
|
|
ldflags = [
|
|
|
|
"-s"
|
|
|
|
"-w"
|
|
|
|
"-X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP ${version} PHP ${phpUnwrapped.version} Caddy'"
|
|
|
|
# pie mode is only available with pkgsMusl, it also automaticaly add -buildmode=pie to $GOFLAGS
|
|
|
|
] ++ (lib.optional pieBuild [ "-static-pie" ]);
|
|
|
|
|
|
|
|
preBuild = ''
|
|
|
|
export CGO_CFLAGS="$(${phpConfig} --includes)"
|
|
|
|
export CGO_LDFLAGS="-DFRANKENPHP_VERSION=${version} \
|
|
|
|
$(${phpConfig} --ldflags) \
|
2023-12-02 14:16:29 +00:00
|
|
|
$(${phpConfig} --libs)"
|
|
|
|
'' + lib.optionalString stdenv.isDarwin ''
|
|
|
|
# replace hard-code homebrew path
|
|
|
|
substituteInPlace ../frankenphp.go \
|
|
|
|
--replace "-L/opt/homebrew/opt/libiconv/lib" "-L${darwin.libiconv}/lib"
|
2023-12-10 16:17:43 +00:00
|
|
|
'';
|
2023-12-02 14:16:29 +00:00
|
|
|
|
2023-12-10 16:17:43 +00:00
|
|
|
preFixup = ''
|
|
|
|
mkdir -p $out/lib
|
2023-12-15 11:18:30 +00:00
|
|
|
ln -s "${phpEmbedWithZts}/lib/php.ini" "$out/lib/frankenphp.ini"
|
2023-12-10 16:17:43 +00:00
|
|
|
|
|
|
|
wrapProgram $out/bin/frankenphp --set-default PHP_INI_SCAN_DIR $out/lib
|
2023-11-18 16:06:29 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
doCheck = false;
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
php = phpEmbedWithZts;
|
|
|
|
tests = {
|
|
|
|
# TODO: real NixOS test with Symfony application
|
|
|
|
version = testers.testVersion {
|
|
|
|
inherit version;
|
|
|
|
package = frankenphp;
|
|
|
|
command = "frankenphp version";
|
|
|
|
};
|
|
|
|
phpinfo = runCommand "php-cli-phpinfo" {
|
|
|
|
phpScript = writeText "phpinfo.php" ''
|
|
|
|
<?php phpinfo();
|
|
|
|
'';
|
|
|
|
} ''
|
|
|
|
${lib.getExe frankenphp} php-cli $phpScript > $out
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
changelog = "https://github.com/dunglas/frankenphp/releases/tag/v${version}";
|
|
|
|
description = "The modern PHP app server";
|
|
|
|
homepage = "https://github.com/dunglas/frankenphp";
|
|
|
|
license = licenses.mit;
|
|
|
|
mainProgram = "frankenphp";
|
2023-12-05 15:11:23 +00:00
|
|
|
maintainers = with maintainers; [ gaelreyrol shyim ];
|
2023-12-02 14:16:29 +00:00
|
|
|
platforms = platforms.linux ++ platforms.darwin;
|
2023-11-18 16:06:29 +00:00
|
|
|
};
|
|
|
|
}
|