mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-26 21:33:03 +03:00
commit
09c14170d8
@ -5,44 +5,86 @@ with lib;
|
|||||||
let
|
let
|
||||||
cfg = config.services.uwsgi;
|
cfg = config.services.uwsgi;
|
||||||
|
|
||||||
python2Pkgs = pkgs.python2Packages.override {
|
|
||||||
python = pkgs.uwsgi.python2;
|
|
||||||
self = python2Pkgs;
|
|
||||||
};
|
|
||||||
|
|
||||||
python3Pkgs = pkgs.python3Packages.override {
|
|
||||||
python = pkgs.uwsgi.python3;
|
|
||||||
self = python3Pkgs;
|
|
||||||
};
|
|
||||||
|
|
||||||
buildCfg = c: if builtins.typeOf c != "set" then builtins.readFile c else builtins.toJSON {
|
|
||||||
uwsgi =
|
|
||||||
if c.type == "normal"
|
|
||||||
then {
|
|
||||||
pythonpath =
|
|
||||||
(if c ? python2Packages
|
|
||||||
then builtins.map (x: "${x}/${pkgs.uwsgi.python2.sitePackages}") (c.python2Packages python2Pkgs)
|
|
||||||
else [])
|
|
||||||
++ (if c ? python3Packages
|
|
||||||
then builtins.map (x: "${x}/${pkgs.uwsgi.python3.sitePackages}") (c.python3Packages python3Pkgs)
|
|
||||||
else []);
|
|
||||||
plugins = cfg.plugins;
|
|
||||||
} // removeAttrs c [ "type" "python2Packages" "python3Packages" ]
|
|
||||||
else if c.type == "emperor"
|
|
||||||
then {
|
|
||||||
emperor = if builtins.typeOf c.vassals != "set" then c.vassals
|
|
||||||
else pkgs.buildEnv {
|
|
||||||
name = "vassals";
|
|
||||||
paths = mapAttrsToList (n: c: pkgs.writeTextDir "${n}.json" (buildCfg c)) c.vassals;
|
|
||||||
};
|
|
||||||
} // removeAttrs c [ "type" "vassals" ]
|
|
||||||
else abort "type should be either 'normal' or 'emperor'";
|
|
||||||
};
|
|
||||||
|
|
||||||
uwsgi = pkgs.uwsgi.override {
|
uwsgi = pkgs.uwsgi.override {
|
||||||
plugins = cfg.plugins;
|
plugins = cfg.plugins;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
buildCfg = name: c:
|
||||||
|
let
|
||||||
|
plugins =
|
||||||
|
if any (n: !any (m: m == n) cfg.plugins) (c.plugins or [])
|
||||||
|
then throw "`plugins` attribute in UWSGI configuration contains plugins not in config.services.uwsgi.plugins"
|
||||||
|
else c.plugins or cfg.plugins;
|
||||||
|
|
||||||
|
hasPython = v: filter (n: n == "python${v}") plugins != [];
|
||||||
|
hasPython2 = hasPython "2";
|
||||||
|
hasPython3 = hasPython "3";
|
||||||
|
|
||||||
|
python =
|
||||||
|
if hasPython2 && hasPython3 then
|
||||||
|
throw "`plugins` attribute in UWSGI configuration shouldn't contain both python2 and python3"
|
||||||
|
else if hasPython2 then uwsgi.python2
|
||||||
|
else if hasPython3 then uwsgi.python3
|
||||||
|
else null;
|
||||||
|
|
||||||
|
pythonPackages = pkgs.pythonPackages.override {
|
||||||
|
inherit python;
|
||||||
|
self = pythonPackages;
|
||||||
|
};
|
||||||
|
|
||||||
|
json = builtins.toJSON {
|
||||||
|
uwsgi =
|
||||||
|
if c.type == "normal"
|
||||||
|
then {
|
||||||
|
inherit plugins;
|
||||||
|
} // removeAttrs c [ "type" "pythonPackages" ]
|
||||||
|
// optionalAttrs (python != null) {
|
||||||
|
pythonpath = "@PYTHONPATH@";
|
||||||
|
env = (c.env or {}) // {
|
||||||
|
PATH = optionalString (c ? env.PATH) "${c.env.PATH}:" + "@PATH@";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if c.type == "emperor"
|
||||||
|
then {
|
||||||
|
emperor = if builtins.typeOf c.vassals != "set" then c.vassals
|
||||||
|
else pkgs.buildEnv {
|
||||||
|
name = "vassals";
|
||||||
|
paths = mapAttrsToList buildCfg c.vassals;
|
||||||
|
};
|
||||||
|
} // removeAttrs c [ "type" "vassals" ]
|
||||||
|
else throw "`type` attribute in UWSGI configuration should be either 'normal' or 'emperor'";
|
||||||
|
};
|
||||||
|
|
||||||
|
in
|
||||||
|
if python == null || c.type != "normal"
|
||||||
|
then pkgs.writeTextDir "${name}.json" json
|
||||||
|
else pkgs.stdenv.mkDerivation {
|
||||||
|
name = "uwsgi-config";
|
||||||
|
inherit json;
|
||||||
|
passAsFile = [ "json" ];
|
||||||
|
nativeBuildInputs = [ pythonPackages.wrapPython ];
|
||||||
|
pythonInputs = (c.pythonPackages or (self: [])) pythonPackages;
|
||||||
|
|
||||||
|
buildCommand = ''
|
||||||
|
mkdir $out
|
||||||
|
declare -A pythonPathsSeen=()
|
||||||
|
program_PYTHONPATH=
|
||||||
|
program_PATH=
|
||||||
|
if [ -n "$pythonInputs" ]; then
|
||||||
|
for i in $pythonInputs; do
|
||||||
|
_addToPythonPath $i
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
# A hack to replace "@PYTHONPATH@" with a JSON list
|
||||||
|
if [ -n "$program_PYTHONPATH" ]; then
|
||||||
|
program_PYTHONPATH="\"''${program_PYTHONPATH//:/\",\"}\""
|
||||||
|
fi
|
||||||
|
substitute $jsonPath $out/${name}.json \
|
||||||
|
--replace '"@PYTHONPATH@"' "[$program_PYTHONPATH]" \
|
||||||
|
--subst-var-by PATH "$program_PATH"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
in {
|
in {
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
@ -71,21 +113,24 @@ in {
|
|||||||
vassals = {
|
vassals = {
|
||||||
moin = {
|
moin = {
|
||||||
type = "normal";
|
type = "normal";
|
||||||
python2Packages = self: with self; [ moinmoin ];
|
pythonPackages = self: with self; [ moinmoin ];
|
||||||
socket = "${config.services.uwsgi.runDir}/uwsgi.sock";
|
socket = "${config.services.uwsgi.runDir}/uwsgi.sock";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
description = ''
|
description = ''
|
||||||
uWSGI configuration. This awaits either a path to file or a set which will be made into one.
|
uWSGI configuration. It awaits an attribute <literal>type</literal> inside which can be either
|
||||||
If given a set, it awaits an attribute <literal>type</literal> which can be either <literal>normal</literal>
|
<literal>normal</literal> or <literal>emperor</literal>.
|
||||||
or <literal>emperor</literal>.
|
|
||||||
|
For <literal>normal</literal> mode you can specify <literal>pythonPackages</literal> as a function
|
||||||
|
from libraries set into a list of libraries. <literal>pythonpath</literal> will be set accordingly.
|
||||||
|
|
||||||
For <literal>normal</literal> mode you can specify <literal>python2Packages</literal> and
|
|
||||||
<literal>python3Packages</literal> as functions from libraries set into lists of libraries.
|
|
||||||
For <literal>emperor</literal> mode, you should use <literal>vassals</literal> attribute
|
For <literal>emperor</literal> mode, you should use <literal>vassals</literal> attribute
|
||||||
which should be either a set of names and configurations or a path to a directory.
|
which should be either a set of names and configurations or a path to a directory.
|
||||||
|
|
||||||
|
Other attributes will be used in configuration file as-is. Notice that you can redefine
|
||||||
|
<literal>plugins</literal> setting here.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -118,7 +163,7 @@ in {
|
|||||||
'';
|
'';
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "notify";
|
Type = "notify";
|
||||||
ExecStart = "${uwsgi}/bin/uwsgi --uid ${cfg.user} --gid ${cfg.group} --json ${pkgs.writeText "uwsgi.json" (buildCfg cfg.instance)}";
|
ExecStart = "${uwsgi}/bin/uwsgi --uid ${cfg.user} --gid ${cfg.group} --json ${buildCfg "server" cfg.instance}/server.json";
|
||||||
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
||||||
ExecStop = "${pkgs.coreutils}/bin/kill -INT $MAINPID";
|
ExecStop = "${pkgs.coreutils}/bin/kill -INT $MAINPID";
|
||||||
NotifyAccess = "main";
|
NotifyAccess = "main";
|
||||||
|
@ -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}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
@ -2,4 +2,5 @@
|
|||||||
plugin_dir = @pluginDir@
|
plugin_dir = @pluginDir@
|
||||||
main_plugin = @basePlugins@
|
main_plugin = @basePlugins@
|
||||||
json = true
|
json = true
|
||||||
|
yaml = false
|
||||||
inherit = base
|
inherit = base
|
||||||
|
@ -3521,6 +3521,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 {};
|
||||||
|
Loading…
Reference in New Issue
Block a user