~aasg/nixexprs

0b021297578a635bdf65f31b96e02ff38125a319 — Aluísio Augusto Silva Gonçalves 8 months ago 483b4f0
patches/ipfs-cluster: Patch to enable connecting to IPFS via Unix socket
M patches/default.nix => patches/default.nix +2 -0
@@ 6,6 6,8 @@ let

    haunt = callPackage ./haunt { };

    ipfs-cluster = callPackage ./ipfs-cluster { };

  };
in
self

A patches/ipfs-cluster/default.nix => patches/ipfs-cluster/default.nix +5 -0
@@ 0,0 1,5 @@
{ ipfs-cluster }:

ipfs-cluster.overrideAttrs (oldAttrs: rec {
  patches = [ ./ipfs-api-via-unix-socket.patch ];
})

A patches/ipfs-cluster/ipfs-api-via-unix-socket.patch => patches/ipfs-cluster/ipfs-api-via-unix-socket.patch +39 -0
@@ 0,0 1,39 @@
diff --git i/ipfsconn/ipfshttp/ipfshttp.go w/ipfsconn/ipfshttp/ipfshttp.go
index bae536e..ffef131 100644
--- i/ipfsconn/ipfshttp/ipfshttp.go
+++ w/ipfsconn/ipfshttp/ipfshttp.go
@@ -9,6 +9,7 @@ import (
 	"fmt"
 	"io"
 	"io/ioutil"
+	"net"
 	"net/http"
 	"net/url"
 	"strconv"
@@ -145,15 +146,24 @@ func NewConnector(cfg *Config) (*Connector, error) {
 		nodeMAddr = resolvedAddrs[0]
 	}
 
-	_, nodeAddr, err := manet.DialArgs(nodeMAddr)
+	network, nodeAddr, err := manet.DialArgs(nodeMAddr)
 	if err != nil {
 		return nil, err
 	}
 
 	c := &http.Client{} // timeouts are handled by context timeouts
+	if network == "unix" {
+		socketPath := nodeAddr
+		nodeAddr = "unix"
+		c.Transport = &http.Transport{
+			DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
+				return net.Dial("unix", socketPath)
+			},
+		}
+	}
 	if cfg.Tracing {
 		c.Transport = &ochttp.Transport{
-			Base:           http.DefaultTransport,
+			Base:           c.Transport,
 			Propagation:    &tracecontext.HTTPFormat{},
 			StartOptions:   trace.StartOptions{SpanKind: trace.SpanKindClient},
 			FormatSpanName: func(req *http.Request) string { return req.Host + ":" + req.URL.Path + ":" + req.Method },

M patches/overlay.nix => patches/overlay.nix +2 -0
@@ 4,4 4,6 @@ self: super:

  haunt = import ./haunt { inherit (super) haunt; };

  ipfs-cluster = import ./ipfs-cluster { inherit (super) ipfs-cluster; };

}