alacritty: add theme option (#5238)
Co-authored-by: r-vdp <ramses@well-founded.dev> Co-authored-by: Sumner Evans <me@sumnerevans.com>
This commit is contained in:
parent
e355ae93a3
commit
938e802b70
1 changed files with 39 additions and 0 deletions
|
|
@ -9,6 +9,22 @@ in {
|
|||
|
||||
package = lib.mkPackageOption pkgs "alacritty" { };
|
||||
|
||||
theme = lib.mkOption {
|
||||
type = with lib.types; nullOr str;
|
||||
default = null;
|
||||
example = "solarized_dark";
|
||||
description = ''
|
||||
A theme from the
|
||||
[alacritty-theme](https://github.com/alacritty/alacritty-theme)
|
||||
repository to import in the configuration.
|
||||
See <https://github.com/alacritty/alacritty-theme/tree/master/themes>
|
||||
for a list of available themes.
|
||||
If you would like to import your own theme, use
|
||||
{option}`programs.alacritty.settings.general.import` or
|
||||
{option}`programs.alacritty.settings.colors` directly.
|
||||
'';
|
||||
};
|
||||
|
||||
settings = lib.mkOption {
|
||||
type = tomlFormat.type;
|
||||
default = { };
|
||||
|
|
@ -40,8 +56,31 @@ in {
|
|||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
assertions = [{
|
||||
# If using the theme option, ensure that theme exists in the
|
||||
# alacritty-theme package.
|
||||
assertion = let
|
||||
available = lib.pipe "${pkgs.alacritty-theme}/share/alacritty-theme" [
|
||||
builtins.readDir
|
||||
(lib.filterAttrs
|
||||
(name: type: type == "regular" && lib.hasSuffix ".toml" name))
|
||||
lib.attrNames
|
||||
(lib.map (lib.removeSuffix ".toml"))
|
||||
];
|
||||
in cfg.theme == null || (builtins.elem cfg.theme available);
|
||||
message = "The alacritty theme '${cfg.theme}' does not exist.";
|
||||
}];
|
||||
|
||||
home.packages = [ cfg.package ];
|
||||
|
||||
programs.alacritty.settings = let
|
||||
theme = "${pkgs.alacritty-theme}/share/alacritty-theme/${cfg.theme}.toml";
|
||||
in lib.mkIf (cfg.theme != null) {
|
||||
general.import =
|
||||
lib.mkIf (lib.versionAtLeast cfg.package.version "0.14") [ theme ];
|
||||
import = lib.mkIf (lib.versionOlder cfg.package.version "0.14") [ theme ];
|
||||
};
|
||||
|
||||
xdg.configFile."alacritty/alacritty.toml" = lib.mkIf (cfg.settings != { }) {
|
||||
source = (tomlFormat.generate "alacritty.toml" cfg.settings).overrideAttrs
|
||||
(finalAttrs: prevAttrs: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue