summary refs log tree commit diff
path: root/nixos/modules
diff options
context:
space:
mode:
authorMatthew Bauer <mjbauer95@gmail.com>2020-08-12 13:47:29 -0500
committerGitHub <noreply@github.com>2020-08-12 13:47:29 -0500
commit6fffd50623b6d6e707bbe3dd83be498a0963946a (patch)
tree425e8c4f76a64d36fad91303b6e5bd52e7419dad /nixos/modules
parent07f111eac53bd351dc8e509751e1a2f5d38111ae (diff)
parente6fe9abd8b1b80c9911bc1469eef9cfb0b3f0003 (diff)
downloadnixpkgs-6fffd50623b6d6e707bbe3dd83be498a0963946a.tar
nixpkgs-6fffd50623b6d6e707bbe3dd83be498a0963946a.tar.gz
nixpkgs-6fffd50623b6d6e707bbe3dd83be498a0963946a.tar.bz2
nixpkgs-6fffd50623b6d6e707bbe3dd83be498a0963946a.tar.lz
nixpkgs-6fffd50623b6d6e707bbe3dd83be498a0963946a.tar.xz
nixpkgs-6fffd50623b6d6e707bbe3dd83be498a0963946a.tar.zst
nixpkgs-6fffd50623b6d6e707bbe3dd83be498a0963946a.zip
Merge pull request #95220 from obsidiansystems/ipfs-quic-socket-activated
nixos/ipfs: Allow QUIC connections to socket activate too
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/services/network-filesystems/ipfs.nix20
-rw-r--r--nixos/modules/system/boot/systemd-unit-options.nix10
-rw-r--r--nixos/modules/system/boot/systemd.nix1
3 files changed, 28 insertions, 3 deletions
diff --git a/nixos/modules/services/network-filesystems/ipfs.nix b/nixos/modules/services/network-filesystems/ipfs.nix
index 5c096d26d82..f298f831fa7 100644
--- a/nixos/modules/services/network-filesystems/ipfs.nix
+++ b/nixos/modules/services/network-filesystems/ipfs.nix
@@ -25,6 +25,15 @@ let
       then "/${lib.concatStringsSep "/" (lib.tail addr)}"
     else null; # not valid for listen stream, skip
 
+  multiaddrToListenDatagram = addrRaw: let
+      addr = splitMulitaddr addrRaw;
+      s = builtins.elemAt addr;
+    in if s 0 == "ip4" && s 2 == "udp"
+      then "${s 1}:${s 3}"
+    else if s 0 == "ip6" && s 2 == "udp"
+      then "[${s 1}]:${s 3}"
+    else null; # not valid for listen datagram, skip
+
 in {
 
   ###### interface
@@ -268,9 +277,14 @@ in {
 
     systemd.sockets.ipfs-gateway = {
       wantedBy = [ "sockets.target" ];
-      socketConfig.ListenStream = let
-          fromCfg = multiaddrToListenStream cfg.gatewayAddress;
-        in [ "" ] ++ lib.optional (fromCfg != null) fromCfg;
+      socketConfig = {
+        ListenStream = let
+            fromCfg = multiaddrToListenStream cfg.gatewayAddress;
+          in [ "" ] ++ lib.optional (fromCfg != null) fromCfg;
+        ListenDatagram = let
+            fromCfg = multiaddrToListenDatagram cfg.gatewayAddress;
+          in [ "" ] ++ lib.optional (fromCfg != null) fromCfg;
+      };
     };
 
     systemd.sockets.ipfs-api = {
diff --git a/nixos/modules/system/boot/systemd-unit-options.nix b/nixos/modules/system/boot/systemd-unit-options.nix
index c6dbb96951a..ac6fed440a2 100644
--- a/nixos/modules/system/boot/systemd-unit-options.nix
+++ b/nixos/modules/system/boot/systemd-unit-options.nix
@@ -379,6 +379,16 @@ in rec {
       '';
     };
 
+    listenDatagrams = mkOption {
+      default = [];
+      type = types.listOf types.str;
+      example = [ "0.0.0.0:993" "/run/my-socket" ];
+      description = ''
+        For each item in this list, a <literal>ListenDatagram</literal>
+        option in the <literal>[Socket]</literal> section will be created.
+      '';
+    };
+
     socketConfig = mkOption {
       default = {};
       example = { ListenStream = "/run/my-socket"; };
diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix
index a5f368c869a..d95f001a225 100644
--- a/nixos/modules/system/boot/systemd.nix
+++ b/nixos/modules/system/boot/systemd.nix
@@ -354,6 +354,7 @@ let
           [Socket]
           ${attrsToSection def.socketConfig}
           ${concatStringsSep "\n" (map (s: "ListenStream=${s}") def.listenStreams)}
+          ${concatStringsSep "\n" (map (s: "ListenDatagram=${s}") def.listenDatagrams)}
         '';
     };