citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

default.nix (1716B)


      1 { config, lib, pkgs, ... }:
      2 
      3 with lib;
      4 
      5 let
      6 
      7   cfg = config.services.footswitch;
      8 
      9 in {
     10 
     11   options.services.footswitch = {
     12     enable = mkOption {
     13       type = types.bool;
     14       default = false;
     15       example = true;
     16       description = "Enable foot switch";
     17     };
     18 
     19     enable-led = mkOption {
     20       type = types.bool;
     21       default = false;
     22       example = true;
     23       description = "Enable foot switch led";
     24     };
     25 
     26     led = mkOption {
     27       type = types.string;
     28       default = "input2::scrolllock";
     29       example = "input2::scrolllock";
     30       description = "/sys/class/leds/<led> to turn on when foot switch is pressed";
     31     };
     32 
     33     args = mkOption {
     34       type = types.string;
     35       default = "-m alt";
     36       example = "-m ctrl";
     37       description = "footswitch arguments";
     38     };
     39 
     40   };
     41 
     42   config = mkIf cfg.enable {
     43     systemd.services.footswitch = {
     44       description = "Footswitch Setup";
     45 
     46       wantedBy = [ "multi-user.target" ];
     47 
     48       serviceConfig.Type = "oneshot";
     49       serviceConfig.RemainAfterExit = "yes";
     50       serviceConfig.ExecStart = "${pkgs.footswitch}/bin/footswitch ${cfg.args}";
     51     };
     52 
     53 
     54     systemd.services.footswitch-led = mkIf cfg.enable-led {
     55       description = "Footswitch LED";
     56 
     57       wantedBy = [ "multi-user.target" ];
     58 
     59       serviceConfig.Type = "simple";
     60       serviceConfig.ExecStart = pkgs.writeScript "footswitch-led" ''
     61         #!${pkgs.bash}/bin/bash
     62         ${pkgs.evtest}/bin/evtest /dev/input/by-id/usb-RDing_FootSwitch1F1.-event-kbd | \
     63           stdbuf -oL grep KEY_ | \
     64           stdbuf -oL sed 's/.*value \(.\)$/\1/' | \
     65           stdbuf -oL tr '2' '1' | \
     66           while read x; do echo $x > /sys/class/leds/${cfg.led}/brightness; done
     67       '';
     68     };
     69   };
     70 
     71 
     72 }