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 1 commit 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 @@ -248,6 +248,7 @@ let
./programs/vifm.nix
./programs/vim-vint.nix
./programs/vim.nix
./programs/vivid.nix
./programs/vscode.nix
./programs/vscode/haskell.nix
./programs/pywal.nix
Expand Down
141 changes: 141 additions & 0 deletions modules/programs/vivid.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{ config, lib, pkgs, ... }:
let
yaml = pkgs.formats.yaml { };
bashLine = theme:
''export LS_COLORS="$(${lib.getExe pkgs.vivid} generate ${theme})"'';
fishLine = theme:
"set -gx LS_COLORS (${lib.getExe pkgs.vivid} generate ${theme})";
nushellLine = theme: "${lib.getExe pkgs.vivid} generate ${theme}";
zshLine = bashLine;
in {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can put a with lib; declaration here, so usages of lib afterward can be shorten.

meta.maintainers = [ lib.maintainers.arunoruto ];

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

package = lib.mkPackageOption pkgs "vivid" { };

enableBashIntegration = lib.mkOption {
default = true;
type = lib.types.bool;
description = ''
Whether to enable Bash integration.
Adds `${bashLine "<theme>"}` to Bash.
'';
};

enableFishIntegration = lib.mkOption {
default = true;
type = lib.types.bool;
description = ''
Whether to enable Fish integration.
Adds `${fishLine "<theme>"}` to Fish.
'';
};

enableNushellIntegration = lib.mkOption {
default = true;
type = lib.types.bool;
description = ''
Whether to enable Nushell integration.
Adds `${nushellLine "<theme>"}` to Nushell.
'';
};

enableZshIntegration = lib.mkOption {
default = true;
type = lib.types.bool;
description = ''
Whether to enable Zsh integration.
Adds `${zshLine "<theme>"}` to Zsh.
'';
};

theme = lib.mkOption {
type = lib.types.nullOr lib.types.str;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type = lib.types.nullOr lib.types.str;
type = with types; nullOr str;

assuming that with lib; was declared above.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same goes for the other options as well.

default = null;
example = "molokai";
description = ''
Color theme to enable.
Run `vivid themes` for a list of available themes.
'';
};

filetypes = lib.mkOption {
type = yaml.type;
default = { };
example = lib.literalExample ''
{
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 = lib.mkOption {
type = lib.types.attrsOf (yaml.type);
default = { };
example = lib.literalExample ''
{
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;
in lib.mkIf cfg.enable {
home.packages = [ cfg.package ];

programs.bash.initExtra =
lib.mkIf cfg.enableBashIntegration (bashLine cfg.theme);
programs.fish.interactiveShellInit =
lib.mkIf cfg.enableFishIntegration (fishLine cfg.theme);
programs.nushell.environmentVariables.LS_COLORS =
lib.mkIf cfg.enableNushellIntegration
(lib.hm.nushell.mkNushellInline (nushellLine cfg.theme));
programs.zsh.initExtra =
lib.mkIf cfg.enableZshIntegration (zshLine cfg.theme);

xdg.configFile = {
"vivid/filetypes.yml" =
lib.mkIf (builtins.length (builtins.attrNames cfg.filetypes) > 0) {
source = yaml.generate "filetypes.yml" cfg.filetypes;
};
} // lib.mapAttrs' (name: value:
lib.nameValuePair "vivid/themes/${name}.yml" {
source = yaml.generate "${name}.yml" value;
}) cfg.themes;
};
}