Kitty term emulator: how to specify custom config?

Hi all,

I’m trying out the kitty terminal emulator. I’m wondering how best to specify the config file. I’m not looking for a solution that e.g. populates $HOME with dotfiles. I’m not looking for ways to have a Nix-y config either, just a way to specify the config file.

I care mostly about macOS, and I’d like the solution to work with the application bundle (kitty.app) which I start via Spotlight.

Here’s my best attempt so far (requires nixpkgs#311655):

{ kitty, makeWrapper, lib }:


kitty.overrideAttrs (oldAttrs: {
  installPhase =
    let
      oldWrapPrograms = lib.filter (lib.hasPrefix "wrapProgram") (lib.splitString "\n" oldAttrs.installPhase);
      oldWrapProgram = (lib.elemAt oldWrapPrograms 0);
      newWrapProgram = "${oldWrapProgram} --add-flags '--config ${./kitty.conf}'";
    in
    lib.replaceStrings [oldWrapProgram] [newWrapProgram] oldAttrs.installPhase;
})

This basically hijacks the wrapProgram call in the installPhase to add a --config argument to the executable. This has two major drawbacks: (1) any config change requires a kitty rebuild and (2) it’s very brittle because it relies on specific behavior in the installPhase.

Did I miss an obvious way of doing this without modifying the kitty package in nixpkgs? Wrapping the derivation with symlinkJoin and doing another wrapProgram doesn’t work (wrapProgram doesn’t seem to like being wrapped again) and e.g. updating the Info.plist to add environment variables (KITTY_CONFIG_DIRECTORY) with defaults does not seem to work reliably (macOS doesn’t pick it up).

Suggestions welcome!

have you checked its home-manager options? i’m seeing:

  • programs.kitty.darwinLaunchOptions
  • programs.kitty.extraConfig

hopefully those can help you achieve what you’d like :slight_smile:

1 Like

Thanks! I’ll admit I’m not familiar with home-manager.

Looking at the kitty-related files, it looks like it might be writing a conf file:

xdg.configFile."kitty/kitty.conf" = {
      text = ''
        # Generated by Home Manager.
        # See https://sw.kovidgoyal.net/kitty/conf.html
      '' + ...
};

(source)

Which is what I was trying to avoid as I wanted to keep everything in the store! Maybe I’ll give home-manager a try but it seemed a bit overkill for my needs

home-manager does do things in a nixy way, so the files will be in the store - it’d just make sym-links in places that applications tend to look in by default so you don’t need to manually tell them to look elsewhere.
it should be possible to have nix let you specify symlinks as well, tho i use a home-manager option for that as well (attribute-set home.file).
i’ll admit i cannot judge your use-case, but for what it’s worth, to explain my own considerations, loading that lib is essentially a few extra lines to get a sleuth of extra configuration options.
i guess there’s also nix-darwin tho i’m not as familiar with it.

On NixOS, I’ve just been using the system-wide XDG config directory, like this:

environment.etc."xdg/kitty/kitty.conf".source = ./kitty.conf;

Maybe that works on macOS as well?