blob: 1897cd1bfc213eccf32dfcd6f2738f4cc773c602 (
plain)
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
|
# Temporary definition for push-notification-api service. This will be moved
# into the flake once it's finished.
{ pkgs, lib, config, flakeInputs, ... }:
let
inherit (lib) mkEnableOption mkOption mkIf types;
cfg = config.my.services.push-notification-api;
in
{
options.my.services.push-notification-api = {
enable = mkEnableOption "Push notification API";
package = mkOption {
description = "What package to use.";
default = flakeInputs.push-notification-api.packages.${pkgs.system}.default;
type = types.package;
};
host = mkOption {
description = "Host(name) to passed to server";
type = types.nonEmptyStr;
default = "0.0.0.0";
};
port = mkOption {
description = "Port to listen for requests on";
type = types.port;
default = 8000;
};
openFirewall = mkEnableOption "Poke holes in the firewall to permit LAN connections.";
};
config = mkIf cfg.enable {
# Create a user to run the server under.
users.users.push-notification-api = {
description = "Runs daily dukse reminder";
group = "push-notification-api";
isSystemUser = true;
home = "/srv/push-notification-api";
createHome = true;
};
users.groups.push-notification-api = { };
# Create a service which runs the server.
systemd.services.push-notification-api = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" "netowrk-online.target" ];
wants = [ "network.target" ];
serviceConfig = {
Type = "simple";
User = config.users.users.push-notification-api.name;
Group = config.users.users.push-notification-api.group;
WorkingDirectory = config.users.users.push-notification-api.home;
ExecStart = ''
"${cfg.package}"/bin/push-notification-api --port ${toString cfg.port} --host "${cfg.host}"
'';
};
};
networking.firewall = mkIf cfg.openFirewall {
allowedTCPPorts = [ cfg.port ];
};
};
}
|