Unverified Commit 5aa30978 authored by Nick Cao's avatar Nick Cao Committed by GitHub
Browse files

nixos/hatsu: init module (#345102)

parents eea10aa8 2f15b523
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -84,6 +84,8 @@
  alos create normal users and change passwords. Available as
  [services.userborn](#opt-services.userborn.enable)

- [Hatsu](https://github.com/importantimport/hatsu), a self-hosted bridge that interacts with Fediverse on behalf of your static site. Available as [services.hatsu](options.html#opt-services.hatsu).

- [Flood](https://flood.js.org/), a beautiful WebUI for various torrent clients. Available as [services.flood](options.html#opt-services.flood).

- [Firefly-iii Data Importer](https://github.com/firefly-iii/data-importer), a data importer for Firefly-III. Available as [services.firefly-iii-data-importer](options.html#opt-services.firefly-iii-data-importer)
+1 −0
Original line number Diff line number Diff line
@@ -1427,6 +1427,7 @@
  ./services/web-apps/goatcounter.nix
  ./services/web-apps/guacamole-client.nix
  ./services/web-apps/guacamole-server.nix
  ./services/web-apps/hatsu.nix
  ./services/web-apps/healthchecks.nix
  ./services/web-apps/hedgedoc.nix
  ./services/web-apps/hledger-web.nix
+23 −0
Original line number Diff line number Diff line
# Hatsu {#module-services-hatsu}

[Hatsu](https://github.com/importantimport/hatsu) is an fully-automated ActivityPub bridge for static sites.

## Quickstart {#module-services-hatsu-quickstart}

the minimum configuration to start hatsu server would look like this:

```nix
{
  services.hatsu = {
    enable = true;
    settings = {
      HATSU_DOMAIN = "hatsu.local";
      HATSU_PRIMARY_ACCOUNT = "example.com";
    };
  };
}
```

this will start the hatsu server on port 3939 and save the database in `/var/lib/hatsu/hatsu.sqlite3`.

Please refer to the [Hatsu Documentation](https://hatsu.cli.rs) for additional configuration options.
+97 −0
Original line number Diff line number Diff line
{
  lib,
  pkgs,
  config,
  ...
}:
let
  cfg = config.services.hatsu;
in
{
  meta.doc = ./hatsu.md;
  meta.maintainers = with lib.maintainers; [ kwaa ];

  options.services.hatsu = {
    enable = lib.mkEnableOption "Self-hosted and fully-automated ActivityPub bridge for static sites";

    package = lib.mkPackageOption pkgs "hatsu" { };

    settings = lib.mkOption {
      type = lib.types.submodule {
        freeformType =
          with lib.types;
          attrsOf (
            nullOr (oneOf [
              bool
              int
              port
              str
            ])
          );

        options = {
          HATSU_DATABASE_URL = lib.mkOption {
            type = lib.types.str;
            default = "sqlite:///var/lib/hatsu/hatsu.sqlite?mode=rwc";
            example = "postgres://username:password@host/database";
            description = "Database URL.";
          };

          HATSU_DOMAIN = lib.mkOption {
            type = lib.types.str;
            description = "The domain name of your instance (eg 'hatsu.local').";
          };

          HATSU_LISTEN_HOST = lib.mkOption {
            type = lib.types.str;
            default = "127.0.0.1";
            description = "Host where hatsu should listen for incoming requests.";
          };

          HATSU_LISTEN_PORT = lib.mkOption {
            type = lib.types.port;
            apply = toString;
            default = 3939;
            description = "Port where hatsu should listen for incoming requests.";
          };

          HATSU_PRIMARY_ACCOUNT = lib.mkOption {
            type = lib.types.str;
            description = "The primary account of your instance (eg 'example.com').";
          };
        };
      };

      default = { };

      description = ''
        Configuration for Hatsu, see
        <link xlink:href="https://hatsu.cli.rs/admins/environments.html"/>
        for supported values.
      '';
    };
  };

  config = lib.mkIf cfg.enable {
    systemd.services.hatsu = {
      environment = cfg.settings;

      description = "Hatsu server";
      documentation = [ "https://hatsu.cli.rs/" ];

      after = [ "network-online.target" ];
      wants = [ "network-online.target" ];

      wantedBy = [ "multi-user.target" ];

      serviceConfig = {
        DynamicUser = true;
        ExecStart = "${lib.getExe cfg.package}";
        Restart = "on-failure";
        StateDirectory = "hatsu";
        Type = "simple";
        WorkingDirectory = "%S/hatsu";
      };
    };
  };
}