2023-09-30 10:58:24 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
2023-03-18 11:00:49 +00:00
|
|
|
let
|
2023-09-30 10:58:24 +00:00
|
|
|
cfg = config.services.lenticular-cloud;
|
|
|
|
python = pkgs.python3;
|
2023-03-18 11:00:49 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = with lib.options; {
|
|
|
|
services.lenticular-cloud ={
|
|
|
|
enable = mkEnableOption "lenticluar service enable";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
config = {
|
2023-09-30 10:58:24 +00:00
|
|
|
environment.systemPackages = [ pkgs.lenticular-cloud ];
|
|
|
|
|
|
|
|
nixpkgs.overlays = [
|
|
|
|
(import ./overlay.nix)
|
|
|
|
];
|
2023-03-18 11:00:49 +00:00
|
|
|
|
|
|
|
users = {
|
|
|
|
groups.lenticular = {
|
|
|
|
};
|
|
|
|
users.lenticular = {
|
|
|
|
createHome = true;
|
|
|
|
home = "/var/lib/lenticular";
|
|
|
|
description = "web server";
|
|
|
|
extraGroups = [
|
|
|
|
];
|
|
|
|
group = "lenticular";
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.lenticular-cloud = {
|
|
|
|
description = "lenticular account";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2023-09-30 10:58:24 +00:00
|
|
|
enable = cfg.enable;
|
2023-03-18 11:00:49 +00:00
|
|
|
|
|
|
|
environment = let
|
2023-09-30 10:58:24 +00:00
|
|
|
python_path = with python.pkgs; makePythonPath [ lenticular-cloud gevent psycopg2];
|
2023-03-18 11:00:49 +00:00
|
|
|
in {
|
|
|
|
CONFIG_FILE = "/etc/lenticular_cloud/production.conf";
|
2023-09-30 10:58:24 +00:00
|
|
|
PYTHONPATH = "${python_path}";
|
|
|
|
# PYTHONPATH = "${lenticular-pkg.pythonPath}:${lenticular-pkg}/lib/python3.10/site-packages:${python_path}";
|
2023-03-18 11:00:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
WorkingDirectory = /var/lib/lenticular;
|
|
|
|
#User="lenticular"; #done by gunicorn
|
|
|
|
ExecStartPre = pkgs.writeScript "lenticular-cloud-server-init" ''
|
|
|
|
#!/bin/sh
|
|
|
|
#cat > /var/lib/lenticular/foobar.conf <<EOF
|
|
|
|
#SECRET_KEY=""
|
|
|
|
#EOF
|
2023-09-30 10:58:24 +00:00
|
|
|
${pkgs.lenticular-cloud}/bin/lenticular_cloud-cli db_upgrade
|
2023-03-18 11:00:49 +00:00
|
|
|
'';
|
2023-09-30 10:58:24 +00:00
|
|
|
ExecStart = ''${python.pkgs.gunicorn}/bin/gunicorn lenticular_cloud.wsgi --name lenticular_cloud \
|
2023-03-18 11:00:49 +00:00
|
|
|
-u lenticular \
|
|
|
|
-g lenticular \
|
|
|
|
--workers 3 --log-level=info \
|
|
|
|
--bind=unix:/run/lenticular.sock \
|
|
|
|
-k gevent'';
|
|
|
|
Restart = "on-failure";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|