better python handling in nix module

This commit is contained in:
tuxcoder 2023-12-24 11:10:19 +01:00
parent ddbba31fe6
commit 2d2766ac30

View file

@ -5,6 +5,7 @@ let
format = pkgs.formats.json {}; format = pkgs.formats.json {};
types = lib.types; types = lib.types;
config_oauth_secret = "${cfg.settings.DATA_FOLDER}/lenticular_oauth_secret.toml"; config_oauth_secret = "${cfg.settings.DATA_FOLDER}/lenticular_oauth_secret.toml";
python_env = python.withPackages (ps: with ps; [ lenticular-cloud gevent setuptools ]);
in in
{ {
options = with lib.options; { options = with lib.options; {
@ -135,13 +136,10 @@ in
enable = cfg.enable; enable = cfg.enable;
environment = let environment = let
python_path = with python.pkgs; makePythonPath [ pkgs.lenticular-cloud gevent setuptools ];
config_file = format.generate "lenticular-cloud.json" cfg.settings; config_file = format.generate "lenticular-cloud.json" cfg.settings;
in { in {
# CONFIG_FILE = "/etc/lenticular_cloud/production.conf"; # CONFIG_FILE = "/etc/lenticular_cloud/production.conf";
CONFIG_FILE = "${config_file}:${config_oauth_secret}"; CONFIG_FILE = "${config_file}:${config_oauth_secret}";
PYTHONPATH = "${python_path}";
# PYTHONPATH = "${lenticular-pkg.pythonPath}:${lenticular-pkg}/lib/python3.10/site-packages:${python_path}";
}; };
preStart = '' preStart = ''
if [[ ! -e "${config_oauth_secret}" ]]; then if [[ ! -e "${config_oauth_secret}" ]]; then
@ -156,7 +154,7 @@ in
Type = "simple"; Type = "simple";
WorkingDirectory = cfg.settings.DATA_FOLDER; WorkingDirectory = cfg.settings.DATA_FOLDER;
User = cfg.username; User = cfg.username;
ExecStart = ''${python.pkgs.gunicorn}/bin/gunicorn lenticular_cloud.wsgi --name lenticular_cloud \ ExecStart = ''${python_env}/bin/gunicorn lenticular_cloud.wsgi --name lenticular_cloud \
--workers 2 --log-level=info \ --workers 2 --log-level=info \
--bind=unix:/run/${cfg.username}/web.sock \ --bind=unix:/run/${cfg.username}/web.sock \
-k gevent''; -k gevent'';