IPFS NixOS module: Socket unit file more precise
The systemd socket unit files now more precisely track the IPFS configuration, by including any multaddr they can make a `ListenStream` for. (The daemon doesn't currently support anything which would use `ListDatagram`, so we don't need to worry about that.) The tests use some of these features.
This commit is contained in:
parent
e76f83c266
commit
4044d81d5c
@ -12,6 +12,19 @@ let
|
|||||||
(optionalString (cfg.defaultMode == "norouting") "--routing=none")
|
(optionalString (cfg.defaultMode == "norouting") "--routing=none")
|
||||||
] ++ cfg.extraFlags);
|
] ++ cfg.extraFlags);
|
||||||
|
|
||||||
|
splitMulitaddr = addrRaw: lib.tail (lib.splitString "/" addrRaw);
|
||||||
|
|
||||||
|
multiaddrToListenStream = addrRaw: let
|
||||||
|
addr = splitMulitaddr addrRaw;
|
||||||
|
s = builtins.elemAt addr;
|
||||||
|
in if s 0 == "ip4" && s 2 == "tcp"
|
||||||
|
then "${s 1}:${s 3}"
|
||||||
|
else if s 0 == "ip6" && s 2 == "tcp"
|
||||||
|
then "[${s 1}]:${s 3}"
|
||||||
|
else if s 0 == "unix"
|
||||||
|
then "/${lib.concatStringsSep "/" (lib.tail addr)}"
|
||||||
|
else null; # not valid for listen stream, skip
|
||||||
|
|
||||||
in {
|
in {
|
||||||
|
|
||||||
###### interface
|
###### interface
|
||||||
@ -80,7 +93,10 @@ in {
|
|||||||
|
|
||||||
swarmAddress = mkOption {
|
swarmAddress = mkOption {
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
default = [ "/ip4/0.0.0.0/tcp/4001" "/ip6/::/tcp/4001" ];
|
default = [
|
||||||
|
"/ip4/0.0.0.0/tcp/4001"
|
||||||
|
"/ip6/::/tcp/4001"
|
||||||
|
];
|
||||||
description = "Where IPFS listens for incoming p2p connections";
|
description = "Where IPFS listens for incoming p2p connections";
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -250,14 +266,18 @@ in {
|
|||||||
|
|
||||||
systemd.sockets.ipfs-gateway = {
|
systemd.sockets.ipfs-gateway = {
|
||||||
wantedBy = [ "sockets.target" ];
|
wantedBy = [ "sockets.target" ];
|
||||||
socketConfig.ListenStream = [ "" ]
|
socketConfig.ListenStream = let
|
||||||
++ lib.optional (cfg.gatewayAddress == opt.gatewayAddress.default) [ "127.0.0.1:8080" "[::1]:8080" ];
|
fromCfg = multiaddrToListenStream cfg.gatewayAddress;
|
||||||
|
in [ "" ] ++ lib.optional (fromCfg != null) fromCfg;
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.sockets.ipfs-api = {
|
systemd.sockets.ipfs-api = {
|
||||||
wantedBy = [ "sockets.target" ];
|
wantedBy = [ "sockets.target" ];
|
||||||
socketConfig.ListenStream = [ "" "%t/ipfs.sock" ]
|
# We also include "%t/ipfs.sock" because tere is no way to put the "%t"
|
||||||
++ lib.optional (cfg.apiAddress == opt.apiAddress.default) [ "127.0.0.1:5001" "[::1]:5001" ];
|
# in the multiaddr.
|
||||||
|
socketConfig.ListenStream = let
|
||||||
|
fromCfg = multiaddrToListenStream cfg.apiAddress;
|
||||||
|
in [ "" "%t/ipfs.sock" ] ++ lib.optional (fromCfg != null) fromCfg;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -7,21 +7,28 @@ import ./make-test-python.nix ({ pkgs, ...} : {
|
|||||||
nodes.machine = { ... }: {
|
nodes.machine = { ... }: {
|
||||||
services.ipfs = {
|
services.ipfs = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
# Also will add a unix domain socket socket API address, see module.
|
||||||
|
startWhenNeeded = true;
|
||||||
apiAddress = "/ip4/127.0.0.1/tcp/2324";
|
apiAddress = "/ip4/127.0.0.1/tcp/2324";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
testScript = ''
|
testScript = ''
|
||||||
start_all()
|
start_all()
|
||||||
machine.wait_for_unit("ipfs")
|
|
||||||
|
|
||||||
machine.wait_until_succeeds("ipfs --api /ip4/127.0.0.1/tcp/2324 id")
|
# IPv4 activation
|
||||||
|
|
||||||
|
machine.succeed("ipfs --api /ip4/127.0.0.1/tcp/2324 id")
|
||||||
ipfs_hash = machine.succeed(
|
ipfs_hash = machine.succeed(
|
||||||
"echo fnord | ipfs --api /ip4/127.0.0.1/tcp/2324 add | awk '{ print $2 }'"
|
"echo fnord | ipfs --api /ip4/127.0.0.1/tcp/2324 add | awk '{ print $2 }'"
|
||||||
)
|
)
|
||||||
|
|
||||||
machine.succeed(f"ipfs cat /ipfs/{ipfs_hash.strip()} | grep fnord")
|
machine.succeed(f"ipfs cat /ipfs/{ipfs_hash.strip()} | grep fnord")
|
||||||
|
|
||||||
|
# Unix domain socket activation
|
||||||
|
|
||||||
|
machine.stop_job("ipfs")
|
||||||
|
|
||||||
ipfs_hash = machine.succeed(
|
ipfs_hash = machine.succeed(
|
||||||
"echo fnord2 | ipfs --api /unix/run/ipfs.sock add | awk '{ print $2 }'"
|
"echo fnord2 | ipfs --api /unix/run/ipfs.sock add | awk '{ print $2 }'"
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user