|
| 1 | +{ config, lib, pkgs, ... }: |
| 2 | +let yaml = pkgs.formats.yaml { }; |
| 3 | +in with lib; { |
| 4 | + meta.maintainers = with maintainers; [ arunoruto ]; |
| 5 | + |
| 6 | + options.programs.vivid = { |
| 7 | + enable = mkEnableOption '' |
| 8 | + vivid - A themeable LS_COLORS generator with a rich filetype datebase |
| 9 | + <link xlink:href="https://github.com/sharkdp/vivid" /> |
| 10 | + ''; |
| 11 | + |
| 12 | + package = mkPackageOption pkgs "vivid" { }; |
| 13 | + |
| 14 | + theme = mkOption { |
| 15 | + type = with types; nullOr str; |
| 16 | + default = null; |
| 17 | + example = "molokai"; |
| 18 | + description = '' |
| 19 | + Color theme to enable. |
| 20 | + Run `vivid themes` for a list of available themes. |
| 21 | + ''; |
| 22 | + }; |
| 23 | + |
| 24 | + filetypes = mkOption { |
| 25 | + type = yaml.type; |
| 26 | + default = { }; |
| 27 | + example = literalExpression '' |
| 28 | + { |
| 29 | + core = { |
| 30 | + regular_file = [ "$fi" ]; |
| 31 | + directory = [ "$di" ]; |
| 32 | + }; |
| 33 | + text = { |
| 34 | + readme = [ "README.md" ]; |
| 35 | + licenses = [ "LICENSE" ]; |
| 36 | + }; |
| 37 | + } |
| 38 | + ''; |
| 39 | + description = '' |
| 40 | + Configuration written to |
| 41 | + <filename>~/.config/vivid/filetypes.yml</filename>. |
| 42 | + Visit <link xlink:href="https://github.com/sharkdp/vivid/tree/master/config/filetypes.yml" /> |
| 43 | + for a reference file. |
| 44 | + ''; |
| 45 | + }; |
| 46 | + |
| 47 | + themes = mkOption { |
| 48 | + type = types.attrsOf (yaml.type); |
| 49 | + default = { }; |
| 50 | + example = literalExpression '' |
| 51 | + { |
| 52 | + mytheme = { |
| 53 | + colors = { |
| 54 | + blue = "0000ff"; |
| 55 | + }; |
| 56 | + core = { |
| 57 | + directory = { |
| 58 | + foreground = "blue"; |
| 59 | + font-style = "bold"; |
| 60 | + }; |
| 61 | + }; |
| 62 | + }; |
| 63 | + } |
| 64 | + ''; |
| 65 | + description = '' |
| 66 | + Theme files written to |
| 67 | + <filename>~/.config/vivid/themes/<mytheme>.yml</filename>. |
| 68 | + Visit <link xlink:href="https://github.com/sharkdp/vivid/tree/master/themes" /> |
| 69 | + for references. |
| 70 | + ''; |
| 71 | + }; |
| 72 | + }; |
| 73 | + |
| 74 | + config = let |
| 75 | + cfg = config.programs.vivid; |
| 76 | + lsColors = builtins.readFile (pkgs.runCommand "vivid-ls-colors" { } '' |
| 77 | + ${lib.getExe pkgs.vivid} generate ${cfg.theme} > $out |
| 78 | + ''); |
| 79 | + in mkIf cfg.enable { |
| 80 | + home = { |
| 81 | + packages = [ cfg.package ]; |
| 82 | + sessionVariables = { LS_COLORS = "${lsColors}"; }; |
| 83 | + }; |
| 84 | + |
| 85 | + xdg.configFile = { |
| 86 | + "vivid/filetypes.yml" = |
| 87 | + mkIf (builtins.length (builtins.attrNames cfg.filetypes) > 0) { |
| 88 | + source = yaml.generate "filetypes.yml" cfg.filetypes; |
| 89 | + }; |
| 90 | + } // mapAttrs' (name: value: |
| 91 | + nameValuePair "vivid/themes/${name}.yml" { |
| 92 | + source = yaml.generate "${name}.yml" value; |
| 93 | + }) cfg.themes; |
| 94 | + }; |
| 95 | +} |
0 commit comments