1{
2 lib,
3 pkgs,
4 config,
5 ...
6}:
7let
8 cfg = config.services.hatsu;
9in
10{
11 meta.doc = ./hatsu.md;
12 meta.maintainers = with lib.maintainers; [ kwaa ];
13
14 options.services.hatsu = {
15 enable = lib.mkEnableOption "Self-hosted and fully-automated ActivityPub bridge for static sites";
16
17 package = lib.mkPackageOption pkgs "hatsu" { };
18
19 settings = lib.mkOption {
20 type = lib.types.submodule {
21 freeformType =
22 with lib.types;
23 attrsOf (
24 nullOr (oneOf [
25 bool
26 int
27 port
28 str
29 ])
30 );
31
32 options = {
33 HATSU_DATABASE_URL = lib.mkOption {
34 type = lib.types.str;
35 default = "sqlite:///var/lib/hatsu/hatsu.sqlite?mode=rwc";
36 example = "postgres://username:password@host/database";
37 description = "Database URL.";
38 };
39
40 HATSU_DOMAIN = lib.mkOption {
41 type = lib.types.str;
42 description = "The domain name of your instance (eg 'hatsu.local').";
43 };
44
45 HATSU_LISTEN_HOST = lib.mkOption {
46 type = lib.types.str;
47 default = "127.0.0.1";
48 description = "Host where hatsu should listen for incoming requests.";
49 };
50
51 HATSU_LISTEN_PORT = lib.mkOption {
52 type = lib.types.port;
53 apply = toString;
54 default = 3939;
55 description = "Port where hatsu should listen for incoming requests.";
56 };
57
58 HATSU_PRIMARY_ACCOUNT = lib.mkOption {
59 type = lib.types.str;
60 description = "The primary account of your instance (eg 'example.com').";
61 };
62 };
63 };
64
65 default = { };
66
67 description = ''
68 Configuration for Hatsu, see
69 <link xlink:href="https://hatsu.cli.rs/admins/environments.html"/>
70 for supported values.
71 '';
72 };
73 };
74
75 config = lib.mkIf cfg.enable {
76 systemd.services.hatsu = {
77 environment = cfg.settings;
78
79 description = "Hatsu server";
80 documentation = [ "https://hatsu.cli.rs/" ];
81
82 after = [ "network-online.target" ];
83 wants = [ "network-online.target" ];
84
85 wantedBy = [ "multi-user.target" ];
86
87 serviceConfig = {
88 DynamicUser = true;
89 ExecStart = "${lib.getExe cfg.package}";
90 Restart = "on-failure";
91 StateDirectory = "hatsu";
92 Type = "simple";
93 WorkingDirectory = "%S/hatsu";
94 };
95 };
96 };
97}