11 # plugins: list of strings, eg. [ "python2" "python3" ]
14 withPAM ? stdenv.hostPlatform.isLinux,
16 withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd,
18 withCap ? stdenv.hostPlatform.isLinux,
29 php-embed = php.override {
36 lib.nameValuePair "python${if pkg.isPy2 then "2" else "3"}" {
37 interpreter = pkg.pythonOnBuildForHost.interpreter;
38 path = "plugins/python";
44 install -Dm644 uwsgidecorators.py $out/${pkg.sitePackages}/uwsgidecorators.py
45 ${pkg.pythonOnBuildForHost.executable} -m compileall $out/${pkg.sitePackages}/
46 ${pkg.pythonOnBuildForHost.executable} -O -m compileall $out/${pkg.sitePackages}/
50 available = lib.listToAttrs [
51 (pythonPlugin python2)
52 (pythonPlugin python3)
53 (lib.nameValuePair "rack" {
54 path = "plugins/rack";
57 (lib.nameValuePair "cgi" {
58 # usage: https://uwsgi-docs.readthedocs.io/en/latest/CGI.html?highlight=cgi
62 (lib.nameValuePair "php" {
63 # usage: https://uwsgi-docs.readthedocs.io/en/latest/PHP.html#running-php-apps-with-nginx
67 php-embed.extensions.session
68 php-embed.extensions.session.dev
69 php-embed.unwrapped.dev
70 ] ++ php-embed.unwrapped.buildInputs;
77 all = lib.concatStringsSep ", " (lib.attrNames available);
79 if lib.hasAttr name available then
80 lib.getAttr name available // { inherit name; }
82 throw "Unknown UWSGI plugin ${name}, available : ${all}";
84 needed = builtins.map getPlugin plugins;
87 stdenv.mkDerivation (finalAttrs: {
91 src = fetchFromGitHub {
94 rev = finalAttrs.version;
95 hash = "sha256-/7Z9lq7JiGBrTpmtbIEqpMg7nw9SVm8ypmzd1/p6xgU=";
99 ./no-ext-session-php_session.h-on-NixOS.patch
100 ./additional-php-ldflags.patch
103 nativeBuildInputs = [
115 ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [
119 ++ lib.optional withPAM pam
120 ++ lib.optional withSystemd systemd
121 ++ lib.optional withCap libcap
122 ++ lib.concatMap (x: x.inputs) needed;
124 basePlugins = lib.concatStringsSep "," (
125 lib.optional withPAM "pam" ++ lib.optional withSystemd "systemd_logger"
128 UWSGI_INCLUDES = lib.optionalString withCap "${libcap.dev}/include";
131 inherit python2 python3;
132 tests.uwsgi = nixosTests.uwsgi;
136 for f in uwsgiconfig.py plugins/*/uwsgiplugin.py; do
137 substituteInPlace "$f" \
138 --replace pkg-config "$PKG_CONFIG"
140 sed -e "s/ + php_version//" -i plugins/php/uwsgiplugin.py
146 export pluginDir=$out/lib/uwsgi
147 substituteAll ${./nixos.ini} buildconf/nixos.ini
149 runHook postConfigure
152 # this is a hack to make the php plugin link with session.so (which on nixos is a separate package)
153 # the hack works in coordination with ./additional-php-ldflags.patch
154 UWSGICONFIG_PHP_LDFLAGS = lib.optionalString (builtins.any (x: x.name == "php") needed) (
155 lib.concatStringsSep "," [
157 "-rpath=${php-embed.extensions.session}/lib/php/extensions/"
158 "--library-path=${php-embed.extensions.session}/lib/php/extensions/"
167 python3 uwsgiconfig.py --build nixos
168 ${lib.concatMapStringsSep ";" (
170 "${x.preBuild or ""}\n ${x.interpreter or "python3"} uwsgiconfig.py --plugin ${x.path} nixos ${x.name}"
179 install -Dm755 uwsgi $out/bin/uwsgi
180 ${lib.concatMapStringsSep "\n" (x: x.install or "") needed}
185 postFixup = lib.optionalString (builtins.any (x: x.name == "php") needed) ''
186 wrapProgram $out/bin/uwsgi --set PHP_INI_SCAN_DIR ${php-embed}/lib
190 description = "Fast, self-healing and developer/sysadmin-friendly application container server coded in pure C";
191 homepage = "https://uwsgi-docs.readthedocs.org/en/latest/";
192 license = lib.licenses.gpl2Plus;
193 maintainers = with lib.maintainers; [
198 platforms = lib.platforms.unix;
199 mainProgram = "uwsgi";