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: add module #6235

Merged
merged 1 commit into from
Jan 1, 2025
Merged

ghostty: add module #6235

merged 1 commit into from
Jan 1, 2025

Conversation

HeitorAugustoLN
Copy link
Member

@HeitorAugustoLN HeitorAugustoLN commented Dec 26, 2024

Description

Adds a module for ghostty terminal emulator, depends on NixOS/nixpkgs#368404
Closes #6236

Checklist

  • Change is backwards compatible.

  • Code formatted with ./format.

  • Code tested through nix-shell --pure tests -A run.all or nix develop --ignore-environment .#all using Flakes.

  • Test cases updated/added. See example.

  • Commit messages are formatted like

    {component}: {description}
    
    {long description}
    

    See CONTRIBUTING for more information and recent commit messages for examples.

  • If this PR adds a new module

    • Added myself as module maintainer. See example.

Maintainer CC

@HeitorAugustoLN HeitorAugustoLN marked this pull request as draft December 26, 2024 22:38
@HeitorAugustoLN HeitorAugustoLN force-pushed the ghostty branch 3 times, most recently from 2dd68b0 to ed3ecd5 Compare December 26, 2024 23:02
@anund
Copy link
Contributor

anund commented Dec 27, 2024

You could also look at module options adding the vim/bat plugins that ship with ghostty. In $out/share there are several external application integrations, I think only vim and bat require user intervention to configure.

https://github.com/clo4/ghostty-hm-module @clo4 might have additional insight to share

@anund
Copy link
Contributor

anund commented Dec 27, 2024

  programs.bat = {
    syntaxes = {
      ghostty = {
        src = ghostty;
        file = "share/bat/syntaxes/ghostty.sublime-syntax";
      };
    };
    config = {
      map-syntax = [ "*/ghostty/config:Ghostty Config" ];
      # or more explicit
      # map-syntax = [ "${config.xdg.configHome}/ghostty/config:Ghostty Config" ];
    };
  };

  programs.vim.plugins = [
    ghostty.vim
  ]; 

@HeitorAugustoLN
Copy link
Member Author

You could also look at module options adding the vim/bat plugins that ship with ghostty. In $out/share there are several
external application integrations, I think only vim and bat require user intervention to configure.

https://github.com/clo4/ghostty-hm-module @clo4 might have additional insight to share

Didn't knew this was a thing, I will look into it.

@HeitorAugustoLN HeitorAugustoLN force-pushed the ghostty branch 3 times, most recently from e69e746 to 6cfb651 Compare December 27, 2024 01:30
@arunoruto
Copy link

Maybe I am missing something, but I am not sure how to add keybindings using the config...
I thought it should be set as an array, but I get an error that it should be of type atom (null, bool, int, float or string). Maybe an additional setting for keybindings could be implemented? The format could be a set with "shortcut" = "action" and it get squished down into a string keybind = shortcut=action.

@HeitorAugustoLN
Copy link
Member Author

HeitorAugustoLN commented Dec 27, 2024

Maybe I am missing something, but I am not sure how to add keybindings using the config... I thought it should be set as an array, but I get an error that it should be of type atom (null, bool, int, float or string). Maybe an additional setting for keybindings could be implemented? The format could be a set with "shortcut" = "action" and it get squished down into a string keybind = shortcut=action.

{
  programs.ghostty.settings = {
    keybind = [
      "clear"
      "ctrl+h=goto_split:left"
      "ctrl+l=goto_split:right"
      # etc.
    ];
  };
}
If this doesn't work for you right now, maybe you should update the input.

I wouldn't really like to create an option solely for keybindings, because I don't think it is really needed. My only concern is the keybind = clear, since I don't know if it's position matters on the configuration file or not. But if it does maybe I will need to create a separate option for that.

@anund
Copy link
Contributor

anund commented Dec 27, 2024

ghostty-org/ghostty#3203 has a good summary explanation for the config format.

@arunoruto
Copy link

Maybe I am missing something, but I am not sure how to add keybindings using the config... I thought it should be set as an array, but I get an error that it should be of type atom (null, bool, int, float or string). Maybe an additional setting for keybindings could be implemented? The format could be a set with "shortcut" = "action" and it get squished down into a string keybind = shortcut=action.

