summaryrefslogtreecommitdiff
path: root/modules/nixos/gotify.nix
diff options
context:
space:
mode:
authorAzat Bahawi <azat@bahawi.net>2022-12-17 16:39:09 +0300
committerAzat Bahawi <azat@bahawi.net>2022-12-17 16:39:09 +0300
commit8f137c28230623259a964484adcf31fe00756594 (patch)
tree82bce6a13fda125087cf6d9dc80aa91d9230d6c4 /modules/nixos/gotify.nix
parent3229e56e0d3620ddc735edcfbbefb167efa3b23f (diff)
2022-12-17
Diffstat (limited to 'modules/nixos/gotify.nix')
-rw-r--r--modules/nixos/gotify.nix75
1 files changed, 75 insertions, 0 deletions
diff --git a/modules/nixos/gotify.nix b/modules/nixos/gotify.nix
new file mode 100644
index 0000000..db47bb4
--- /dev/null
+++ b/modules/nixos/gotify.nix
@@ -0,0 +1,75 @@
+{
+ config,
+ lib,
+ ...
+}:
+with lib; let
+ cfg = config.nixfiles.modules.gotify;
+in {
+ options.nixfiles.modules.gotify = {
+ enable = mkEnableOption "Gotify";
+
+ domain = mkOption {
+ description = "Domain name sans protocol scheme.";
+ type = with types; str;
+ default = "gotify.${config.networking.domain}";
+ };
+ };
+
+ config = let
+ db = "gotify";
+ in
+ mkIf cfg.enable {
+ nixfiles.modules = {
+ nginx = {
+ enable = true;
+ upstreams.gotify.servers."127.0.0.1:${toString config.services.gotify.port}" = {};
+ virtualHosts.${cfg.domain} = {
+ locations."/" = {
+ proxyPass = "http://gotify";
+ proxyWebsockets = true;
+ };
+ extraConfig = nginxInternalOnly;
+ };
+ };
+ postgresql = {
+ enable = true;
+ extraPostStart = [
+ ''
+ $PSQL "${db}" -tAc 'GRANT ALL ON SCHEMA "public" TO "${db}"'
+ ''
+ ];
+ };
+ };
+
+ services = {
+ gotify = {
+ enable = true;
+ port = 7665;
+ };
+
+ postgresql = {
+ ensureDatabases = [db];
+ ensureUsers = [
+ {
+ name = db;
+ ensurePermissions."DATABASE \"${db}\"" = "ALL";
+ }
+ ];
+ };
+ };
+
+ systemd.services.gotify-server = {
+ after = ["network-online.target" "postgresql.service"];
+ environment = {
+ GOTIFY_DATABASE_DIALECT = "postgres";
+ GOTIFY_DATABASE_CONNECTION = concatStringsSep " " [
+ "host=/run/postgresql"
+ "user=${db}"
+ "dbname=${db}"
+ "sslmode=disable"
+ ];
+ };
+ };
+ };
+}