1{ config, pkgs, lib, ... }:
2
3with lib;
4
5let cfg = config.services.ombi;
6
7in {
8 options = {
9 services.ombi = {
10 enable = mkEnableOption (lib.mdDoc ''
11 Ombi.
12 Optionally see <https://docs.ombi.app/info/reverse-proxy>
13 on how to set up a reverse proxy
14 '');
15
16 dataDir = mkOption {
17 type = types.str;
18 default = "/var/lib/ombi";
19 description = lib.mdDoc "The directory where Ombi stores its data files.";
20 };
21
22 port = mkOption {
23 type = types.port;
24 default = 5000;
25 description = lib.mdDoc "The port for the Ombi web interface.";
26 };
27
28 openFirewall = mkOption {
29 type = types.bool;
30 default = false;
31 description = lib.mdDoc "Open ports in the firewall for the Ombi web interface.";
32 };
33
34 user = mkOption {
35 type = types.str;
36 default = "ombi";
37 description = lib.mdDoc "User account under which Ombi runs.";
38 };
39
40 group = mkOption {
41 type = types.str;
42 default = "ombi";
43 description = lib.mdDoc "Group under which Ombi runs.";
44 };
45 };
46 };
47
48 config = mkIf cfg.enable {
49 systemd.tmpfiles.rules = [
50 "d '${cfg.dataDir}' 0700 ${cfg.user} ${cfg.group} - -"
51 ];
52
53 systemd.services.ombi = {
54 description = "Ombi";
55 after = [ "network.target" ];
56 wantedBy = [ "multi-user.target" ];
57
58 serviceConfig = {
59 Type = "simple";
60 User = cfg.user;
61 Group = cfg.group;
62 ExecStart = "${pkgs.ombi}/bin/Ombi --storage '${cfg.dataDir}' --host 'http://*:${toString cfg.port}'";
63 Restart = "on-failure";
64 };
65 };
66
67 networking.firewall = mkIf cfg.openFirewall {
68 allowedTCPPorts = [ cfg.port ];
69 };
70
71 users.users = mkIf (cfg.user == "ombi") {
72 ombi = {
73 isSystemUser = true;
74 group = cfg.group;
75 home = cfg.dataDir;
76 };
77 };
78
79 users.groups = mkIf (cfg.group == "ombi") { ombi = { }; };
80 };
81}