10 # plugins: list of strings, eg. [ "python2" "python3" ]
12 , pam, withPAM ? stdenv.isLinux
13 , systemd, withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd
14 , libcap, withCap ? stdenv.isLinux
15 , python2, python3, ncurses
17 , makeWrapper, fetchFromGitHub
21 php-embed = php.override {
26 pythonPlugin = pkg : lib.nameValuePair "python${if pkg.isPy2 then "2" else "3"}" {
27 interpreter = pkg.pythonOnBuildForHost.interpreter;
28 path = "plugins/python";
29 inputs = [ pkg ncurses ];
31 install -Dm644 uwsgidecorators.py $out/${pkg.sitePackages}/uwsgidecorators.py
32 ${pkg.pythonOnBuildForHost.executable} -m compileall $out/${pkg.sitePackages}/
33 ${pkg.pythonOnBuildForHost.executable} -O -m compileall $out/${pkg.sitePackages}/
37 available = lib.listToAttrs [
38 (pythonPlugin python2)
39 (pythonPlugin python3)
40 (lib.nameValuePair "rack" {
41 path = "plugins/rack";
44 (lib.nameValuePair "cgi" {
45 # usage: https://uwsgi-docs.readthedocs.io/en/latest/CGI.html?highlight=cgi
49 (lib.nameValuePair "php" {
50 # usage: https://uwsgi-docs.readthedocs.io/en/latest/PHP.html#running-php-apps-with-nginx
54 php-embed.extensions.session
55 php-embed.extensions.session.dev
56 php-embed.unwrapped.dev
57 ] ++ php-embed.unwrapped.buildInputs;
63 all = lib.concatStringsSep ", " (lib.attrNames available);
65 if lib.hasAttr name available
66 then lib.getAttr name available // { inherit name; }
67 else throw "Unknown UWSGI plugin ${name}, available : ${all}";
69 needed = builtins.map getPlugin plugins;
72 stdenv.mkDerivation (finalAttrs: {
76 src = fetchFromGitHub {
79 rev = finalAttrs.version;
80 hash = "sha256-3nmmVNNDvQ1RzaD5BQFrScHHnmUtMwjo3wodEGIJCvI=";
84 ./no-ext-session-php_session.h-on-NixOS.patch
85 ./additional-php-ldflags.patch
94 buildInputs = [ jansson pcre libxcrypt ]
95 ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ expat zlib ]
96 ++ lib.optional withPAM pam
97 ++ lib.optional withSystemd systemd
98 ++ lib.optional withCap libcap
99 ++ lib.concatMap (x: x.inputs) needed;
101 basePlugins = lib.concatStringsSep ","
102 ( lib.optional withPAM "pam"
103 ++ lib.optional withSystemd "systemd_logger"
106 UWSGI_INCLUDES = lib.optionalString withCap "${libcap.dev}/include";
109 inherit python2 python3;
110 tests.uwsgi = nixosTests.uwsgi;
114 for f in uwsgiconfig.py plugins/*/uwsgiplugin.py; do
115 substituteInPlace "$f" \
116 --replace pkg-config "$PKG_CONFIG"
118 sed -e "s/ + php_version//" -i plugins/php/uwsgiplugin.py
124 export pluginDir=$out/lib/uwsgi
125 substituteAll ${./nixos.ini} buildconf/nixos.ini
127 runHook postConfigure
130 # this is a hack to make the php plugin link with session.so (which on nixos is a separate package)
131 # the hack works in coordination with ./additional-php-ldflags.patch
132 UWSGICONFIG_PHP_LDFLAGS = lib.optionalString
133 (builtins.any (x: x.name == "php") needed)
134 (lib.concatStringsSep "," [
136 "-rpath=${php-embed.extensions.session}/lib/php/extensions/"
137 "--library-path=${php-embed.extensions.session}/lib/php/extensions/"
145 python3 uwsgiconfig.py --build nixos
146 ${lib.concatMapStringsSep ";" (x: "${x.preBuild or ""}\n ${x.interpreter or "python3"} uwsgiconfig.py --plugin ${x.path} nixos ${x.name}") needed}
154 install -Dm755 uwsgi $out/bin/uwsgi
155 ${lib.concatMapStringsSep "\n" (x: x.install or "") needed}
160 postFixup = lib.optionalString (builtins.any (x: x.name == "php") needed)
162 wrapProgram $out/bin/uwsgi --set PHP_INI_SCAN_DIR ${php-embed}/lib
166 description = "Fast, self-healing and developer/sysadmin-friendly application container server coded in pure C";
167 homepage = "https://uwsgi-docs.readthedocs.org/en/latest/";
168 license = lib.licenses.gpl2Plus;
169 maintainers = with lib.maintainers; [ abbradar schneefux globin ];
170 platforms = lib.platforms.unix;
171 mainProgram = "uwsgi";