diff --git a/modules/programs/ghostty.nix b/modules/programs/ghostty.nix index 9ebaa7b30c0e..8ed8b34a7fa7 100644 --- a/modules/programs/ghostty.nix +++ b/modules/programs/ghostty.nix @@ -78,7 +78,9 @@ in { installBatSyntax = lib.mkEnableOption "installation of Ghostty configuration syntax for bat" // { - default = true; + default = pkgs.stdenv.hostPlatform.isLinux; + defaultText = + lib.literalMD "`true` if host platform is Linux, if not, `false`"; }; enableBashIntegration = lib.mkEnableOption '' @@ -108,7 +110,8 @@ in { config = lib.mkIf cfg.enable (lib.mkMerge [ { - home.packages = [ cfg.package ]; + home.packages = + lib.optionals pkgs.stdenv.hostPlatform.isLinux [ cfg.package ]; programs.ghostty.settings = lib.mkIf cfg.clearDefaultKeybinds { keybind = lib.mkBefore [ "clear" ]; @@ -116,27 +119,46 @@ in { # MacOS also supports XDG configuration directory, so we use it for both # Linux and macOS to reduce complexity - xdg.configFile = lib.mkMerge [ + xdg.configFile = let + validate = file: + lib.mkIf pkgs.stdenv.hostPlatform.isLinux "${ + lib.getExe cfg.package + } +validate-config --config-file=${config.xdg.configHome}/ghostty/${file}"; + in lib.mkMerge [ { "ghostty/config" = lib.mkIf (cfg.settings != { }) { source = keyValue.generate "ghostty-config" cfg.settings; - onChange = "${lib.getExe cfg.package} +validate-config"; + onChange = validate "config"; }; } (lib.mkIf (cfg.themes != { }) (lib.mapAttrs' (name: value: { name = "ghostty/themes/${name}"; - value.source = keyValue.generate "ghostty-${name}-theme" value; + value = { + source = keyValue.generate "ghostty-${name}-theme" value; + onChange = validate "themes/${name}"; + }; }) cfg.themes)) ]; } (lib.mkIf cfg.installVimSyntax { - programs.vim.plugins = [ cfg.package.vim ]; + assertions = [{ + assertion = cfg.installVimSyntax -> pkgs.stdenv.hostPlatform.isLinux; + 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.mkIf cfg.installBatSyntax { - programs.bat = { + assertions = [{ + assertion = cfg.installBatSyntax -> pkgs.stdenv.hostPlatform.isLinux; + message = + "programs.ghostty.installBatSyntax cannot be enabled on darwin as it depends on the package"; + }]; + programs.bat = lib.mkIf pkgs.stdenv.hostPlatform.isLinux { syntaxes.ghostty = { src = cfg.package; file = "share/bat/syntaxes/ghostty.sublime-syntax";