diff options
author | Alyssa Ross <hi@alyssa.is> | 2023-10-22 08:39:18 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2023-10-22 08:39:18 +0000 |
commit | 403acf82248d3cdbc0beda0c5c373c1b46b9b636 (patch) | |
tree | e3913fd47e374b9525858fa1e61064fd1113e475 /nixpkgs/nixos/modules/config/fanout.nix | |
parent | b5faee77a2dceb31545db209ebee1476acb71198 (diff) | |
parent | 8dfad603247387df1df4826b8bea58efc5d012d8 (diff) | |
download | nixlib-403acf82248d3cdbc0beda0c5c373c1b46b9b636.tar nixlib-403acf82248d3cdbc0beda0c5c373c1b46b9b636.tar.gz nixlib-403acf82248d3cdbc0beda0c5c373c1b46b9b636.tar.bz2 nixlib-403acf82248d3cdbc0beda0c5c373c1b46b9b636.tar.lz nixlib-403acf82248d3cdbc0beda0c5c373c1b46b9b636.tar.xz nixlib-403acf82248d3cdbc0beda0c5c373c1b46b9b636.tar.zst nixlib-403acf82248d3cdbc0beda0c5c373c1b46b9b636.zip |
Merge commit '8dfad603247387df1df4826b8bea58efc5d012d8'
Diffstat (limited to 'nixpkgs/nixos/modules/config/fanout.nix')
-rw-r--r-- | nixpkgs/nixos/modules/config/fanout.nix | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/nixpkgs/nixos/modules/config/fanout.nix b/nixpkgs/nixos/modules/config/fanout.nix new file mode 100644 index 000000000000..60ee145f19af --- /dev/null +++ b/nixpkgs/nixos/modules/config/fanout.nix @@ -0,0 +1,49 @@ +{ config, lib, pkgs, ... }: +let + cfg = config.services.fanout; + mknodCmds = n: lib.lists.imap0 (i: s: + "mknod /dev/fanout${builtins.toString i} c $MAJOR ${builtins.toString i}" + ) (lib.lists.replicate n ""); +in +{ + options.services.fanout = { + enable = lib.mkEnableOption (lib.mdDoc "fanout"); + fanoutDevices = lib.mkOption { + type = lib.types.int; + default = 1; + description = "Number of /dev/fanout devices"; + }; + bufferSize = lib.mkOption { + type = lib.types.int; + default = 16384; + description = "Size of /dev/fanout buffer in bytes"; + }; + }; + + config = lib.mkIf cfg.enable { + boot.extraModulePackages = [ config.boot.kernelPackages.fanout.out ]; + + boot.kernelModules = [ "fanout" ]; + + boot.extraModprobeConfig = '' + options fanout buffersize=${builtins.toString cfg.bufferSize} + ''; + + systemd.services.fanout = { + description = "Bring up /dev/fanout devices"; + script = '' + MAJOR=$(${pkgs.gnugrep}/bin/grep fanout /proc/devices | ${pkgs.gawk}/bin/awk '{print $1}') + ${lib.strings.concatLines (mknodCmds cfg.fanoutDevices)} + ''; + + wantedBy = [ "multi-user.target" ]; + + serviceConfig = { + Type = "oneshot"; + User = "root"; + RemainAfterExit = "yes"; + Restart = "no"; + }; + }; + }; +} |