Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vivid: add module #6045

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ let
./programs/vim-vint.nix
./programs/vim.nix
./programs/vinegar.nix
./programs/vivid.nix
./programs/vscode.nix
./programs/vscode/haskell.nix
./programs/pywal.nix
Expand Down
95 changes: 95 additions & 0 deletions modules/programs/vivid.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{ config, lib, pkgs, ... }:
let yaml = pkgs.formats.yaml { };
in with lib; {
meta.maintainers = with maintainers; [ arunoruto ];

options.programs.vivid = {
enable = mkEnableOption ''
vivid - A themeable LS_COLORS generator with a rich filetype database
<link xlink:href="https://github.com/sharkdp/vivid" />
'';

package = mkPackageOption pkgs "vivid" { };

theme = mkOption {
type = with types; nullOr str;
default = null;
example = "molokai";
description = ''
Color theme to enable.
Run `vivid themes` for a list of available themes.
'';
};

filetypes = mkOption {
type = yaml.type;
default = { };
example = literalExpression ''
{
core = {
regular_file = [ "$fi" ];
directory = [ "$di" ];
};
text = {
readme = [ "README.md" ];
licenses = [ "LICENSE" ];
};
}
'';
description = ''
Configuration written to
<filename>~/.config/vivid/filetypes.yml</filename>.
Visit <link xlink:href="https://github.com/sharkdp/vivid/tree/master/config/filetypes.yml" />
for a reference file.
'';
};

themes = mkOption {
type = types.attrsOf (yaml.type);
default = { };
example = literalExpression ''
{
mytheme = {
colors = {
blue = "0000ff";
};
core = {
directory = {
foreground = "blue";
font-style = "bold";
};
};
};
}
'';
description = ''
Theme files written to
<filename>~/.config/vivid/themes/<mytheme>.yml</filename>.
Visit <link xlink:href="https://github.com/sharkdp/vivid/tree/master/themes" />
for references.
'';
};
};

config = let
cfg = config.programs.vivid;
lsColors = builtins.readFile (pkgs.runCommand "vivid-ls-colors" { } ''
${lib.getExe cfg.package} generate ${cfg.theme} > $out
'');
in mkIf cfg.enable {
home = {
packages = [ cfg.package ];
sessionVariables = { LS_COLORS = "${lsColors}"; };
};

xdg.configFile = {
"vivid/filetypes.yml" =
mkIf (builtins.length (builtins.attrNames cfg.filetypes) > 0) {
source = yaml.generate "filetypes.yml" cfg.filetypes;
};
} // mapAttrs' (name: value:
nameValuePair "vivid/themes/${name}.yml" {
source = yaml.generate "${name}.yml" value;
}) cfg.themes;
};
}
1 change: 1 addition & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ in import nmtSrc {
./modules/programs/vifm
./modules/programs/vim-vint
./modules/programs/vinegar
./modules/programs/vivid
./modules/programs/vscode
./modules/programs/watson
./modules/programs/wezterm
Expand Down
5 changes: 5 additions & 0 deletions tests/modules/programs/vivid/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
vivid-empty-settings = ./empty.nix;
vivid-filetypes = ./filetypes-example.nix;
vivid-themes = ./themes-example.nix;
}
11 changes: 11 additions & 0 deletions tests/modules/programs/vivid/empty.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
programs.vivid = {
enable = true;
theme = "test";
};
test.stubs.vivid = { };
nmt.script = ''
assertPathNotExists home-files/.config/vivid/filetypes.yaml
assertPathNotExists home-files/.config/vivid/themes
'';
}
Loading
Loading