summary refs log tree commit diff
path: root/nixos/modules/services
diff options
context:
space:
mode:
authorNikolay Amiantov <ab@fmap.me>2016-03-21 18:46:26 +0300
committerNikolay Amiantov <ab@fmap.me>2016-03-27 19:23:01 +0300
commit25754a5fc2fe5a9b7b1f1bacbbe289f92972da47 (patch)
treecdff6d7bcb49501143e77e1c8e32b60678b8874f /nixos/modules/services
parentea5c7d553c0f43a971fe75216b595a31dc80af94 (diff)
downloadnixlib-25754a5fc2fe5a9b7b1f1bacbbe289f92972da47.tar
nixlib-25754a5fc2fe5a9b7b1f1bacbbe289f92972da47.tar.gz
nixlib-25754a5fc2fe5a9b7b1f1bacbbe289f92972da47.tar.bz2
nixlib-25754a5fc2fe5a9b7b1f1bacbbe289f92972da47.tar.lz
nixlib-25754a5fc2fe5a9b7b1f1bacbbe289f92972da47.tar.xz
nixlib-25754a5fc2fe5a9b7b1f1bacbbe289f92972da47.tar.zst
nixlib-25754a5fc2fe5a9b7b1f1bacbbe289f92972da47.zip
uwsgi service: use python.buildEnv, fix PATH
Diffstat (limited to 'nixos/modules/services')
-rw-r--r--nixos/modules/services/web-servers/uwsgi.nix50
1 files changed, 16 insertions, 34 deletions
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 {