diff --git a/modules/programs/alacritty.nix b/modules/programs/alacritty.nix index e095f0ca..01b85243 100644 --- a/modules/programs/alacritty.nix +++ b/modules/programs/alacritty.nix @@ -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 + 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: {