|
7 | 7 | let |
8 | 8 | inherit (lib) |
9 | 9 | mkIf |
| 10 | + mkMerge |
10 | 11 | mkEnableOption |
11 | 12 | mkPackageOption |
12 | 13 | mkOption |
13 | 14 | types |
14 | 15 | ; |
15 | 16 |
|
16 | | - inherit (lib.hm.shell) |
17 | | - mkBashIntegrationOption |
18 | | - mkZshIntegrationOption |
19 | | - mkFishIntegrationOption |
20 | | - ; |
21 | | - |
22 | 17 | cfg = config.programs.vivid; |
23 | 18 | yamlFormat = pkgs.formats.yaml { }; |
24 | 19 | in |
25 | 20 | { |
26 | | - meta.maintainers = with lib.hm.maintainers; [ aguirre-matteo ]; |
| 21 | + meta.maintainers = [ |
| 22 | + lib.hm.maintainers.aguirre-matteo |
| 23 | + lib.maintainers.arunoruto |
| 24 | + ]; |
27 | 25 |
|
28 | 26 | options.programs.vivid = { |
29 | 27 | enable = mkEnableOption "vivid"; |
30 | 28 | package = mkPackageOption pkgs "vivid" { nullable = true; }; |
31 | 29 |
|
32 | | - enableBashIntegration = mkBashIntegrationOption { inherit config; }; |
33 | | - enableZshIntegration = mkZshIntegrationOption { inherit config; }; |
34 | | - enableFishIntegration = mkFishIntegrationOption { inherit config; }; |
35 | | - |
36 | 30 | colorMode = mkOption { |
37 | 31 | type = with types; nullOr str; |
38 | 32 | default = null; |
|
71 | 65 | }; |
72 | 66 |
|
73 | 67 | activeTheme = mkOption { |
74 | | - type = with types; nullOr str; |
75 | | - default = null; |
| 68 | + type = types.str; |
| 69 | + default = ""; |
76 | 70 | example = "molokai"; |
77 | 71 | description = '' |
78 | 72 | Active theme for vivid. |
|
116 | 110 |
|
117 | 111 | }; |
118 | 112 |
|
119 | | - config = |
120 | | - let |
121 | | - vividCommand = "vivid ${ |
122 | | - lib.optionalString (cfg.colorMode != null) "-m ${cfg.colorMode}" |
123 | | - } generate ${lib.optionalString (cfg.activeTheme != null) cfg.activeTheme}"; |
124 | | - in |
125 | | - mkIf cfg.enable { |
126 | | - home.packages = mkIf (cfg.package != null) [ cfg.package ]; |
127 | | - |
128 | | - home.sessionVariables = mkIf (cfg.activeTheme != null) { VIVID_THEME = cfg.activeTheme; }; |
| 113 | + config = mkMerge [ |
| 114 | + (mkIf (cfg.enable || cfg.themes != { }) { |
| 115 | + home.sessionVariables.LS_COLORS = |
| 116 | + let |
| 117 | + colorMode = lib.optionalString (cfg.colorMode != null) "-m ${cfg.colorMode}"; |
| 118 | + themePath = |
| 119 | + if builtins.isAttrs cfg.themes.${cfg.activeTheme} then |
| 120 | + pkgs.writeText "${cfg.activeTheme}.json" (builtins.toJSON cfg.themes.${cfg.activeTheme}) |
| 121 | + else if config.xdg.configFile ? "vivid/themes/${cfg.activeTheme}.yml" then |
| 122 | + config.xdg.configFile."vivid/themes/${cfg.activeTheme}.yml".source |
| 123 | + else |
| 124 | + cfg.activeTheme; |
| 125 | + in |
| 126 | + "$(cat ${ |
| 127 | + pkgs.runCommand "ls-colors" { |
| 128 | + nativeBuildInputs = [ cfg.package ]; |
| 129 | + } "vivid ${colorMode} generate ${themePath} > $out" |
| 130 | + })"; |
| 131 | + }) |
| 132 | + (mkIf cfg.enable { |
| 133 | + home.sessionVariables = mkIf (cfg.activeTheme != "") { VIVID_THEME = cfg.activeTheme; }; |
129 | 134 |
|
130 | 135 | xdg.configFile = { |
131 | 136 | "vivid/filetypes.yml" = mkIf (cfg.filetypes != { }) { |
|
134 | 139 | } |
135 | 140 | // (lib.mapAttrs' ( |
136 | 141 | name: value: |
137 | | - lib.nameValuePair "vivid/themes/${name}.yml" { |
138 | | - source = if lib.isAttrs value then yamlFormat.generate "${name}.yml" value else value; |
139 | | - } |
| 142 | + lib.nameValuePair "vivid/themes/${name}.yml" ( |
| 143 | + if lib.isAttrs value then |
| 144 | + { source = pkgs.writeText "${name}.json" (builtins.toJSON value); } |
| 145 | + else |
| 146 | + { source = value; } |
| 147 | + ) |
140 | 148 | ) cfg.themes); |
141 | | - |
142 | | - programs.bash.initExtra = mkIf cfg.enableBashIntegration '' |
143 | | - export LS_COLORS="$(${vividCommand})" |
144 | | - ''; |
145 | | - |
146 | | - programs.zsh.initContent = mkIf cfg.enableZshIntegration '' |
147 | | - export LS_COLORS="$(${vividCommand})" |
148 | | - ''; |
149 | | - |
150 | | - programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration '' |
151 | | - set -gx LS_COLORS "$(${vividCommand})" |
152 | | - ''; |
153 | | - }; |
| 149 | + }) |
| 150 | + ]; |
154 | 151 | } |
0 commit comments