at 23.11-beta 3.2 kB view raw
1{ config, lib, pkgs, ... }: 2 3let 4 cfg = config.services.eris-server; 5 stateDirectoryPath = "\${STATE_DIRECTORY}"; 6in { 7 8 options.services.eris-server = { 9 10 enable = lib.mkEnableOption "an ERIS server"; 11 12 package = lib.mkOption { 13 type = lib.types.package; 14 default = pkgs.eris-go; 15 defaultText = lib.literalExpression "pkgs.eris-go"; 16 description = "Package to use for the ERIS server."; 17 }; 18 19 decode = lib.mkOption { 20 type = lib.types.bool; 21 default = false; 22 description = '' 23 Whether the HTTP service (when enabled) will decode ERIS content at /uri-res/N2R?urn:eris:. 24 Enabling this is recommended only for private or local-only servers. 25 ''; 26 }; 27 28 listenCoap = lib.mkOption { 29 type = lib.types.str; 30 default = ":5683"; 31 example = "[::1]:5683"; 32 description = '' 33 Server CoAP listen address. Listen on all IP addresses at port 5683 by default. 34 Please note that the server can service client requests for ERIS-blocks by 35 querying other clients connected to the server. Whether or not blocks are 36 relayed back to the server depends on client configuration but be aware this 37 may leak sensitive metadata and trigger network activity. 38 ''; 39 }; 40 41 listenHttp = lib.mkOption { 42 type = lib.types.str; 43 default = ""; 44 example = "[::1]:8080"; 45 description = "Server HTTP listen address. Do not listen by default."; 46 }; 47 48 backends = lib.mkOption { 49 type = with lib.types; listOf str; 50 description = '' 51 List of backend URLs. 52 Add "get" and "put" as query elements to enable those operations. 53 ''; 54 example = [ 55 "bolt+file:///srv/eris.bolt?get&put" 56 "coap+tcp://eris.example.com:5683?get" 57 ]; 58 }; 59 60 mountpoint = lib.mkOption { 61 type = lib.types.str; 62 default = ""; 63 example = "/eris"; 64 description = '' 65 Mountpoint for FUSE namespace that exposes "urn:eris:" files. 66 ''; 67 }; 68 69 }; 70 71 config = lib.mkIf cfg.enable { 72 systemd.services.eris-server = let 73 cmd = 74 "${cfg.package}/bin/eris-go server --coap '${cfg.listenCoap}' --http '${cfg.listenHttp}' ${ 75 lib.optionalString cfg.decode "--decode " 76 }${ 77 lib.optionalString (cfg.mountpoint != "") 78 ''--mountpoint "${cfg.mountpoint}" '' 79 }${lib.strings.escapeShellArgs cfg.backends}"; 80 in { 81 description = "ERIS block server"; 82 after = [ "network.target" ]; 83 wantedBy = [ "multi-user.target" ]; 84 script = lib.mkIf (cfg.mountpoint != "") '' 85 export PATH=${config.security.wrapperDir}:$PATH 86 ${cmd} 87 ''; 88 serviceConfig = let 89 umounter = lib.mkIf (cfg.mountpoint != "") 90 "-${config.security.wrapperDir}/fusermount -uz ${cfg.mountpoint}"; 91 in { 92 ExecStartPre = umounter; 93 ExecStart = lib.mkIf (cfg.mountpoint == "") cmd; 94 ExecStopPost = umounter; 95 Restart = "always"; 96 RestartSec = 20; 97 AmbientCapabilities = "CAP_NET_BIND_SERVICE"; 98 }; 99 }; 100 }; 101 102 meta.maintainers = with lib.maintainers; [ ehmry ]; 103}