diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2020-06-17 16:19:01 -0400 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2020-06-17 21:43:04 +0000 |
commit | 4044d81d5cea617e58ec9682f9cc447dde326850 (patch) | |
tree | cb2988403da7db68d9ac2af2b9f231d557e6cd74 /nixos/modules/services/network-filesystems/ipfs.nix | |
parent | e76f83c266f7b03afe798cfcd9ff068ac369d5e4 (diff) | |
download | nixpkgs-4044d81d5cea617e58ec9682f9cc447dde326850.tar nixpkgs-4044d81d5cea617e58ec9682f9cc447dde326850.tar.gz nixpkgs-4044d81d5cea617e58ec9682f9cc447dde326850.tar.bz2 nixpkgs-4044d81d5cea617e58ec9682f9cc447dde326850.tar.lz nixpkgs-4044d81d5cea617e58ec9682f9cc447dde326850.tar.xz nixpkgs-4044d81d5cea617e58ec9682f9cc447dde326850.tar.zst nixpkgs-4044d81d5cea617e58ec9682f9cc447dde326850.zip |
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.
Diffstat (limited to 'nixos/modules/services/network-filesystems/ipfs.nix')
-rw-r--r-- | nixos/modules/services/network-filesystems/ipfs.nix | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/nixos/modules/services/network-filesystems/ipfs.nix b/nixos/modules/services/network-filesystems/ipfs.nix index a3bd40135d1..7d18410ff0a 100644 --- a/nixos/modules/services/network-filesystems/ipfs.nix +++ b/nixos/modules/services/network-filesystems/ipfs.nix @@ -12,6 +12,19 @@ let (optionalString (cfg.defaultMode == "norouting") "--routing=none") ] ++ 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 { ###### interface @@ -80,7 +93,10 @@ in { swarmAddress = mkOption { 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"; }; @@ -250,14 +266,18 @@ in { systemd.sockets.ipfs-gateway = { wantedBy = [ "sockets.target" ]; - socketConfig.ListenStream = [ "" ] - ++ lib.optional (cfg.gatewayAddress == opt.gatewayAddress.default) [ "127.0.0.1:8080" "[::1]:8080" ]; + socketConfig.ListenStream = let + fromCfg = multiaddrToListenStream cfg.gatewayAddress; + in [ "" ] ++ lib.optional (fromCfg != null) fromCfg; }; systemd.sockets.ipfs-api = { wantedBy = [ "sockets.target" ]; - socketConfig.ListenStream = [ "" "%t/ipfs.sock" ] - ++ lib.optional (cfg.apiAddress == opt.apiAddress.default) [ "127.0.0.1:5001" "[::1]:5001" ]; + # We also include "%t/ipfs.sock" because tere is no way to put the "%t" + # in the multiaddr. + socketConfig.ListenStream = let + fromCfg = multiaddrToListenStream cfg.apiAddress; + in [ "" "%t/ipfs.sock" ] ++ lib.optional (fromCfg != null) fromCfg; }; }; |