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 1 commit
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
42 changes: 34 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.";
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to capitalize ghostty in the description

Suggested change
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.";
};
package = lib.mkPackageOption pkgs "Ghostty" { default = [ "ghostty" ]; };

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't appear to work when nixpkgs is marking the package as broken. Setting the package to null in config isn't allowed (not nullable) and nixpkgs evaluates the default since it is present. This does work when the package isn't present at all.

Copy link
Member

@HeitorAugustoLN HeitorAugustoLN Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't be present look at: #6300 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, my mistake on where the actual eval was coming from. "Ghostty" isn't needed if we're guarding all the package sites. mkPackageOption currently only checks for presence not whether or not the package is broken.

I considered checking if the package is broken instead and looked at ~hostPlatform. I think Linux is the only supported output from hostPlatform so that doesn't seem to buy much generality.


settings = lib.mkOption {
inherit (keyValue) type;
Expand Down Expand Up @@ -78,7 +82,9 @@ in {
installBatSyntax =
lib.mkEnableOption "installation of Ghostty configuration syntax for bat"
// {
default = true;
default = cfg.package != null;
defaultText =
"Enabled by default when programs.ghostty.package is not null.";
anund marked this conversation as resolved.
Show resolved Hide resolved
};

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

config = lib.mkIf cfg.enable (lib.mkMerge [
{
home.packages = [ cfg.package ];
home.packages = lib.mkIf (cfg.package != null) [ cfg.package ];
anund marked this conversation as resolved.
Show resolved Hide resolved

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 =
"programs.ghostty.package does not have a vim output or is null.";
}];

programs.vim.plugins = lib.mkIf (cfg.package != null) [ cfg.package.vim ];
anund marked this conversation as resolved.
Show resolved Hide resolved
})

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

programs.bat = lib.mkIf (cfg.package != null) {
anund marked this conversation as resolved.
Show resolved Hide resolved
syntaxes.ghostty = {
src = cfg.package;
file = "share/bat/syntaxes/ghostty.sublime-syntax";
Expand Down
Loading