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

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