diff options
Diffstat (limited to 'customized/uwsgi.nix')
| -rw-r--r-- | customized/uwsgi.nix | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/customized/uwsgi.nix b/customized/uwsgi.nix index f3494264..87bd3238 100644 --- a/customized/uwsgi.nix +++ b/customized/uwsgi.nix | |||
| @@ -1,31 +1,40 @@ | |||
| 1 | { stdenv, lib, fetchurl, pkgconfig, jansson | 1 | { stdenv, lib, fetchurl, pkgconfig, jansson |
| 2 | # plugins: list of strings, eg. [ "python2" "python3" ] | ||
| 2 | , plugins | 3 | , plugins |
| 3 | , pam, withPAM ? stdenv.isLinux | 4 | , pam, withPAM ? stdenv.isLinux |
| 4 | , systemd, withSystemd ? stdenv.isLinux | 5 | , systemd, withSystemd ? stdenv.isLinux |
| 5 | , python2, python3, ncurses | 6 | , python2, python3, ncurses |
| 6 | , extraPlugins ? [] | 7 | , extraPlugins ? {} |
| 7 | }: | 8 | }: |
| 8 | 9 | ||
| 9 | let pythonPlugin = pkg : { name = "python${if pkg ? isPy2 then "2" else "3"}"; | 10 | let pythonPlugin = pkg : lib.nameValuePair "python${if pkg ? isPy2 then "2" else "3"}" { |
| 10 | interpreter = pkg; | 11 | interpreter = pkg.interpreter; |
| 11 | path = "plugins/python"; | 12 | path = "plugins/python"; |
| 12 | deps = [ pkg ncurses ]; | 13 | inputs = [ pkg ncurses ]; |
| 13 | install = '' | 14 | install = '' |
| 14 | install -Dm644 uwsgidecorators.py $out/${pkg.sitePackages}/uwsgidecorators.py | 15 | install -Dm644 uwsgidecorators.py $out/${pkg.sitePackages}/uwsgidecorators.py |
| 15 | ${pkg.executable} -m compileall $out/${pkg.sitePackages}/ | 16 | ${pkg.executable} -m compileall $out/${pkg.sitePackages}/ |
| 16 | ${pkg.executable} -O -m compileall $out/${pkg.sitePackages}/ | 17 | ${pkg.executable} -O -m compileall $out/${pkg.sitePackages}/ |
| 17 | ''; | 18 | ''; |
| 18 | }; | 19 | }; |
| 19 | available = [ (pythonPlugin python2) | 20 | |
| 21 | available = (lib.listToAttrs [ | ||
| 22 | (pythonPlugin python2) | ||
| 20 | (pythonPlugin python3) | 23 | (pythonPlugin python3) |
| 21 | ] ++ extraPlugins; | 24 | ]) // extraPlugins; |
| 22 | needed = builtins.filter (x: lib.any (y: x.name == y) plugins) available; | ||
| 23 | in | ||
| 24 | 25 | ||
| 25 | assert builtins.filter (x: lib.all (y: y.name != x) available) plugins == []; | 26 | getPlugin = name: |
| 27 | let all = lib.concatStringsSep ", " (lib.attrNames available); | ||
| 28 | in if lib.hasAttr name available | ||
| 29 | then lib.getAttr name available // { inherit name; } | ||
| 30 | else throw "Unknown UWSGI plugin ${name}, available : ${all}"; | ||
| 31 | |||
| 32 | needed = builtins.map getPlugin plugins; | ||
| 33 | in | ||
| 26 | 34 | ||
| 27 | stdenv.mkDerivation rec { | 35 | stdenv.mkDerivation rec { |
| 28 | name = "uwsgi-2.0.13.1"; | 36 | name = "uwsgi-${version}"; |
| 37 | version = "2.0.13.1"; | ||
| 29 | 38 | ||
| 30 | src = fetchurl { | 39 | src = fetchurl { |
| 31 | url = "http://projects.unbit.it/downloads/${name}.tar.gz"; | 40 | url = "http://projects.unbit.it/downloads/${name}.tar.gz"; |
| @@ -34,17 +43,15 @@ stdenv.mkDerivation rec { | |||
| 34 | 43 | ||
| 35 | nativeBuildInputs = [ python3 pkgconfig ]; | 44 | nativeBuildInputs = [ python3 pkgconfig ]; |
| 36 | 45 | ||
| 37 | buildInputs = with stdenv.lib; | 46 | buildInputs = [ jansson ] |
| 38 | [ jansson ] | 47 | ++ lib.optional withPAM pam |
| 39 | ++ optional withPAM pam | 48 | ++ lib.optional withSystemd systemd |
| 40 | ++ optional withSystemd systemd | 49 | ++ lib.concatMap (x: x.inputs) needed |
| 41 | ++ lib.concatMap (x: x.deps) needed | ||
| 42 | ; | 50 | ; |
| 43 | 51 | ||
| 44 | basePlugins = with stdenv.lib; | 52 | basePlugins = lib.concatStringsSep "," |
| 45 | concatStringsSep "," | 53 | ( lib.optional withPAM "pam" |
| 46 | ( optional withPAM "pam" | 54 | ++ lib.optional withSystemd "systemd_logger" |
| 47 | ++ optional withSystemd "systemd_logger" | ||
| 48 | ); | 55 | ); |
| 49 | 56 | ||
| 50 | passthru = { | 57 | passthru = { |
| @@ -59,21 +66,21 @@ stdenv.mkDerivation rec { | |||
| 59 | buildPhase = '' | 66 | buildPhase = '' |
| 60 | mkdir -p $pluginDir | 67 | mkdir -p $pluginDir |
| 61 | python3 uwsgiconfig.py --build nixos | 68 | python3 uwsgiconfig.py --build nixos |
| 62 | ${lib.concatMapStringsSep ";" (x: "${x.interpreter.interpreter} uwsgiconfig.py --plugin ${x.path} nixos ${x.name}") needed} | 69 | ${lib.concatMapStringsSep ";" (x: "${x.interpreter} uwsgiconfig.py --plugin ${x.path} nixos ${x.name}") needed} |
| 63 | ''; | 70 | ''; |
| 64 | 71 | ||
| 65 | installPhase = '' | 72 | installPhase = '' |
| 66 | install -Dm755 uwsgi $out/bin/uwsgi | 73 | install -Dm755 uwsgi $out/bin/uwsgi |
| 67 | #cp *_plugin.so $pluginDir || true | ||
| 68 | ${lib.concatMapStringsSep "\n" (x: x.install) needed} | 74 | ${lib.concatMapStringsSep "\n" (x: x.install) needed} |
| 69 | ''; | 75 | ''; |
| 70 | 76 | ||
| 71 | NIX_CFLAGES_LINK = [ "-lsystemd" ]; | 77 | NIX_CFLAGS_LINK = [ "-lsystemd" ]; |
| 72 | 78 | ||
| 73 | meta = with stdenv.lib; { | 79 | meta = with stdenv.lib; { |
| 74 | homepage = http://uwsgi-docs.readthedocs.org/en/latest/; | 80 | homepage = http://uwsgi-docs.readthedocs.org/en/latest/; |
| 75 | description = "A fast, self-healing and developer/sysadmin-friendly application container server coded in pure C"; | 81 | description = "A fast, self-healing and developer/sysadmin-friendly application container server coded in pure C"; |
| 76 | license = licenses.gpl2; | 82 | license = licenses.gpl2; |
| 77 | maintainers = with maintainers; [ abbradar ]; | 83 | maintainers = with maintainers; [ abbradar ]; |
| 84 | platforms = platforms.linux; | ||
| 78 | }; | 85 | }; |
| 79 | } | 86 | } |
