fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . programs . feh ; 8 9bindingsOf = t :with types ; attrsOf ( nullOr ( either t ( listOf t ))); 10 11renderBindings = bindings : 12let 13enabled = filterAttrs ( n :v :v != null ) bindings ; 14disabled = filterAttrs ( n :v :v == null ) bindings ; 15render = mapAttrsToList renderBinding ; 16in concatStringsSep "\n" ( render disabled ++ render enabled ); 17 18renderBinding = func :key : 19if key == null then 20func 21else if isList key then 22concatStringsSep " " ([ func ] ++ map toString key ) 23else 24" ${ func } ${ toString key } " ; 25 26in { 27options . programs . feh = { 28enable = mkEnableOption "feh - a fast and light image viewer" ; 29 30package = mkPackageOption pkgs "feh" { }; 31 32buttons = mkOption { 33default = { }; 34type = with types ; bindingsOf ( either str int ); 35example = { 36zoom_in = 4 ; 37zoom_out = "C-4" ; 38prev_img = [ 3 "C-3" ]; 39}; 40description = '' 41Override feh's default mouse button mapping. If you want to disable an 42action, set its value to null. If you want to bind multiple buttons to 43an action, set its value to a list. 44See <https://man.finalrewind.org/1/feh/#x425554544f4e53> for 45default bindings and available commands. 46'' ; 47}; 48 49keybindings = mkOption { 50default = { }; 51type = bindingsOf types . str ; 52example = { 53zoom_in = "plus" ; 54zoom_out = "minus" ; 55prev_img = [ "h" "Left" ]; 56}; 57description = '' 58Override feh's default keybindings. If you want to disable a keybinding 59set its value to null. If you want to bind multiple keys to an action, 60set its value to a list. 61See <https://man.finalrewind.org/1/feh/#x4b455953> for 62default bindings and available commands. 63'' ; 64}; 65}; 66 67config = mkIf cfg . enable { 68assertions = [{ 69assertion = (( filterAttrs ( n :v :v == "" ) cfg . keybindings ) == { }); 70message = 71"To disable a keybinding, use `null` instead of an empty string." ; 72}]; 73 74home . packages = [ cfg . package ]; 75 76xdg . configFile . "feh/buttons" = 77mkIf ( cfg . buttons != { }) { text = renderBindings cfg . buttons + "\n" ; }; 78 79xdg . configFile . "feh/keys" = mkIf ( cfg . keybindings != { }) { 80text = renderBindings cfg . keybindings + "\n" ; 81}; 82}; 83}