Skip to content

Commit 05f72b9

Browse files
committed
vivid: running at evaluation time
1 parent e121f37 commit 05f72b9

File tree

2 files changed

+37
-48
lines changed

2 files changed

+37
-48
lines changed

modules/programs/vivid.nix

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,26 @@
77
let
88
inherit (lib)
99
mkIf
10+
mkMerge
1011
mkEnableOption
1112
mkPackageOption
1213
mkOption
1314
types
1415
;
1516

16-
inherit (lib.hm.shell)
17-
mkBashIntegrationOption
18-
mkZshIntegrationOption
19-
mkFishIntegrationOption
20-
;
21-
2217
cfg = config.programs.vivid;
2318
yamlFormat = pkgs.formats.yaml { };
2419
in
2520
{
26-
meta.maintainers = with lib.hm.maintainers; [ aguirre-matteo ];
21+
meta.maintainers = [
22+
lib.hm.maintainers.aguirre-matteo
23+
lib.maintainers.arunoruto
24+
];
2725

2826
options.programs.vivid = {
2927
enable = mkEnableOption "vivid";
3028
package = mkPackageOption pkgs "vivid" { nullable = true; };
3129

32-
enableBashIntegration = mkBashIntegrationOption { inherit config; };
33-
enableZshIntegration = mkZshIntegrationOption { inherit config; };
34-
enableFishIntegration = mkFishIntegrationOption { inherit config; };
35-
3630
colorMode = mkOption {
3731
type = with types; nullOr str;
3832
default = null;
@@ -71,8 +65,8 @@ in
7165
};
7266

7367
activeTheme = mkOption {
74-
type = with types; nullOr str;
75-
default = null;
68+
type = types.str;
69+
default = "";
7670
example = "molokai";
7771
description = ''
7872
Active theme for vivid.
@@ -116,16 +110,27 @@ in
116110

117111
};
118112

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; };
129134

130135
xdg.configFile = {
131136
"vivid/filetypes.yml" = mkIf (cfg.filetypes != { }) {
@@ -134,21 +139,13 @@ in
134139
}
135140
// (lib.mapAttrs' (
136141
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+
)
140148
) 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+
];
154151
}
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
colors:
2-
primary: 00aaff
3-
secondary: ff00aa
4-
core:
5-
directory:
6-
foreground: primary
7-
executable-file:
8-
font-style: bold
9-
foreground: secondary
1+
{"colors":{"primary":"00aaff","secondary":"ff00aa"},"core":{"directory":{"foreground":"primary"},"executable-file":{"font-style":"bold","foreground":"secondary"}}}

0 commit comments

Comments
 (0)