1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.networking.rxe;
7
8 runRxeCmd = cmd: ifcs:
9 concatStrings ( map (x: "${pkgs.rdma-core}/bin/rxe_cfg -n ${cmd} ${x};") ifcs);
10
11 startScript = pkgs.writeShellScriptBin "rxe-start" ''
12 ${pkgs.rdma-core}/bin/rxe_cfg -n start
13 ${runRxeCmd "add" cfg.interfaces}
14 ${pkgs.rdma-core}/bin/rxe_cfg
15 '';
16
17 stopScript = pkgs.writeShellScriptBin "rxe-stop" ''
18 ${runRxeCmd "remove" cfg.interfaces }
19 ${pkgs.rdma-core}/bin/rxe_cfg -n stop
20 '';
21
22in {
23 ###### interface
24
25 options = {
26 networking.rxe = {
27 enable = mkEnableOption "RDMA over converged ethernet";
28 interfaces = mkOption {
29 type = types.listOf types.str;
30 default = [ ];
31 example = [ "eth0" ];
32 description = ''
33 Enable RDMA on the listed interfaces. The corresponding virtual
34 RDMA interfaces will be named rxe0 ... rxeN where the ordering
35 will be as they are named in the list. UDP port 4791 must be
36 open on the respective ethernet interfaces.
37 '';
38 };
39 };
40 };
41
42 ###### implementation
43
44 config = mkIf cfg.enable {
45
46 systemd.services.rxe = {
47 path = with pkgs; [ kmod rdma-core ];
48 description = "RoCE interfaces";
49
50 wantedBy = [ "multi-user.target" ];
51 after = [ "systemd-modules-load.service" "network-online.target" ];
52 wants = [ "network-pre.target" ];
53
54 serviceConfig = {
55 Type = "oneshot";
56 RemainAfterExit = true;
57 ExecStart = "${startScript}/bin/rxe-start";
58 ExecStop = "${stopScript}/bin/rxe-stop";
59 };
60 };
61 };
62}
63