about summary refs log tree commit diff
path: root/nixos/modules/services/network-filesystems
diff options
context:
space:
mode:
authorLuflosi <luflosi@luflosi.de>2023-04-14 15:56:10 +0200
committerLuflosi <luflosi@luflosi.de>2023-04-15 15:25:06 +0200
commit7ceebbb35bfebd887f41418588d1ccc32d3a977a (patch)
tree8797bfe82d19cfd4e8059528f48ebe3f3578330b /nixos/modules/services/network-filesystems
parent929a00bd84acbf35447d3df1066b1c8afd7ac82d (diff)
downloadnixlib-7ceebbb35bfebd887f41418588d1ccc32d3a977a.tar
nixlib-7ceebbb35bfebd887f41418588d1ccc32d3a977a.tar.gz
nixlib-7ceebbb35bfebd887f41418588d1ccc32d3a977a.tar.bz2
nixlib-7ceebbb35bfebd887f41418588d1ccc32d3a977a.tar.lz
nixlib-7ceebbb35bfebd887f41418588d1ccc32d3a977a.tar.xz
nixlib-7ceebbb35bfebd887f41418588d1ccc32d3a977a.tar.zst
nixlib-7ceebbb35bfebd887f41418588d1ccc32d3a977a.zip
nixos/kubo: allow multiple API and Gateway addresses
The daemon allows specifying an array of multiaddrs for Addresses.API and Addresses.Gateway, so the NixOS module should allow that as well.
Diffstat (limited to 'nixos/modules/services/network-filesystems')
-rw-r--r--nixos/modules/services/network-filesystems/kubo.nix40
1 files changed, 25 insertions, 15 deletions
diff --git a/nixos/modules/services/network-filesystems/kubo.nix b/nixos/modules/services/network-filesystems/kubo.nix
index 716be4fd59a9..f496cfb4338f 100644
--- a/nixos/modules/services/network-filesystems/kubo.nix
+++ b/nixos/modules/services/network-filesystems/kubo.nix
@@ -50,6 +50,22 @@ let
 
   splitMulitaddr = addrRaw: lib.tail (lib.splitString "/" addrRaw);
 
+  multiaddrsToListenStreams = addrIn:
+    let
+      addrs = if builtins.typeOf addrIn == "list"
+      then addrIn else [ addrIn ];
+      unfilteredResult = map multiaddrToListenStream addrs;
+    in
+      builtins.filter (addr: addr != null) unfilteredResult;
+
+  multiaddrsToListenDatagrams = addrIn:
+    let
+      addrs = if builtins.typeOf addrIn == "list"
+      then addrIn else [ addrIn ];
+      unfilteredResult = map multiaddrToListenDatagram addrs;
+    in
+      builtins.filter (addr: addr != null) unfilteredResult;
+
   multiaddrToListenStream = addrRaw:
     let
       addr = splitMulitaddr addrRaw;
@@ -166,13 +182,16 @@ in
 
           options = {
             Addresses.API = mkOption {
-              type = types.str;
+              type = types.oneOf [ types.str (types.listOf types.str) ];
               default = "/ip4/127.0.0.1/tcp/5001";
-              description = lib.mdDoc "Where Kubo exposes its API to";
+              description = lib.mdDoc ''
+                Multiaddr or array of multiaddrs describing the address to serve the local HTTP API on.
+                In addition to the multiaddrs listed here, the daemon will also listen on a Unix domain socket.
+              '';
             };
 
             Addresses.Gateway = mkOption {
-              type = types.str;
+              type = types.oneOf [ types.str (types.listOf types.str) ];
               default = "/ip4/127.0.0.1/tcp/8080";
               description = lib.mdDoc "Where the IPFS Gateway can be reached";
             };
@@ -350,15 +369,9 @@ in
       wantedBy = [ "sockets.target" ];
       socketConfig = {
         ListenStream =
-          let
-            fromCfg = multiaddrToListenStream cfg.settings.Addresses.Gateway;
-          in
-          [ "" ] ++ lib.optional (fromCfg != null) fromCfg;
+          [ "" ] ++ (multiaddrsToListenStreams cfg.settings.Addresses.Gateway);
         ListenDatagram =
-          let
-            fromCfg = multiaddrToListenDatagram cfg.settings.Addresses.Gateway;
-          in
-          [ "" ] ++ lib.optional (fromCfg != null) fromCfg;
+          [ "" ] ++ (multiaddrsToListenDatagrams cfg.settings.Addresses.Gateway);
       };
     };
 
@@ -367,10 +380,7 @@ in
       # We also include "%t/ipfs.sock" because there is no way to put the "%t"
       # in the multiaddr.
       socketConfig.ListenStream =
-        let
-          fromCfg = multiaddrToListenStream cfg.settings.Addresses.API;
-        in
-        [ "" "%t/ipfs.sock" ] ++ lib.optional (fromCfg != null) fromCfg;
+        [ "" "%t/ipfs.sock" ] ++ multiaddrsToListenStreams cfg.settings.Addresses.API;
     };
   };