1{
2 config,
3 lib,
4 ...
5}: let
6 cfg = config.services.tangled.appview;
7in
8 with lib; {
9 options = {
10 services.tangled.appview = {
11 enable = mkOption {
12 type = types.bool;
13 default = false;
14 description = "Enable tangled appview";
15 };
16 package = mkOption {
17 type = types.package;
18 description = "Package to use for the appview";
19 };
20 port = mkOption {
21 type = types.int;
22 default = 3000;
23 description = "Port to run the appview on";
24 };
25 environmentFile = mkOption {
26 type = with types; nullOr path;
27 default = null;
28 example = "/etc-/appview.env";
29 description = ''
30 Additional environment file as defined in {manpage}`systemd.exec(5)`.
31
32 Sensitive secrets such as {env}`TANGLED_COOKIE_SECRET` may be
33 passed to the service without makeing them world readable in the
34 nix store.
35
36 '';
37 };
38 };
39 };
40
41 config = mkIf cfg.enable {
42 services.redis.servers.appview = {
43 enable = true;
44 port = 6379;
45 };
46
47 systemd.services.appview = {
48 description = "tangled appview service";
49 wantedBy = ["multi-user.target"];
50 after = ["redis-appview.service"];
51 requires = ["redis-appview.service"];
52
53 serviceConfig = {
54 ListenStream = "0.0.0.0:${toString cfg.port}";
55 ExecStart = "${cfg.package}/bin/appview";
56 Restart = "always";
57 EnvironmentFile = optional (cfg.environmentFile != null) cfg.environmentFile;
58 };
59
60 environment = {
61 TANGLED_DB_PATH = "appview.db";
62 };
63 };
64 };
65 }