From 4be78f0dd3040627cf88fee2c4c4e7f2b0e4af50 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Wed, 5 Jan 2022 14:13:37 +0300 Subject: [PATCH 1/2] uwsgi service: redefine PATH envvar Previously if user had `PATH` variable set we would define several `PATH` variables and trigger a conflict. --- nixos/modules/services/web-servers/uwsgi.nix | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/nixos/modules/services/web-servers/uwsgi.nix b/nixos/modules/services/web-servers/uwsgi.nix index a1cad17336d8..d1748e150c3f 100644 --- a/nixos/modules/services/web-servers/uwsgi.nix +++ b/nixos/modules/services/web-servers/uwsgi.nix @@ -48,13 +48,10 @@ let pyhome = "${pythonEnv}"; 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}:"}${pythonEnv}/bin" ]; + let envs = partition (hasPrefix "PATH=") (c.env or []); + oldPaths = map (x: substring (stringLength "PATH=") (stringLength x) x) envs.right; + paths = oldPaths ++ [ "${pythonEnv}/bin" ]; + in [ "PATH=${concatStringsSep ":" paths}" ] ++ envs.wrong; } else if isEmperor then { From 2be5e93ecca1e1ec03101ca91b949843bf691355 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Sun, 12 Apr 2020 20:25:35 +0300 Subject: [PATCH 2/2] uwsgi service: deduplicate plugins list Duplicates can lead to unnecessary `uwsgi` rebuilds and conflicts. --- nixos/modules/services/web-servers/uwsgi.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/web-servers/uwsgi.nix b/nixos/modules/services/web-servers/uwsgi.nix index d1748e150c3f..1b3474f2f521 100644 --- a/nixos/modules/services/web-servers/uwsgi.nix +++ b/nixos/modules/services/web-servers/uwsgi.nix @@ -20,10 +20,11 @@ let buildCfg = name: c: let - plugins = + 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; + plugins = unique plugins'; hasPython = v: filter (n: n == "python${v}") plugins != []; hasPython2 = hasPython "2"; @@ -222,7 +223,7 @@ in { }; services.uwsgi.package = pkgs.uwsgi.override { - inherit (cfg) plugins; + plugins = unique cfg.plugins; }; }; }