git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #107403 from gdamjan/fix-uwsgi-php

pkgs/uwsgi: fix compiling and linking the php plugin in uwsgi

commit4b66d030e75a07572d5bad55e66ed88c86eb069f authorMichele Guerini Rocco <rnhmjoj@users.noreply.github.com> dateWed 23 Dec 2020, 00:55 (6 years ago) parenta1c004741af371
4 files changed+83−7
nixos/tests/uwsgi.nix+16−2 pkgs/servers/uwsgi/additional-php-ldflags.patch+13 pkgs/servers/uwsgi/default.nix+25−5 pkgs/servers/uwsgi/no-ext-session-php_session.h-on-NixOS.patch+29
nixos/tests/uwsgi.nix+16−2
@@ -4,12 +4,13 @@ import ./make-test-python.nix ({ pkgs, ... }:
44 meta = with pkgs.stdenv.lib.maintainers; {
55 maintainers = [ lnl7 ];
66 };
7+
78 machine = { pkgs, ... }: {
89 services.uwsgi.enable = true;
9− services.uwsgi.plugins = [ "python3" ];
10+ services.uwsgi.plugins = [ "python3" "php" ];
1011 services.uwsgi.instance = {
1112 type = "emperor";
12− vassals.hello = {
13+ vassals.python = {
1314 type = "normal";
1415 master = true;
1516 workers = 2;
@@ -25,6 +26,17 @@ import ./make-test-python.nix ({ pkgs, ... }:
2526 '';
2627 pythonPackages = self: with self; [ flask ];
2728 };
29+ vassals.php = {
30+ type = "normal";
31+ master = true;
32+ workers = 2;
33+ http-socket = ":8001";
34+ http-socket-modifier1 = 14;
35+ php-index = "index.php";
36+ php-docroot = pkgs.writeTextDir "index.php" ''
37+ <?php echo "Hello World\n"; ?>
38+ '';
39+ };
2840 };
2941 };
3042
@@ -33,6 +45,8 @@ import ./make-test-python.nix ({ pkgs, ... }:
3345 machine.wait_for_unit("multi-user.target")
3446 machine.wait_for_unit("uwsgi.service")
3547 machine.wait_for_open_port(8000)
48+ machine.wait_for_open_port(8001)
3649 assert "Hello World" in machine.succeed("curl -fv 127.0.0.1:8000")
50+ assert "Hello World" in machine.succeed("curl -fv 127.0.0.1:8001")
3751 '';
3852})
pkgs/servers/uwsgi/additional-php-ldflags.patchnew file+13
@@ -0,0 +1,13 @@
1+diff --git a/plugins/php/uwsgiplugin.py b/plugins/php/uwsgiplugin.py
2+index d930c44e..2fcbc22a 100644
3+--- a/plugins/php/uwsgiplugin.py
4++++ b/plugins/php/uwsgiplugin.py
5+@@ -17,6 +17,8 @@ php_version = os.popen(PHPPATH + ' --version').read().rstrip().split('.')[0]
6+ CFLAGS = [os.popen(PHPPATH + ' --includes').read().rstrip(), '-Wno-sign-compare']
7+ LDFLAGS = os.popen(PHPPATH + ' --ldflags').read().rstrip().split()
8+
9++LDFLAGS.append(os.environ.get('UWSGICONFIG_PHP_LDFLAGS', []))
10++
11+ if ld_run_path:
12+ LDFLAGS.append('-L%s' % ld_run_path)
13+ os.environ['LD_RUN_PATH'] = ld_run_path
pkgs/servers/uwsgi/default.nix+25−5
@@ -1,4 +1,4 @@
1−{ stdenv, lib, fetchurl, pkgconfig, jansson, pcre
1+{ stdenv, nixosTests, lib, fetchurl, pkgconfig, jansson, pcre
22# plugins: list of strings, eg. [ "python2" "python3" ]
33, plugins ? []
44, pam, withPAM ? stdenv.isLinux
@@ -38,8 +38,12 @@ let php-embed = php.override {
3838 (lib.nameValuePair "php" {
3939 # usage: https://uwsgi-docs.readthedocs.io/en/latest/PHP.html#running-php-apps-with-nginx
4040 path = "plugins/php";
41− inputs = [ php-embed ] ++ php-embed.buildInputs;
42− NIX_CFLAGS_LINK = [ "-L${libmysqlclient}/lib/mysql" ];
41+ inputs = [
42+ php-embed
43+ php-embed.extensions.session
44+ php-embed.extensions.session.dev
45+ php-embed.unwrapped.dev
46+ ] ++ php-embed.unwrapped.buildInputs;
4347 })
4448 ];
4549
@@ -61,6 +65,11 @@ stdenv.mkDerivation rec {
6165 sha256 = "0256v72b7zr6ds4srpaawk1px3bp0djdwm239w3wrxpw7dzk1gjn";
6266 };
6367
68+ patches = [
69+ ./no-ext-session-php_session.h-on-NixOS.patch
70+ ./additional-php-ldflags.patch
71+ ];
72+
6473 nativeBuildInputs = [ python3 pkgconfig ];
6574
6675 buildInputs = [ jansson pcre ]
@@ -83,6 +92,16 @@ stdenv.mkDerivation rec {
8392 substituteAll ${./nixos.ini} buildconf/nixos.ini
8493 '';
8594
95+ # this is a hack to make the php plugin link with session.so (which on nixos is a separate package)
96+ # the hack works in coordination with ./additional-php-ldflags.patch
97+ UWSGICONFIG_PHP_LDFLAGS = lib.optionalString (builtins.any (x: x.name == "php") needed)
98+ (lib.concatStringsSep "," [
99+ "-Wl"
100+ "-rpath=${php-embed.extensions.session}/lib/php/extensions/"
101+ "--library-path=${php-embed.extensions.session}/lib/php/extensions/"
102+ "-l:session.so"
103+ ]);
104+
86105 buildPhase = ''
87106 mkdir -p $pluginDir
88107 python3 uwsgiconfig.py --build nixos
@@ -94,8 +113,6 @@ stdenv.mkDerivation rec {
94113 ${lib.concatMapStringsSep "\n" (x: x.install or "") needed}
95114 '';
96115
97− NIX_CFLAGS_LINK = toString (lib.optional withSystemd "-lsystemd" ++ lib.concatMap (x: x.NIX_CFLAGS_LINK or []) needed);
98−
99116 meta = with stdenv.lib; {
100117 homepage = "https://uwsgi-docs.readthedocs.org/en/latest/";
101118 description = "A fast, self-healing and developer/sysadmin-friendly application container server coded in pure C";
@@ -103,4 +120,7 @@ stdenv.mkDerivation rec {
103120 maintainers = with maintainers; [ abbradar schneefux globin ];
104121 platforms = platforms.unix;
105122 };
123+
124+ passthru.tests.uwsgi = nixosTests.uwsgi;
125+
106126}
pkgs/servers/uwsgi/no-ext-session-php_session.h-on-NixOS.patchnew file+29
@@ -0,0 +1,29 @@
1+From 6b9b3559d8ce59eda6c5cd6f04224cebaaa5d0ea Mon Sep 17 00:00:00 2001
2+From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?=
3+ =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?=
4+ <gdamjan@gmail.com>
5+Date: Tue, 8 Sep 2020 17:11:39 +0200
6+Subject: [PATCH] no ext/session/php_session.h on NixOS
7+
8+on NixOS php_session.h is in its own package, and is not installed in
9+ext/session/
10+---
11+ plugins/php/common.h | 2 +-
12+ 1 file changed, 1 insertion(+), 1 deletion(-)
13+
14+diff --git a/plugins/php/common.h b/plugins/php/common.h
15+index 9bf1c069..be93f519 100644
16+--- a/plugins/php/common.h
17++++ b/plugins/php/common.h
18+@@ -10,7 +10,7 @@
19+ #endif
20+ #include "ext/standard/info.h"
21+
22+-#include "ext/session/php_session.h"
23++#include "php_session.h"
24+
25+ #include <uwsgi.h>
26+
27+--
28+2.28.0
29+