From 2f15b523d9b9a9d7e9e303830ce9aca572f43234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=97=8D+85CD?= <50108258+kwaa@users.noreply.github.com> Date: Tue, 1 Oct 2024 00:33:38 +0800 Subject: [PATCH] nixos/hatsu: init module --- .../manual/release-notes/rl-2411.section.md | 2 + nixos/modules/module-list.nix | 1 + nixos/modules/services/web-apps/hatsu.md | 23 +++++ nixos/modules/services/web-apps/hatsu.nix | 97 +++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 nixos/modules/services/web-apps/hatsu.md create mode 100644 nixos/modules/services/web-apps/hatsu.nix diff --git a/nixos/doc/manual/release-notes/rl-2411.section.md b/nixos/doc/manual/release-notes/rl-2411.section.md index f9a5846c1f38..3ae95691c2db 100644 --- a/nixos/doc/manual/release-notes/rl-2411.section.md +++ b/nixos/doc/manual/release-notes/rl-2411.section.md @@ -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) diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 7f6fa1c8e73b..7e17841d2a65 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -1424,6 +1424,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 diff --git a/nixos/modules/services/web-apps/hatsu.md b/nixos/modules/services/web-apps/hatsu.md new file mode 100644 index 000000000000..e2c61d00f121 --- /dev/null +++ b/nixos/modules/services/web-apps/hatsu.md @@ -0,0 +1,23 @@ +# 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. diff --git a/nixos/modules/services/web-apps/hatsu.nix b/nixos/modules/services/web-apps/hatsu.nix new file mode 100644 index 000000000000..093ae150cfdc --- /dev/null +++ b/nixos/modules/services/web-apps/hatsu.nix @@ -0,0 +1,97 @@ +{ + 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 + + 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"; + }; + }; + }; +}