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

+27 -21
+25 -21
pkgs/servers/uwsgi/default.nix
··· 1 1 { stdenv, lib, fetchurl, pkgconfig, jansson 2 - # plugins: list of strings, eg. [python2, python3] 2 + # plugins: list of strings, eg. [ "python2" "python3" ] 3 3 , plugins 4 - , pam, withPAM ? stdenv.isLinux 5 - , systemd, withSystemd ? stdenv.isLinux 4 + , pam, withPAM ? false 5 + , systemd, withSystemd ? false 6 6 , python2, python3, ncurses 7 7 }: 8 8 9 - let pythonPlugin = pkg : { name = "python${if pkg ? isPy2 then "2" else "3"}"; 10 - interpreter = pkg; 9 + let pythonPlugin = pkg : lib.nameValuePair "python${if pkg ? isPy2 then "2" else "3"}" { 10 + interpreter = pkg.interpreter; 11 11 path = "plugins/python"; 12 - deps = [ pkg ncurses ]; 12 + inputs = [ pkg ncurses ]; 13 13 install = '' 14 14 install -Dm644 uwsgidecorators.py $out/${pkg.sitePackages}/uwsgidecorators.py 15 15 ${pkg.executable} -m compileall $out/${pkg.sitePackages}/ 16 16 ${pkg.executable} -O -m compileall $out/${pkg.sitePackages}/ 17 17 ''; 18 18 }; 19 - available = [ (pythonPlugin python2) 19 + 20 + available = lib.listToAttrs [ 21 + (pythonPlugin python2) 20 22 (pythonPlugin python3) 21 23 ]; 22 - needed = builtins.filter (x: lib.any (y: x.name == y) plugins) available; 23 - in 24 24 25 - assert builtins.filter (x: lib.all (y: y.name != x) available) plugins == []; 25 + getPlugin = name: 26 + let all = lib.concatStringsSep ", " (lib.attrNames available); 27 + in if lib.hasAttr name available 28 + then lib.getAttr name available // { inherit name; } 29 + else throw "Unknown UWSGI plugin ${name}, available : ${all}"; 30 + 31 + needed = builtins.map getPlugin plugins; 32 + in 26 33 27 34 stdenv.mkDerivation rec { 28 35 name = "uwsgi-2.0.11.2"; ··· 34 41 35 42 nativeBuildInputs = [ python3 pkgconfig ]; 36 43 37 - buildInputs = with stdenv.lib; 38 - [ jansson ] 39 - ++ optional withPAM pam 40 - ++ optional withSystemd systemd 41 - ++ lib.concatMap (x: x.deps) needed 44 + buildInputs = [ jansson ] 45 + ++ lib.optional withPAM pam 46 + ++ lib.optional withSystemd systemd 47 + ++ lib.concatMap (x: x.inputs) needed 42 48 ; 43 49 44 - basePlugins = with stdenv.lib; 45 - concatStringsSep "," 46 - ( optional withPAM "pam" 47 - ++ optional withSystemd "systemd_logger" 50 + basePlugins = lib.concatStringsSep "," 51 + ( lib.optional withPAM "pam" 52 + ++ lib.optional withSystemd "systemd_logger" 48 53 ); 49 54 50 55 passthru = { ··· 59 64 buildPhase = '' 60 65 mkdir -p $pluginDir 61 66 python3 uwsgiconfig.py --build nixos 62 - ${lib.concatMapStringsSep ";" (x: "${x.interpreter.interpreter} uwsgiconfig.py --plugin ${x.path} nixos ${x.name}") needed} 67 + ${lib.concatMapStringsSep ";" (x: "${x.interpreter} uwsgiconfig.py --plugin ${x.path} nixos ${x.name}") needed} 63 68 ''; 64 69 65 70 installPhase = '' 66 71 install -Dm755 uwsgi $out/bin/uwsgi 67 - #cp *_plugin.so $pluginDir || true 68 72 ${lib.concatMapStringsSep "\n" (x: x.install) needed} 69 73 ''; 70 74
+2
pkgs/top-level/all-packages.nix
··· 3477 3477 3478 3478 uwsgi = callPackage ../servers/uwsgi { 3479 3479 plugins = []; 3480 + withPAM = stdenv.isLinux; 3481 + withSystemd = stdenv.isLinux; 3480 3482 }; 3481 3483 3482 3484 vacuum = callPackage ../applications/networking/instant-messengers/vacuum {};