From 25754a5fc2fe5a9b7b1f1bacbbe289f92972da47 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Mon, 21 Mar 2016 18:46:26 +0300 Subject: uwsgi service: use python.buildEnv, fix PATH --- nixos/modules/services/web-servers/uwsgi.nix | 50 +++++++++------------------- 1 file changed, 16 insertions(+), 34 deletions(-) (limited to 'nixos/modules/services') diff --git a/nixos/modules/services/web-servers/uwsgi.nix b/nixos/modules/services/web-servers/uwsgi.nix index e6c25e6215c1..56f077e62a89 100644 --- a/nixos/modules/services/web-servers/uwsgi.nix +++ b/nixos/modules/services/web-servers/uwsgi.nix @@ -32,17 +32,27 @@ let self = pythonPackages; }; - json = builtins.toJSON { + penv = python.buildEnv.override { + extraLibs = (c.pythonPackages or (self: [])) pythonPackages; + }; + + uwsgiCfg = { 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@"; - }; + pythonpath = "${penv}/${python.sitePackages}"; + env = + # Argh, uwsgi expects list of key-values there instead of a dictionary. + let env' = c.env or []; + getPath = + x: if hasPrefix "PATH=" x + then substring (stringLength "PATH=") (stringLength x) x + else null; + oldPaths = filter (x: x != null) (map getPath env'); + in env' ++ [ "PATH=${optionalString (oldPaths != []) "${last oldPaths}:"}${penv}/bin" ]; } else if c.type == "emperor" then { @@ -55,35 +65,7 @@ let 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 pkgs.writeTextDir "${name}.json" (builtins.toJSON uwsgiCfg); in { -- cgit 1.4.1