-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.nix
68 lines (56 loc) · 1.84 KB
/
module.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
{ pkgs, lib, config, ... }:
with lib;
let
cfg = config.services.ugragatekeeper;
configFmt = pkgs.formats.yaml {};
configFile = configFmt.generate "ugragatekeeper.yaml" cfg.config;
# ugragatekeeper = pkgs.callPackage "/root/ugragatekeeper" {};
in {
options = {
services.ugragatekeeper = {
enable = mkEnableOption "ugragatekeeper";
config = mkOption {
type = configFmt.type;
default = {};
description = "Configuration for ugragatekeeper.";
};
privateConfigFile = mkOption {
type = types.path;
description = "Path to config file with tokens.";
};
domain = mkOption {
type = types.str;
description = "Domain to run ugragatekeeper under.";
};
};
};
config = mkIf cfg.enable {
systemd.services."ugragatekeeper" = {
description = "Bot for keeping order in your Telegram chat";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
serviceConfig = {
LoadCredential = "private_cfg:${cfg.privateConfigFile}";
DynamicUser = true;
RuntimeDirectory = "ugragatekeeper";
RuntimeDirectoryMode = "0750";
Group = "nginx";
PrivateTmp = true;
};
path = with pkgs; [ coreutils yaml-merge ugragatekeeper ];
script = ''
yaml-merge ${configFile} $CREDENTIALS_DIRECTORY/private_cfg > /run/ugragatekeeper/config.yaml
exec ugragatekeeper --config /run/ugragatekeeper/config.yaml --unix /run/ugragatekeeper/http.sock --domain ${cfg.domain}
'';
};
services.nginx = {
enable = true;
virtualHosts."${cfg.domain}" = {
forceSSL = true;
enableACME = true;
locations."/".proxyPass = "http://unix:/run/ugragatekeeper/http.sock";
};
};
};
}