uwsgi: refactor, throw sensible error if plugin is not found
This commit is contained in:
@@ -1,28 +1,35 @@
|
|||||||
{ stdenv, lib, fetchurl, pkgconfig, jansson
|
{ stdenv, lib, fetchurl, pkgconfig, jansson
|
||||||
# plugins: list of strings, eg. [python2, python3]
|
# plugins: list of strings, eg. [ "python2" "python3" ]
|
||||||
, plugins
|
, plugins
|
||||||
, pam, withPAM ? stdenv.isLinux
|
, pam, withPAM ? false
|
||||||
, systemd, withSystemd ? stdenv.isLinux
|
, systemd, withSystemd ? false
|
||||||
, python2, python3, ncurses
|
, python2, python3, ncurses
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let pythonPlugin = pkg : { name = "python${if pkg ? isPy2 then "2" else "3"}";
|
let pythonPlugin = pkg : lib.nameValuePair "python${if pkg ? isPy2 then "2" else "3"}" {
|
||||||
interpreter = pkg;
|
interpreter = pkg.interpreter;
|
||||||
path = "plugins/python";
|
path = "plugins/python";
|
||||||
deps = [ pkg ncurses ];
|
inputs = [ pkg ncurses ];
|
||||||
install = ''
|
install = ''
|
||||||
install -Dm644 uwsgidecorators.py $out/${pkg.sitePackages}/uwsgidecorators.py
|
install -Dm644 uwsgidecorators.py $out/${pkg.sitePackages}/uwsgidecorators.py
|
||||||
${pkg.executable} -m compileall $out/${pkg.sitePackages}/
|
${pkg.executable} -m compileall $out/${pkg.sitePackages}/
|
||||||
${pkg.executable} -O -m compileall $out/${pkg.sitePackages}/
|
${pkg.executable} -O -m compileall $out/${pkg.sitePackages}/
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
available = [ (pythonPlugin python2)
|
|
||||||
|
available = lib.listToAttrs [
|
||||||
|
(pythonPlugin python2)
|
||||||
(pythonPlugin python3)
|
(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 {
|
stdenv.mkDerivation rec {
|
||||||
name = "uwsgi-2.0.11.2";
|
name = "uwsgi-2.0.11.2";
|
||||||
@@ -34,17 +41,15 @@ stdenv.mkDerivation rec {
|
|||||||
|
|
||||||
nativeBuildInputs = [ python3 pkgconfig ];
|
nativeBuildInputs = [ python3 pkgconfig ];
|
||||||
|
|
||||||
buildInputs = with stdenv.lib;
|
buildInputs = [ jansson ]
|
||||||
[ jansson ]
|
++ lib.optional withPAM pam
|
||||||
++ optional withPAM pam
|
++ lib.optional withSystemd systemd
|
||||||
++ optional withSystemd systemd
|
++ lib.concatMap (x: x.inputs) needed
|
||||||
++ lib.concatMap (x: x.deps) needed
|
|
||||||
;
|
;
|
||||||
|
|
||||||
basePlugins = with stdenv.lib;
|
basePlugins = lib.concatStringsSep ","
|
||||||
concatStringsSep ","
|
( lib.optional withPAM "pam"
|
||||||
( optional withPAM "pam"
|
++ lib.optional withSystemd "systemd_logger"
|
||||||
++ optional withSystemd "systemd_logger"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
passthru = {
|
passthru = {
|
||||||
@@ -59,12 +64,11 @@ stdenv.mkDerivation rec {
|
|||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
mkdir -p $pluginDir
|
mkdir -p $pluginDir
|
||||||
python3 uwsgiconfig.py --build nixos
|
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 = ''
|
installPhase = ''
|
||||||
install -Dm755 uwsgi $out/bin/uwsgi
|
install -Dm755 uwsgi $out/bin/uwsgi
|
||||||
#cp *_plugin.so $pluginDir || true
|
|
||||||
${lib.concatMapStringsSep "\n" (x: x.install) needed}
|
${lib.concatMapStringsSep "\n" (x: x.install) needed}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
|||||||
@@ -3477,6 +3477,8 @@ let
|
|||||||
|
|
||||||
uwsgi = callPackage ../servers/uwsgi {
|
uwsgi = callPackage ../servers/uwsgi {
|
||||||
plugins = [];
|
plugins = [];
|
||||||
|
withPAM = stdenv.isLinux;
|
||||||
|
withSystemd = stdenv.isLinux;
|
||||||
};
|
};
|
||||||
|
|
||||||
vacuum = callPackage ../applications/networking/instant-messengers/vacuum {};
|
vacuum = callPackage ../applications/networking/instant-messengers/vacuum {};
|
||||||
|
|||||||
Reference in New Issue
Block a user