about summary refs log tree commit diff
path: root/modules/matrix
diff options
context:
space:
mode:
Diffstat (limited to 'modules/matrix')
-rw-r--r--modules/matrix/default.nix5
-rw-r--r--modules/matrix/dendrite.nix41
-rw-r--r--modules/matrix/element.nix25
3 files changed, 36 insertions, 35 deletions
diff --git a/modules/matrix/default.nix b/modules/matrix/default.nix
index ef9fb18..781e50f 100644
--- a/modules/matrix/default.nix
+++ b/modules/matrix/default.nix
@@ -1 +1,4 @@
-{ lib, ... }: with lib; { imports = attrValues (modulesIn ./.); }
+{ lib, ... }:
+{
+  imports = lib.modulesIn ./. |> lib.attrValues;
+}
diff --git a/modules/matrix/dendrite.nix b/modules/matrix/dendrite.nix
index c391ba0..960096c 100644
--- a/modules/matrix/dendrite.nix
+++ b/modules/matrix/dendrite.nix
@@ -6,22 +6,21 @@
   this,
   ...
 }:
-with lib;
 let
   cfg = config.nixfiles.modules.matrix.dendrite;
 in
 {
   options.nixfiles.modules.matrix.dendrite = {
-    enable = mkEnableOption "Dendrite Matrix server";
+    enable = lib.mkEnableOption "Dendrite Matrix server";
 
-    port = mkOption {
+    port = lib.mkOption {
       description = "Port.";
-      type = with types; port;
+      type = lib.types.port;
       default = 8008;
     };
 
-    domain = mkOption {
-      type = types.str;
+    domain = lib.mkOption {
+      type = lib.types.str;
       default = config.networking.domain;
       description = "Domain name sans protocol scheme.";
     };
@@ -31,7 +30,7 @@ in
     let
       db = "dendrite";
     in
-    mkIf cfg.enable {
+    lib.mkIf cfg.enable {
       ark.directories = [
         "/var/lib/dendrite"
         "/var/lib/private/dendrite"
@@ -58,14 +57,16 @@ in
                 add_header Content-Type application/json;
                 add_header Access-Control-Allow-Origin *;
               '';
-              return = "200 '${generators.toJSON { } { "m.server" = "${cfg.domain}:443"; }}'";
+              return = "200 '${lib.generators.toJSON { } { "m.server" = "${cfg.domain}:443"; }}'";
             };
             "= /.well-known/matrix/client" = {
               extraConfig = ''
                 add_header Content-Type application/json;
                 add_header Access-Control-Allow-Origin *;
               '';
-              return = "200 '${generators.toJSON { } { "m.homeserver".base_url = "https://${cfg.domain}"; }}'";
+              return = "200 '${
+                lib.generators.toJSON { } { "m.homeserver".base_url = "https://${cfg.domain}"; }
+              }'";
             };
           };
         };
@@ -119,7 +120,7 @@ in
         serviceConfig =
           let
             needsPrivileges = cfg.port < 1024;
-            capabilities = [ "" ] ++ optionals needsPrivileges [ "CAP_NET_BIND_SERVICE" ];
+            capabilities = [ "" ] ++ lib.optionals needsPrivileges [ "CAP_NET_BIND_SERVICE" ];
           in
           {
             Restart = "on-failure";
@@ -185,13 +186,13 @@ in
                   ];
                 };
               in
-              concatStringsSep " " [
-                (getExe pkgs.envsubst)
+              lib.concatStringsSep " " [
+                (lib.getExe pkgs.envsubst)
                 "-i ${(pkgs.formats.yaml { }).generate "dendrite.yaml" settings}"
                 "-o /run/dendrite/dendrite.yaml"
               ];
-            ExecStart = concatStringsSep " " [
-              (getExe' pkgs.dendrite "dendrite")
+            ExecStart = lib.concatStringsSep " " [
+              (lib.getExe' pkgs.dendrite "dendrite")
               "--config /run/dendrite/dendrite.yaml"
               "--http-bind-address 127.0.0.1:${toString cfg.port}"
             ];
@@ -237,13 +238,11 @@ in
           };
       };
 
-      topology = with cfg; {
-        nodes.${this.hostname}.services.dendrite = {
-          name = "Dendrite";
-          icon = "${inputs.homelab-svg-assets}/assets/matrix-white.svg";
-          info = domain;
-          details.listen.text = "127.0.0.1:${toString port}";
-        };
+      topology.nodes.${this.hostname}.services.dendrite = {
+        name = "Dendrite";
+        icon = "${inputs.homelab-svg-assets}/assets/matrix-white.svg";
+        info = cfg.domain;
+        details.listen.text = "127.0.0.1:${toString cfg.port}";
       };
     };
 }
diff --git a/modules/matrix/element.nix b/modules/matrix/element.nix
index 01b991e..6fc336e 100644
--- a/modules/matrix/element.nix
+++ b/modules/matrix/element.nix
@@ -4,28 +4,27 @@
   pkgs,
   ...
 }:
-with lib;
 let
   cfg = config.nixfiles.modules.matrix.element;
 in
 {
   options.nixfiles.modules.matrix.element = {
-    enable = mkEnableOption "Element, a Matrix web interface";
+    enable = lib.mkEnableOption "Element, a Matrix web interface";
 
-    domain = mkOption {
+    domain = lib.mkOption {
       description = "Domain name sans protocol scheme.";
-      type = with types; nullOr str;
+      type = with lib.types; nullOr str;
       default = "element.${config.networking.domain}";
     };
 
-    homeserver = mkOption {
+    homeserver = lib.mkOption {
       description = "Default Matrix homeserver.";
-      type = with types; str;
-      default = my.domain.azahi;
+      type = lib.types.str;
+      default = lib.my.domain.azahi;
     };
   };
 
-  config = mkIf cfg.enable {
+  config = lib.mkIf cfg.enable {
     assertions = [
       {
         assertion =
@@ -35,19 +34,19 @@ in
       }
     ];
 
-    nixfiles.modules.nginx = with cfg; {
+    nixfiles.modules.nginx = {
       enable = true;
-      virtualHosts.${domain}.locations."/".root = pkgs.element-web.override {
+      virtualHosts.${cfg.domain}.locations."/".root = pkgs.element-web.override {
         conf = {
           default_server_config."m.homeserver" = {
-            base_url = "https://${homeserver}";
-            server_name = homeserver;
+            base_url = "https://${cfg.homeserver}";
+            server_name = cfg.homeserver;
           };
           disable_custom_urls = true;
           disable_guests = true;
           disable_login_language_selector = true;
           disable_3pid_login = true;
-          brand = homeserver;
+          brand = cfg.homeserver;
           branding.authFooterLinks = [
             {
               text = "NixOS";

Consider giving Nix/NixOS a try! <3