-
Notifications
You must be signed in to change notification settings - Fork 1
/
service.nix
78 lines (74 loc) · 1.75 KB
/
service.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{ pkgs, config, lib, ... }:
with lib;
let
python3 = pkgs.python311.withPackages (ps: with ps; [
flask
mysql-connector
ping3
requests
psycopg2
gunicorn
]);
cfg = config.services.ssvp;
npmlock2nix = import (builtins.fetchTarball
"https://github.com/nix-community/npmlock2nix/archive/9197bbf.tar.gz"
) {};
nodeModules = npmlock2nix.v2.node_modules {
src = ./.;
installPhase = "mv node_modules $out/";
};
ins = pkgs.runCommand "ssvp" {src = ./.; buildInputs = with pkgs; [ nodejs ];} ''
cp -r --no-preserve=all $src $out
cd $out
cp -r ${nodeModules} node_modules
make
'';
in {
options.services.ssvp = {
enable = mkEnableOption "SSVP Production Environment";
configFile = mkOption {
type = types.str;
description = "Configuration file";
};
};
config = mkIf cfg.enable {
systemd.services.ssvp-gunicorn = {
path = with pkgs; [
python3
which
jq
bash
];
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
script = ''
cd ${ins}
${pkgs.bash}/bin/bash srv/gunicorn.sh
'';
environment = { SSVP_CONFIG = cfg.configFile; };
};
systemd.timers.ssvp-interval = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnUnitActiveSec = "5m";
Unit = "ssvp-interval.service";
};
};
systemd.services.ssvp-interval = {
path = with pkgs; [
python3
bash
];
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
script = ''
cd ${ins}
${python3}/bin/python3 srv/interval.py
'';
serviceConfig = {
Type = "oneshot";
};
environment = { SSVP_CONFIG = cfg.configFile; };
};
};
}