at 24.11-pre 1.3 kB view raw
1{ config, lib, pkgs, ... }: 2let 3 cfg = config.services.fanout; 4 mknodCmds = n: lib.lists.imap0 (i: s: 5 "mknod /dev/fanout${builtins.toString i} c $MAJOR ${builtins.toString i}" 6 ) (lib.lists.replicate n ""); 7in 8{ 9 options.services.fanout = { 10 enable = lib.mkEnableOption "fanout"; 11 fanoutDevices = lib.mkOption { 12 type = lib.types.int; 13 default = 1; 14 description = "Number of /dev/fanout devices"; 15 }; 16 bufferSize = lib.mkOption { 17 type = lib.types.int; 18 default = 16384; 19 description = "Size of /dev/fanout buffer in bytes"; 20 }; 21 }; 22 23 config = lib.mkIf cfg.enable { 24 boot.extraModulePackages = [ config.boot.kernelPackages.fanout.out ]; 25 26 boot.kernelModules = [ "fanout" ]; 27 28 boot.extraModprobeConfig = '' 29 options fanout buffersize=${builtins.toString cfg.bufferSize} 30 ''; 31 32 systemd.services.fanout = { 33 description = "Bring up /dev/fanout devices"; 34 script = '' 35 MAJOR=$(${pkgs.gnugrep}/bin/grep fanout /proc/devices | ${pkgs.gawk}/bin/awk '{print $1}') 36 ${lib.strings.concatLines (mknodCmds cfg.fanoutDevices)} 37 ''; 38 39 wantedBy = [ "multi-user.target" ]; 40 41 serviceConfig = { 42 Type = "oneshot"; 43 User = "root"; 44 RemainAfterExit = "yes"; 45 Restart = "no"; 46 }; 47 }; 48 }; 49}