fork/home-manager
git clone https://git.julia.blue/fork/home-manager
44635279
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . programs . bat ; 8 9package = pkgs . bat ; 10 11toConfigFile = generators . toKeyValue { 12mkKeyValue = k :v :"-- ${ k } = ${ lib . escapeShellArg v } " ; 13listsAsDuplicateKeys = true ; 14}; 15 16in { 17meta . maintainers = [ ]; 18 19options . programs . bat = { 20enable = mkEnableOption "bat, a cat clone with wings" ; 21 22config = mkOption { 23type = with types ; attrsOf ( either str ( listOf str )); 24default = { }; 25example = { 26theme = "TwoDark" ; 27pager = "less -FR" ; 28map-syntax = [ "*.jenkinsfile:Groovy" "*.props:Java Properties" ]; 29}; 30description = '' 31Bat configuration. 32'' ; 33}; 34 35extraPackages = mkOption { 36type = types . listOf types . package ; 37default = [ ]; 38example = literalExpression 39"with pkgs.bat-extras; [ batdiff batman batgrep batwatch ];" ; 40description = '' 41Additional bat packages to install. 42'' ; 43}; 44 45themes = mkOption { 46type = types . attrsOf ( types . either types . lines ( types . submodule { 47options = { 48src = mkOption { 49type = types . path ; 50description = "Path to the theme folder." ; 51}; 52 53file = mkOption { 54type = types . nullOr types . str ; 55default = null ; 56description = 57"Subpath of the theme file within the source, if needed." ; 58}; 59}; 60})); 61default = { }; 62example = literalExpression '' 63{ 64dracula = { 65src = pkgs.fetchFromGitHub { 66owner = "dracula"; 67repo = "sublime"; # Bat uses sublime syntax for its themes 68rev = "26c57ec282abcaa76e57e055f38432bd827ac34e"; 69sha256 = "019hfl4zbn4vm4154hh3bwk6hm7bdxbr1hdww83nabxwjn99ndhv"; 70}; 71file = "Dracula.tmTheme"; 72}; 73} 74'' ; 75description = '' 76Additional themes to provide. 77'' ; 78}; 79 80syntaxes = mkOption { 81type = types . attrsOf ( types . either types . lines ( types . submodule { 82options = { 83src = mkOption { 84type = types . path ; 85description = "Path to the syntax folder." ; 86}; 87file = mkOption { 88type = types . nullOr types . str ; 89default = null ; 90description = 91"Subpath of the syntax file within the source, if needed." ; 92}; 93}; 94})); 95default = { }; 96example = literalExpression '' 97{ 98gleam = { 99src = pkgs.fetchFromGitHub { 100owner = "molnarmark"; 101repo = "sublime-gleam"; 102rev = "2e761cdb1a87539d827987f997a20a35efd68aa9"; 103hash = "sha256-Zj2DKTcO1t9g18qsNKtpHKElbRSc9nBRE2QBzRn9+qs="; 104}; 105file = "syntax/gleam.sublime-syntax"; 106}; 107} 108'' ; 109description = '' 110Additional syntaxes to provide. 111'' ; 112}; 113}; 114 115config = mkIf cfg . enable ( mkMerge [ 116( mkIf ( any isString ( attrValues cfg . themes )) { 117warnings = [ '' 118Using programs.bat.themes as a string option is deprecated and will be 119removed in the future. Please change to using it as an attribute set 120instead. 121'' ]; 122}) 123( mkIf ( any isString ( attrValues cfg . syntaxes )) { 124warnings = [ '' 125Using programs.bat.syntaxes as a string option is deprecated and will be 126removed in the future. Please change to using it as an attribute set 127instead. 128'' ]; 129}) 130{ 131home . packages = [ package ] ++ cfg . extraPackages ; 132 133xdg . configFile = mkMerge ([({ 134"bat/config" = 135mkIf ( cfg . config != { }) { text = toConfigFile cfg . config ; }; 136})] ++ ( flip mapAttrsToList cfg . themes ( name :val :{ 137"bat/themes/ ${ name } .tmTheme" = if isString val then { 138text = val ; 139} else { 140source = 141if isNull val . file then " ${ val . src } " else " ${ val . src } / ${ val . file } " ; 142}; 143})) ++ ( flip mapAttrsToList cfg . syntaxes ( name :val :{ 144"bat/syntaxes/ ${ name } .sublime-syntax" = if isString val then { 145text = val ; 146} else { 147source = 148if isNull val . file then " ${ val . src } " else " ${ val . src } / ${ val . file } " ; 149}; 150}))); 151 152home . activation . batCache = hm . dag . entryAfter [ "linkGeneration" ] '' 153( 154export XDG_CACHE_HOME= ${ escapeShellArg config . xdg . cacheHome } 155$VERBOSE_ECHO "Rebuilding bat theme cache" 156$DRY_RUN_CMD ${ lib . getExe package } cache --build 157) 158'' ; 159} 160]); 161}