{
  programs.ghostty.settings = {
    keybind = [
      "clear"
      "ctrl+h=goto_split:left"
      "ctrl+l=goto_split:right"
      # etc.
    ];
  };
}
If this doesn't work for you right now, maybe you should update the input.

I wouldn't really like to create an option solely for keybindings, because I don't think it is really needed. My only concern is the keybind = clear, since I don't know if it's position matters on the configuration file or not. But if it does maybe I will need to create a separate option for that.

Fair enough, I just came up at the same solution! Thanks tho!

@HeitorAugustoLN
Copy link
Member Author

Added a option for prepending keybind = clear before settings so it doesn't reset some custom keybinds

@zoedsoupe
Copy link

wow! i was starting to implement this module! awesome!

now question i have is: I don't know how home-manager aims to tackle this or if there's a standard, but some module have extensive nix options representing actual settings items and others have a generic 'settings' option that receive a raw string while others have a mix of 'native' options in addition to the extraConfig option.

based in the standard (or not), does it make sense to try to implement native options in nix for the Ghostty settings? I could tackle this in another pr if this is the case. wdyt?

@HeitorAugustoLN
Copy link
Member Author

now question i have is: I don't know how home-manager aims to tackle this or if there's a standard, but some module have extensive nix options representing actual settings items and others have a generic 'settings' option that receive a raw string while others have a mix of 'native' options in addition to the extraConfig option.

There is a standard: RFC 0042, which is what I’m following for this PR. But yeah, not all modules implement it.

Based on the standard (or not), does it make sense to try and implement native options in Nix for Ghostty’s settings? If it does, I could take this on in another PR. What do you think?

Technically, I could create a submodule to map out all the Ghostty options and then add a freeformType for anything not covered. But honestly, that feels super counterintuitive. It would take a ton of time and still end up with the same result. Plus, over time, as Ghostty adds more options (and it already has a ton), it’ll just get harder to maintain. Check out the motivation section in the RFC.

That said, there are cases where mapping options is worth it, like if the upstream project doesn’t have proper documentation for their settings. But that’s not the case with Ghostty, they’ve got a solid configuration reference

@samhh samhh mentioned this pull request Dec 27, 2024
modules/programs/ghostty.nix Outdated Show resolved Hide resolved
@arunoruto
Copy link

I got feedback on my PR for adding ghostty to stylix. One question was if there was a way to configure custom themes using the HM module. AFAIK the theme can only be set, but not provided. Are there any plans on adding this feature in this PR, or should I open up a new one when this one gets merged?

@HeitorAugustoLN
Copy link
Member Author

I got feedback on my PR for adding ghostty to stylix. One question was if there was a way to configure custom themes using the HM module. AFAIK the theme can only be set, but not provided. Are there any plans on adding this feature in this PR, or should I open up a new one when this one gets merged?

I will add an option to add themes

@HeitorAugustoLN
Copy link
Member Author

@arunoruto added themes option

Copy link
Member

@rycee rycee left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! Looks good in general, I've just added a few minor comments.

modules/programs/ghostty.nix Show resolved Hide resolved
modules/programs/ghostty.nix Outdated Show resolved Hide resolved
modules/programs/ghostty.nix Outdated Show resolved Hide resolved
modules/programs/ghostty.nix Outdated Show resolved Hide resolved
tests/modules/programs/ghostty/empty-settings.nix Outdated Show resolved Hide resolved
modules/programs/ghostty.nix Outdated Show resolved Hide resolved
modules/programs/ghostty.nix Outdated Show resolved Hide resolved
modules/programs/ghostty.nix Show resolved Hide resolved
modules/programs/ghostty.nix Outdated Show resolved Hide resolved
@anund
Copy link
Contributor

anund commented Dec 28, 2024

May want to add an option for an ssh terminfo work around. Named to indicate it's a work around. See https://ghostty.org/docs/help/terminfo#ssh (there could be better ways to address this)

  programs.ssh = {
    matchBlocks = {
      "*" = {
        extraOptions = {
          SetEnv = "TERM=xterm-256color";
        };
      };
    };
  };    

@anund
Copy link
Contributor

anund commented Dec 28, 2024

Could also include shell-integration flags following the manual integration steps here: https://ghostty.org/docs/help/terminfo#ssh. Similar to kitty, though I don't think you need the extra mangling they to to set no-rc.

@arunoruto
Copy link

