|
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 | + ]; |
| 25 | + |
| 26 | + imports = [ |
| 27 | + (lib.mkRemovedOptionModule [ |
| 28 | + "programs" |
| 29 | + "vivid" |
| 30 | + "enableBashIntegration" |
| 31 | + ] "Now the shell integration is always enabled.") |
| 32 | + (lib.mkRemovedOptionModule [ |
| 33 | + "programs" |
| 34 | + "vivid" |
| 35 | + "enableZshIntegration" |
| 36 | + ] "Now the shell integration is always enabled.") |
| 37 | + (lib.mkRemovedOptionModule [ |
| 38 | + "programs" |
| 39 | + "vivid" |
| 40 | + "enableFishIntegration" |
| 41 | + ] "Now the shell integration is always enabled.") |
| 42 | + ]; |
27 | 43 |
|
28 | 44 | options.programs.vivid = { |
29 | 45 | enable = mkEnableOption "vivid"; |
30 | 46 | package = mkPackageOption pkgs "vivid" { nullable = true; }; |
31 | 47 |
|
32 | | - enableBashIntegration = mkBashIntegrationOption { inherit config; }; |
33 | | - enableZshIntegration = mkZshIntegrationOption { inherit config; }; |
34 | | - enableFishIntegration = mkFishIntegrationOption { inherit config; }; |
35 | | - |
36 | 48 | colorMode = mkOption { |
37 | | - type = with types; nullOr str; |
| 49 | + type = |
| 50 | + with types; |
| 51 | + nullOr (enum [ |
| 52 | + "8-bit" |
| 53 | + "24-bit" |
| 54 | + ]); |
38 | 55 | default = null; |
39 | 56 | example = "8-bit"; |
40 | 57 | description = '' |
|
71 | 88 | }; |
72 | 89 |
|
73 | 90 | activeTheme = mkOption { |
74 | | - type = with types; nullOr str; |
75 | | - default = null; |
| 91 | + type = types.str; |
| 92 | + default = ""; |
76 | 93 | example = "molokai"; |
77 | 94 | description = '' |
78 | 95 | Active theme for vivid. |
|
116 | 133 |
|
117 | 134 | }; |
118 | 135 |
|
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; }; |
| 136 | + config = mkMerge [ |
| 137 | + (mkIf (cfg.enable || cfg.themes != { }) { |
| 138 | + home.sessionVariables.LS_COLORS = |
| 139 | + let |
| 140 | + colorMode = lib.optionalString (cfg.colorMode != null) "-m ${cfg.colorMode}"; |
| 141 | + filetypes = lib.optionalString ( |
| 142 | + cfg.filetypes != { } |
| 143 | + ) "-d ${yamlFormat.generate "vivid-filetypes" cfg.filetypes}"; |
| 144 | + themePath = |
| 145 | + if builtins.isAttrs cfg.themes.${cfg.activeTheme} then |
| 146 | + pkgs.writeText "${cfg.activeTheme}.json" (builtins.toJSON cfg.themes.${cfg.activeTheme}) |
| 147 | + else if config.xdg.configFile ? "vivid/themes/${cfg.activeTheme}.yml" then |
| 148 | + config.xdg.configFile."vivid/themes/${cfg.activeTheme}.yml".source |
| 149 | + else |
| 150 | + cfg.activeTheme; |
| 151 | + in |
| 152 | + "$(cat ${ |
| 153 | + pkgs.runCommand "ls-colors" { |
| 154 | + nativeBuildInputs = [ cfg.package ]; |
| 155 | + } "vivid ${colorMode} ${filetypes} generate ${themePath} >$out" |
| 156 | + })"; |
| 157 | + }) |
| 158 | + (mkIf cfg.enable { |
| 159 | + home.sessionVariables = mkIf (cfg.activeTheme != "") { VIVID_THEME = cfg.activeTheme; }; |
129 | 160 |
|
130 | 161 | xdg.configFile = { |
131 | 162 | "vivid/filetypes.yml" = mkIf (cfg.filetypes != { }) { |
|
135 | 166 | // (lib.mapAttrs' ( |
136 | 167 | name: value: |
137 | 168 | lib.nameValuePair "vivid/themes/${name}.yml" { |
138 | | - source = if lib.isAttrs value then yamlFormat.generate "${name}.yml" value else value; |
| 169 | + # Since JSON is a YAML subset, it can be used to populate the config file |
| 170 | + # JSON has better support in Nix than YAML |
| 171 | + # Values like 1e2030 will be treated as a string by Nix, but in YAML are read as a number in scientific notation |
| 172 | + source = if lib.isAttrs value then pkgs.writeText "${name}.json" (builtins.toJSON value) else value; |
139 | 173 | } |
140 | 174 | ) 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 | | - }; |
| 175 | + }) |
| 176 | + ]; |
154 | 177 | } |
0 commit comments