at 23.11-pre 1.8 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.interception-tools; 7in { 8 options.services.interception-tools = { 9 enable = mkOption { 10 type = types.bool; 11 default = false; 12 description = lib.mdDoc "Whether to enable the interception tools service."; 13 }; 14 15 plugins = mkOption { 16 type = types.listOf types.package; 17 default = [ pkgs.interception-tools-plugins.caps2esc ]; 18 defaultText = literalExpression "[ pkgs.interception-tools-plugins.caps2esc ]"; 19 description = lib.mdDoc '' 20 A list of interception tools plugins that will be made available to use 21 inside the udevmon configuration. 22 ''; 23 }; 24 25 udevmonConfig = mkOption { 26 type = types.either types.str types.path; 27 default = '' 28 - JOB: "intercept -g $DEVNODE | caps2esc | uinput -d $DEVNODE" 29 DEVICE: 30 EVENTS: 31 EV_KEY: [KEY_CAPSLOCK, KEY_ESC] 32 ''; 33 example = '' 34 - JOB: "intercept -g $DEVNODE | y2z | x2y | uinput -d $DEVNODE" 35 DEVICE: 36 EVENTS: 37 EV_KEY: [KEY_X, KEY_Y] 38 ''; 39 description = lib.mdDoc '' 40 String of udevmon YAML configuration, or path to a udevmon YAML 41 configuration file. 42 ''; 43 }; 44 }; 45 46 config = mkIf cfg.enable { 47 systemd.services.interception-tools = { 48 description = "Interception tools"; 49 path = [ pkgs.bash pkgs.interception-tools ] ++ cfg.plugins; 50 serviceConfig = { 51 ExecStart = '' 52 ${pkgs.interception-tools}/bin/udevmon -c \ 53 ${if builtins.typeOf cfg.udevmonConfig == "path" 54 then cfg.udevmonConfig 55 else pkgs.writeText "udevmon.yaml" cfg.udevmonConfig} 56 ''; 57 Nice = -20; 58 }; 59 wantedBy = [ "multi-user.target" ]; 60 }; 61 }; 62}