Ghostty just got merged into nixos-unstable. I wanted to ask what needs to be done, to change the draft status and marge it :)

@HeitorAugustoLN HeitorAugustoLN force-pushed the ghostty branch 2 times, most recently from 4c49e96 to 2a80e8a Compare December 30, 2024 21:47
@HeitorAugustoLN
Copy link
Member Author

HeitorAugustoLN commented Dec 30, 2024

Some updates:

  • I decided to drop the installVimSyntax option since the package already takes care of it.
  • Added optional shell integration options

@HeitorAugustoLN
Copy link
Member Author

HeitorAugustoLN commented Dec 30, 2024

I wanted to ask what needs to be done, to change the draft status and marge it :)

I would like to mark it as ready after flake.lock gets updated, #6240 updates it, but still in a older version of nixos-unstable.

@surfaceflinger
Copy link
Contributor

I think rycee or someone could manually trigger the flake update workflow, otherwise you'll have to wait until Wednesday and then for a merge

@anund
Copy link
Contributor

anund commented Dec 31, 2024

For the vim syntax: adding programs.vim.plugins = [ ghostty.vim ]; is required by users. nixpkgs/home-manager vim modules will not automatically add the plugin. Just to confuse things: Neovim will.

@HeitorAugustoLN
Copy link
Member Author

For the vim syntax: adding programs.vim.plugins = [ ghostty.vim ]; is required by users. nixpkgs/home-manager vim modules will not automatically add the plugin. Just to confuse things: Neovim will.

I completely forgot that vim handles things differently, re-added the option exclusively for vim

modules/programs/ghostty.nix Outdated Show resolved Hide resolved
@rycee rycee merged commit 5f6aa26 into nix-community:master Jan 1, 2025
3 checks passed
@rycee
Copy link
Member

rycee commented Jan 1, 2025

Thanks! Merged to master now 🙂

@HeitorAugustoLN HeitorAugustoLN deleted the ghostty branch January 1, 2025 23:57
@nyabinary
Copy link

Does this have nushell integration?

@arunoruto
Copy link

Does this have nushell integration?

Ghostty does not provide a nushell integration according to their docs

@anund
Copy link
Contributor

anund commented Jan 2, 2025

Not currently no. See https://github.com/ghostty-org/ghostty/tree/main/src/shell-integration and perhaps https://github.com/ghostty-org/ghostty/pull/1772/files / https://github.com/ghostty-org/ghostty/pull/1774/files as a sketch pr for adding a new shell. (elvish was added later as a couple changes)

@HeitorAugustoLN
Copy link
Member Author

Does this have nushell integration?

Some shells such as Nushell have built-in support for some of the features that Ghostty provides, so shell integration is not necessary.

This is what they have in their documentation

@NeQuissimus
Copy link

This module does break when bat is enabled. It looks like the syntax files are not as expected by that module.

@HeitorAugustoLN
Copy link
Member Author

This module does break when bat is enabled. It looks like the syntax files are not as expected by that module.

Could you provide the error for me? I have bat enabled in my configuration, and it didn't fail to build, last time I updated my configuration

@NeQuissimus
Copy link

Starting Home Manager activation
Activating checkFilesChanged
Activating checkLaunchAgents
Activating checkLinkTargets
Activating writeBoundary
Activating linkGeneration
Cleaning up orphan links from /Users/nequi
Creating profile generation 85
Creating home file links in /Users/nequi
Activating batCache
No themes were found in '/Users/nequi/.config/bat/themes', using the default set
[bat error]: error finding all the files in a directory: IO error for operation on /Users/nequi/.config/ba
t/syntaxes/ghostty.sublime-syntax: No such file or directory (os error 2)

Relevant configs:

  programs = {
    bat.enable = true;

    ghostty = {
      enable = true;
      enableZshIntegration = true;

      settings = {
        auto-update = "off";
        background-opacity = 0.8;
        confirm-close-surface = false;
        font-family = "FiraCode Nerd Font Mono";
        font-size = 12;
        theme = "Teerb";
      };
    };
};

@HeitorAugustoLN
Copy link
Member Author

I see you are on macOS, so my guess is that the bat syntax file is not available in the darwin package for some reason, and looks like the package got marked again as broken on darwin

@getchoo getchoo mentioned this pull request Jan 8, 2025
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Program request: Ghostty