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

ghostty: allow darwin users to manager their config #6300

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
36 changes: 29 additions & 7 deletions modules/programs/ghostty.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''
Expand Down Expand Up @@ -108,35 +110,55 @@ 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" ];
};

# 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";
Expand Down
Loading