Skip to content

Commit

Permalink
ghostty: allow darwin users to manager their config
Browse files Browse the repository at this point in the history
Currently nixpkgs does not contain a package defintion for ghostty
compatible with Darwin. Darwin users may still want to use this module
to manage their config or share config between systems. This carries
over behaviour from the beta period where this same technique was used.

see: https://github.com/clo4/ghostty-hm-module/blob/887e13a6e7acf5ffaab0119d96e476d84db90904/module.nix#L167-L173

Also improves validation to cover theme files.
  • Loading branch information
anund committed Jan 10, 2025
1 parent 20665c6 commit 60ccfa9
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions modules/programs/ghostty.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ in {
options.programs.ghostty = {
enable = lib.mkEnableOption "Ghostty";

package = lib.mkPackageOption pkgs "ghostty" { };
package = lib.mkPackageOption pkgs "ghostty" {
nullable = true;
extraDescription =
"On darwin set this to null to manage ghostty config while ghostty is not present in nixpkgs.";
};

settings = lib.mkOption {
inherit (keyValue) type;
Expand Down Expand Up @@ -78,7 +82,7 @@ in {
installBatSyntax =
lib.mkEnableOption "installation of Ghostty configuration syntax for bat"
// {
default = true;
default = (cfg.package != null);
};

enableBashIntegration = lib.mkEnableOption ''
Expand Down Expand Up @@ -108,35 +112,53 @@ in {

config = lib.mkIf cfg.enable (lib.mkMerge [
{
home.packages = [ cfg.package ];
home.packages = lib.mkIf (cfg.package != null) [ 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 (cfg.package != null) "${
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 = lib.elem "vim" cfg.package.outputs or [ ];
message = "ghostty.package does not have a vim output or is null";
}];

programs.vim.plugins = lib.mkIf (cfg.package != null) [ cfg.package.vim ];
})

(lib.mkIf cfg.installBatSyntax {
programs.bat = {
assertions = [{
assertion = cfg.package != null;
message = "cannot install bat syntax while .package is null";
}];

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 60ccfa9

Please sign in to comment.