forked from Deiru2k/miracle-tv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.nix
More file actions
107 lines (105 loc) · 2.86 KB
/
Copy pathmodule.nix
File metadata and controls
107 lines (105 loc) · 2.86 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{ lib, pkgs, config, ... }:
with lib;
let
cfg = config.services.miracle-tv;
miracleSrc = ./.;
miracle-tv = (import "${miracleSrc}/default.nix");
in {
options.services.miracle-tv = {
enable = mkEnableOption "Miracle TV server";
settings = {
nodeEnv = mkOption {
type = types.str;
default = "production";
};
name = mkOption {
type = types.str;
default = "MiracleTV";
};
dataDir = mkOption {
type = types.str;
default = "/var/miracle-tv";
};
enableNginx = mkEnableOption "Enable Nginx Management";
url = mkOption {
type = types.str;
default = "localhost";
};
client = {
hostname = mkOption {
type = types.str;
default = "0.0.0.0";
};
port = mkOption {
type = types.int;
default = 4000;
};
};
server = {
hostname = mkOption {
type = types.str;
default = "0.0.0.0";
};
port = mkOption {
type = types.int;
default = 4000;
};
};
database = {
host = mkOption {
type = types.str;
default = "localhost";
};
port = mkOption {
type = types.int;
default = 28015;
};
db = mkOption {
type = types.str;
default = "miracle-tv";
};
};
};
};
config = let
configFile = pkgs.writeText "config.json" (builtins.toJSON cfg.settings);
in lib.mkIf cfg.enable {
services.nginx.virtualHosts = lib.mkIf cfg.settings.enableNginx {
"${cfg.settings.url}" = {
enableACME = true;
forceSSL = true;
locations."/" = {
proxyPass = "http://localhost:${toString cfg.settings.client.port}/";
extraConfig = ''
proxy_pass_request_headers on;
'';
};
locations."/media" = {
root = "${cfg.settings.dataDir}";
};
locations."/api/" = {
proxyPass = "http://localhost:${toString cfg.settings.server.port}/";
extraConfig = ''
proxy_pass_request_headers on;
'';
};
};
};
systemd.services.miracle-tv = {
wantedBy = [ "multi-user.target" ];
serviceConfig.ExecStart = "${miracle-tv}/bin/miracle-server ${configFile}";
environment = {
NODE_ENV = cfg.settings.nodeEnv;
};
};
systemd.services.miracle-tv-frontend = {
wantedBy = [ "multi-user.target" ];
serviceConfig.ExecStart = "${miracle-tv}/bin/miracle-client -p ${toString cfg.settings.client.port} -H ${cfg.settings.client.hostname}";
environment = {
NEXT_PUBLIC_API_URL = "https://${cfg.settings.url}/api/graphql";
NEXT_PUBLIC_MEDIA_URL = "https://${cfg.settings.url}/media";
NODE_ENV = cfg.settings.nodeEnv;
};
};
};
}