at 23.11-pre 2.6 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 pkg = pkgs.ostinato; 7 cfg = config.services.ostinato; 8 configFile = pkgs.writeText "drone.ini" '' 9 [General] 10 RateAccuracy=${cfg.rateAccuracy} 11 12 [RpcServer] 13 Address=${cfg.rpcServer.address} 14 15 [PortList] 16 Include=${concatStringsSep "," cfg.portList.include} 17 Exclude=${concatStringsSep "," cfg.portList.exclude} 18 ''; 19 20in 21{ 22 23 ###### interface 24 25 options = { 26 27 services.ostinato = { 28 29 enable = mkEnableOption (lib.mdDoc "Ostinato agent-controller (Drone)"); 30 31 port = mkOption { 32 type = types.port; 33 default = 7878; 34 description = lib.mdDoc '' 35 Port to listen on. 36 ''; 37 }; 38 39 rateAccuracy = mkOption { 40 type = types.enum [ "High" "Low" ]; 41 default = "High"; 42 description = lib.mdDoc '' 43 To ensure that the actual transmit rate is as close as possible to 44 the configured transmit rate, Drone runs a busy-wait loop. 45 While this provides the maximum accuracy possible, the CPU 46 utilization is 100% while the transmit is on. You can however, 47 sacrifice the accuracy to reduce the CPU load. 48 ''; 49 }; 50 51 rpcServer = { 52 address = mkOption { 53 type = types.str; 54 default = "0.0.0.0"; 55 description = lib.mdDoc '' 56 By default, the Drone RPC server will listen on all interfaces and 57 local IPv4 addresses for incoming connections from clients. Specify 58 a single IPv4 or IPv6 address if you want to restrict that. 59 To listen on any IPv6 address, use :: 60 ''; 61 }; 62 }; 63 64 portList = { 65 include = mkOption { 66 type = types.listOf types.str; 67 default = []; 68 example = [ "eth*" "lo*" ]; 69 description = lib.mdDoc '' 70 For a port to pass the filter and appear on the port list managed 71 by drone, it be allowed by this include list. 72 ''; 73 }; 74 exclude = mkOption { 75 type = types.listOf types.str; 76 default = []; 77 example = [ "usbmon*" "eth0" ]; 78 description = lib.mdDoc '' 79 A list of ports does not appear on the port list managed by drone. 80 ''; 81 }; 82 }; 83 84 }; 85 86 }; 87 88 ###### implementation 89 90 config = mkIf cfg.enable { 91 92 environment.systemPackages = [ pkg ]; 93 94 systemd.services.drone = { 95 description = "Ostinato agent-controller"; 96 wantedBy = [ "multi-user.target" ]; 97 script = '' 98 ${pkg}/bin/drone ${toString cfg.port} ${configFile} 99 ''; 100 }; 101 102 }; 103 104}