nixpkgs/pkgs/servers/uwsgi/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

174 lines
4.7 KiB
Nix
Raw Normal View History

2023-08-01 07:31:47 +00:00
{ stdenv
, nixosTests
, lib
, pkg-config
, jansson
, pcre
, libxcrypt
, expat
, zlib
# plugins: list of strings, eg. [ "python2" "python3" ]
2019-02-03 15:30:42 +00:00
, plugins ? []
, pam, withPAM ? stdenv.isLinux
, systemd, withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd
2020-11-04 18:21:02 +00:00
, libcap, withCap ? stdenv.isLinux
2014-12-10 01:41:02 +00:00
, python2, python3, ncurses
2021-02-16 06:53:19 +00:00
, ruby, php
, makeWrapper, fetchFromGitHub
2014-12-10 01:41:02 +00:00
}:
2023-08-01 07:31:47 +00:00
let
php-embed = php.override {
embedSupport = true;
apxs2Support = false;
};
pythonPlugin = pkg : lib.nameValuePair "python${if pkg.isPy2 then "2" else "3"}" {
interpreter = pkg.pythonOnBuildForHost.interpreter;
2023-08-01 07:31:47 +00:00
path = "plugins/python";
inputs = [ pkg ncurses ];
install = ''
install -Dm644 uwsgidecorators.py $out/${pkg.sitePackages}/uwsgidecorators.py
${pkg.pythonOnBuildForHost.executable} -m compileall $out/${pkg.sitePackages}/
${pkg.pythonOnBuildForHost.executable} -O -m compileall $out/${pkg.sitePackages}/
2023-08-01 07:31:47 +00:00
'';
};
available = lib.listToAttrs [
(pythonPlugin python2)
(pythonPlugin python3)
(lib.nameValuePair "rack" {
path = "plugins/rack";
inputs = [ ruby ];
})
(lib.nameValuePair "cgi" {
# usage: https://uwsgi-docs.readthedocs.io/en/latest/CGI.html?highlight=cgi
path = "plugins/cgi";
inputs = [ ];
})
(lib.nameValuePair "php" {
# usage: https://uwsgi-docs.readthedocs.io/en/latest/PHP.html#running-php-apps-with-nginx
path = "plugins/php";
inputs = [
php-embed
php-embed.extensions.session
php-embed.extensions.session.dev
php-embed.unwrapped.dev
] ++ php-embed.unwrapped.buildInputs;
})
];
getPlugin = name:
let
all = lib.concatStringsSep ", " (lib.attrNames available);
in
if lib.hasAttr name available
then lib.getAttr name available // { inherit name; }
else throw "Unknown UWSGI plugin ${name}, available : ${all}";
needed = builtins.map getPlugin plugins;
in
2014-12-10 01:41:02 +00:00
2023-08-01 07:31:47 +00:00
stdenv.mkDerivation (finalAttrs: {
pname = "uwsgi";
2024-06-02 04:19:11 +00:00
version = "2.0.26";
2014-12-10 01:41:02 +00:00
src = fetchFromGitHub {
owner = "unbit";
repo = "uwsgi";
2023-08-01 07:31:47 +00:00
rev = finalAttrs.version;
2024-06-02 04:19:11 +00:00
hash = "sha256-3nmmVNNDvQ1RzaD5BQFrScHHnmUtMwjo3wodEGIJCvI=";
2014-12-10 01:41:02 +00:00
};
patches = [
2023-08-01 07:31:47 +00:00
./no-ext-session-php_session.h-on-NixOS.patch
./additional-php-ldflags.patch
];
2023-08-01 07:31:47 +00:00
nativeBuildInputs = [
makeWrapper
pkg-config
python3
];
2014-12-10 01:41:02 +00:00
2022-09-29 23:47:20 +00:00
buildInputs = [ jansson pcre libxcrypt ]
2023-08-01 07:31:47 +00:00
++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ expat zlib ]
++ lib.optional withPAM pam
++ lib.optional withSystemd systemd
++ lib.optional withCap libcap
++ lib.concatMap (x: x.inputs) needed;
2014-12-10 01:41:02 +00:00
basePlugins = lib.concatStringsSep ","
2023-08-01 07:31:47 +00:00
( lib.optional withPAM "pam"
++ lib.optional withSystemd "systemd_logger"
);
2014-12-10 01:41:02 +00:00
2020-11-04 18:21:02 +00:00
UWSGI_INCLUDES = lib.optionalString withCap "${libcap.dev}/include";
2014-12-10 01:41:02 +00:00
passthru = {
inherit python2 python3;
2023-08-01 07:31:47 +00:00
tests.uwsgi = nixosTests.uwsgi;
2014-12-10 01:41:02 +00:00
};
2020-10-03 22:58:17 +00:00
postPatch = ''
for f in uwsgiconfig.py plugins/*/uwsgiplugin.py; do
substituteInPlace "$f" \
--replace pkg-config "$PKG_CONFIG"
done
sed -e "s/ + php_version//" -i plugins/php/uwsgiplugin.py
2021-12-03 00:46:40 +00:00
'';
2020-10-03 22:58:17 +00:00
2014-12-10 01:41:02 +00:00
configurePhase = ''
2023-08-01 07:31:47 +00:00
runHook preConfigure
2014-12-10 01:41:02 +00:00
export pluginDir=$out/lib/uwsgi
substituteAll ${./nixos.ini} buildconf/nixos.ini
2023-08-01 07:31:47 +00:00
runHook postConfigure
2014-12-10 01:41:02 +00:00
'';
# this is a hack to make the php plugin link with session.so (which on nixos is a separate package)
# the hack works in coordination with ./additional-php-ldflags.patch
2023-08-01 07:31:47 +00:00
UWSGICONFIG_PHP_LDFLAGS = lib.optionalString
(builtins.any (x: x.name == "php") needed)
(lib.concatStringsSep "," [
"-Wl"
"-rpath=${php-embed.extensions.session}/lib/php/extensions/"
"--library-path=${php-embed.extensions.session}/lib/php/extensions/"
"-l:session.so"
]);
2014-12-10 01:41:02 +00:00
buildPhase = ''
2023-08-01 07:31:47 +00:00
runHook preBuild
2014-12-10 01:41:02 +00:00
mkdir -p $pluginDir
python3 uwsgiconfig.py --build nixos
2016-10-22 12:08:30 +00:00
${lib.concatMapStringsSep ";" (x: "${x.preBuild or ""}\n ${x.interpreter or "python3"} uwsgiconfig.py --plugin ${x.path} nixos ${x.name}") needed}
2023-08-01 07:31:47 +00:00
runHook postBuild
2014-12-10 01:41:02 +00:00
'';
installPhase = ''
2023-08-01 07:31:47 +00:00
runHook preInstall
2014-12-10 01:41:02 +00:00
install -Dm755 uwsgi $out/bin/uwsgi
2016-06-20 23:39:55 +00:00
${lib.concatMapStringsSep "\n" (x: x.install or "") needed}
2023-08-01 07:31:47 +00:00
runHook postInstall
2014-12-10 01:41:02 +00:00
'';
postFixup = lib.optionalString (builtins.any (x: x.name == "php") needed)
''
wrapProgram $out/bin/uwsgi --set PHP_INI_SCAN_DIR ${php-embed}/lib
'';
2023-08-01 07:31:47 +00:00
meta = {
description = "Fast, self-healing and developer/sysadmin-friendly application container server coded in pure C";
2023-08-01 07:31:47 +00:00
homepage = "https://uwsgi-docs.readthedocs.org/en/latest/";
2024-05-23 08:44:51 +00:00
license = lib.licenses.gpl2Plus;
2023-08-01 07:31:47 +00:00
maintainers = with lib.maintainers; [ abbradar schneefux globin ];
platforms = lib.platforms.unix;
2023-11-23 21:09:35 +00:00
mainProgram = "uwsgi";
2014-12-10 01:41:02 +00:00
};
2023-08-01 07:31:47 +00:00
})