Skip to content

Commit

Permalink
ghostty: allow nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
anund committed Jan 11, 2025
1 parent b948bae commit 891c29d
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions modules/programs/ghostty.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ in {
options.programs.ghostty = {
enable = lib.mkEnableOption "Ghostty";

package = lib.mkPackageOption pkgs "ghostty" { };
package = lib.mkPackageOption pkgs "ghostty" { nullable = true; };

settings = lib.mkOption {
inherit (keyValue) type;
Expand Down Expand Up @@ -78,9 +78,9 @@ in {
installBatSyntax =
lib.mkEnableOption "installation of Ghostty configuration syntax for bat"
// {
default = pkgs.stdenv.hostPlatform.isLinux;
default = cfg.package != null;
defaultText =
lib.literalMD "`true` if host platform is Linux, if not, `false`";
lib.literalMD "`true` if programs.ghostty.package is not null";
};

enableBashIntegration = lib.mkEnableOption ''
Expand Down Expand Up @@ -110,8 +110,7 @@ in {

config = lib.mkIf cfg.enable (lib.mkMerge [
{
home.packages =
lib.optionals pkgs.stdenv.hostPlatform.isLinux [ cfg.package ];
home.packages = lib.optionals (cfg.package != null) [ cfg.package ];

programs.ghostty.settings = lib.mkIf cfg.clearDefaultKeybinds {
keybind = lib.mkBefore [ "clear" ];
Expand All @@ -121,7 +120,7 @@ in {
# Linux and macOS to reduce complexity
xdg.configFile = let
validate = file:
lib.mkIf pkgs.stdenv.hostPlatform.isLinux "${
lib.mkIf (cfg.package != null) "${
lib.getExe cfg.package
} +validate-config --config-file=${config.xdg.configHome}/ghostty/${file}";
in lib.mkMerge [
Expand All @@ -144,21 +143,21 @@ in {

(lib.mkIf cfg.installVimSyntax {
assertions = [{
assertion = cfg.installVimSyntax -> pkgs.stdenv.hostPlatform.isLinux;
assertion = cfg.installVimSyntax -> cfg.package != null;
message =
"programs.ghostty.installVimSyntax cannot be enabled on darwin as it depends on the package";
}];
programs.vim.plugins =
lib.optionals pkgs.stdenv.hostPlatform.isLinux [ cfg.package.vim ];
lib.optionals (cfg.package != null) [ cfg.package.vim ];
})

(lib.mkIf cfg.installBatSyntax {
assertions = [{
assertion = cfg.installBatSyntax -> pkgs.stdenv.hostPlatform.isLinux;
assertion = cfg.installBatSyntax -> cfg.package != null;
message =
"programs.ghostty.installBatSyntax cannot be enabled on darwin as it depends on the package";
}];
programs.bat = lib.mkIf pkgs.stdenv.hostPlatform.isLinux {
programs.bat = lib.mkIf (cfg.package != null) {
syntaxes.ghostty = {
src = cfg.package;
file = "share/bat/syntaxes/ghostty.sublime-syntax";
Expand Down

0 comments on commit 891c29d

Please sign in to comment.