about summary refs log tree commit diff
path: root/modules/ipfs.nix
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--modules/ipfs.nix32
1 files changed, 28 insertions, 4 deletions
diff --git a/modules/ipfs.nix b/modules/ipfs.nix
index cd28372..1dad6a6 100644
--- a/modules/ipfs.nix
+++ b/modules/ipfs.nix
@@ -1,5 +1,6 @@
 {
   config,
+  inputs,
   lib,
   libNginx,
   this,
@@ -23,12 +24,22 @@ in
       default = "ipfs.${config.networking.fqdn}";
     };
 
+    gatewayBind = mkOption {
+      description = "Gateway bind.";
+      type = with types; str;
+      default = "127.0.0.1";
+    };
     gatewayPort = mkOption {
       description = "Gateway port.";
       type = with types; port;
       default = if this.isHeadless then gatewayDefaultPort + 990 else gatewayDefaultPort;
     };
 
+    apiBind = mkOption {
+      description = "API bind.";
+      type = with types; str;
+      default = "127.0.0.1";
+    };
     apiPort = mkOption {
       description = "API port.";
       type = with types; port;
@@ -85,8 +96,8 @@ in
             in
             {
               Addresses = {
-                API = "/ip4/127.0.0.1/tcp/${toString cfg.apiPort}";
-                Gateway = "/ip4/127.0.0.1/tcp/${toString cfg.gatewayPort}";
+                API = "/ip4/${cfg.apiBind}/tcp/${toString cfg.apiPort}";
+                Gateway = "/ip4/${cfg.gatewayBind}/tcp/${toString cfg.gatewayPort}";
                 Swarm =
                   let
                     port = toString cfg.swarmPort;
@@ -118,13 +129,24 @@ in
         allowedTCPPorts = [ swarmDefaultPort ];
         allowedUDPPorts = allowedTCPPorts;
       };
+
+      topology = with cfg; {
+        nodes.${this.hostname}.services.ipfs-kubo = {
+          name = "IPFS Kubo";
+          icon = "${inputs.homelab-svg-assets}/assets/ipfs.svg";
+          details.listen.text = ''
+            ${gatewayBind}:${toString gatewayPort}
+            ${apiBind}:${toString apiPort}
+          '';
+        };
+      };
     }
     (mkIf this.isHeadless {
       nixfiles.modules.nginx = {
         enable = true;
         upstreams = with cfg; {
-          kubo_gateway.servers."127.0.0.1:${toString gatewayPort}" = { };
-          kubo_api.servers."127.0.0.1:${toString apiPort}" = { };
+          kubo_gateway.servers."${gatewayBind}:${toString gatewayPort}" = { };
+          kubo_api.servers."${apiBind}:${toString apiPort}" = { };
         };
         virtualHosts = {
           ${cfg.domain} = {
@@ -140,6 +162,8 @@ in
           };
         };
       };
+
+      topology.nodes.${this.hostname}.services.ipfs-kubo.info = cfg.domain;
     })
   ]);
 }

Consider giving Nix/NixOS a try! <3