uwsgi: refactor, throw sensible error if plugin is not found

This commit is contained in:
Nikolay Amiantov 2016-02-19 17:00:19 +03:00
parent b64192744a
commit c6f143307c
2 changed files with 27 additions and 21 deletions

View file

@ -1,28 +1,35 @@
{ stdenv, lib, fetchurl, pkgconfig, jansson
# plugins: list of strings, eg. [python2, python3]
# plugins: list of strings, eg. [ "python2" "python3" ]
, plugins
, pam, withPAM ? stdenv.isLinux
, systemd, withSystemd ? stdenv.isLinux
, pam, withPAM ? false
, systemd, withSystemd ? false
, python2, python3, ncurses
}:
let pythonPlugin = pkg : { name = "python${if pkg ? isPy2 then "2" else "3"}";
interpreter = pkg;
let pythonPlugin = pkg : lib.nameValuePair "python${if pkg ? isPy2 then "2" else "3"}" {
interpreter = pkg.interpreter;
path = "plugins/python";
deps = [ pkg ncurses ];
inputs = [ pkg ncurses ];
install = ''
install -Dm644 uwsgidecorators.py $out/${pkg.sitePackages}/uwsgidecorators.py
${pkg.executable} -m compileall $out/${pkg.sitePackages}/
${pkg.executable} -O -m compileall $out/${pkg.sitePackages}/
'';
};
available = [ (pythonPlugin python2)
available = lib.listToAttrs [
(pythonPlugin python2)
(pythonPlugin python3)
];
needed = builtins.filter (x: lib.any (y: x.name == y) plugins) available;
in
assert builtins.filter (x: lib.all (y: y.name != x) available) plugins == [];
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
stdenv.mkDerivation rec {
name = "uwsgi-2.0.11.2";
@ -34,17 +41,15 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ python3 pkgconfig ];
buildInputs = with stdenv.lib;
[ jansson ]
++ optional withPAM pam
++ optional withSystemd systemd
++ lib.concatMap (x: x.deps) needed
buildInputs = [ jansson ]
++ lib.optional withPAM pam
++ lib.optional withSystemd systemd
++ lib.concatMap (x: x.inputs) needed
;
basePlugins = with stdenv.lib;
concatStringsSep ","
( optional withPAM "pam"
++ optional withSystemd "systemd_logger"
basePlugins = lib.concatStringsSep ","
( lib.optional withPAM "pam"
++ lib.optional withSystemd "systemd_logger"
);
passthru = {
@ -59,12 +64,11 @@ stdenv.mkDerivation rec {
buildPhase = ''
mkdir -p $pluginDir
python3 uwsgiconfig.py --build nixos
${lib.concatMapStringsSep ";" (x: "${x.interpreter.interpreter} uwsgiconfig.py --plugin ${x.path} nixos ${x.name}") needed}
${lib.concatMapStringsSep ";" (x: "${x.interpreter} uwsgiconfig.py --plugin ${x.path} nixos ${x.name}") needed}
'';
installPhase = ''
install -Dm755 uwsgi $out/bin/uwsgi
#cp *_plugin.so $pluginDir || true
${lib.concatMapStringsSep "\n" (x: x.install) needed}
'';

View file

@ -3477,6 +3477,8 @@ let
uwsgi = callPackage ../servers/uwsgi {
plugins = [];
withPAM = stdenv.isLinux;
withSystemd = stdenv.isLinux;
};
vacuum = callPackage ../applications/networking/instant-messengers/vacuum {};