diff options
author | Nikolay Amiantov <ab@fmap.me> | 2016-02-19 17:00:19 +0300 |
---|---|---|
committer | Nikolay Amiantov <ab@fmap.me> | 2016-02-19 17:02:40 +0300 |
commit | c6f143307c10ca4ecf448c523267bc37fa10299e (patch) | |
tree | 1ac8c575d12be4f35ca503a4ec1924da5be48a2e /pkgs/servers | |
parent | b64192744a985a5214fb249565bef0841936d4ae (diff) | |
download | nixlib-c6f143307c10ca4ecf448c523267bc37fa10299e.tar nixlib-c6f143307c10ca4ecf448c523267bc37fa10299e.tar.gz nixlib-c6f143307c10ca4ecf448c523267bc37fa10299e.tar.bz2 nixlib-c6f143307c10ca4ecf448c523267bc37fa10299e.tar.lz nixlib-c6f143307c10ca4ecf448c523267bc37fa10299e.tar.xz nixlib-c6f143307c10ca4ecf448c523267bc37fa10299e.tar.zst nixlib-c6f143307c10ca4ecf448c523267bc37fa10299e.zip |
uwsgi: refactor, throw sensible error if plugin is not found
Diffstat (limited to 'pkgs/servers')
-rw-r--r-- | pkgs/servers/uwsgi/default.nix | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/pkgs/servers/uwsgi/default.nix b/pkgs/servers/uwsgi/default.nix index abcbaa04b8c0..2d447d3c82a9 100644 --- a/pkgs/servers/uwsgi/default.nix +++ b/pkgs/servers/uwsgi/default.nix @@ -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} ''; |