From 85cf1d92caa0a503b6d9b20a5ee27b4f9ec0b421 Mon Sep 17 00:00:00 2001 From: Jelle Spreeuwenberg Date: Mon, 27 Apr 2026 23:15:08 +0200 Subject: [PATCH] feat: make kitty boot in single instance mode --- modules/capabilities/terminal.nix | 39 ++++++++++++++++++++++++--- modules/profiles/workstation-base.nix | 4 +-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/modules/capabilities/terminal.nix b/modules/capabilities/terminal.nix index 83d97fb..947f6e3 100644 --- a/modules/capabilities/terminal.nix +++ b/modules/capabilities/terminal.nix @@ -1,7 +1,24 @@ -{ config, ... }: +{ lib, config, ... }: let repo = config.repo; + kittySingleInstance = + pkgs: + pkgs.symlinkJoin { + name = "kitty-single"; + paths = [ pkgs.kitty ]; + meta = pkgs.kitty.meta; + buildInputs = [ pkgs.makeWrapper ]; + postBuild = '' + # Wrap the binary to always launch as a single instance + wrapProgram $out/bin/kitty --add-flags "-1" + + # Patch the .desktop file for strict app launchers like Vicinae + rm $out/share/applications/kitty.desktop + sed 's/Exec=kitty/Exec=kitty -1/g' ${pkgs.kitty}/share/applications/kitty.desktop > $out/share/applications/kitty.desktop + ''; + }; + mkTerminal = { desktopEntryName, @@ -103,7 +120,7 @@ in { programs.kitty = { enable = true; - package = pkgs.kitty; + package = kittySingleInstance pkgs; font = { name = "JetBrains Mono"; size = 11; @@ -156,6 +173,22 @@ in color17 ${palette.terminal.color17} ''; }; + systemd.user.services.kitty-daemon = { + Unit = { + Description = "Kitty Terminal Daemon"; + PartOf = [ "graphical-session.target" ]; + After = [ "graphical-session.target" ]; + }; + Install = { + WantedBy = [ "graphical-session.target" ]; + }; + Service = { + # Use the wrapped package (which already includes -1) + # Start it hidden and run an infinite dummy process so the instance stays alive + ExecStart = "${lib.getExe (kittySingleInstance pkgs)} --start-as=hidden ${pkgs.coreutils}/bin/tail -f /dev/null"; + Restart = "on-failure"; + }; + }; }; flake.modules.homeManager.primary-terminal-foot = mkTerminal { @@ -166,7 +199,7 @@ in flake.modules.homeManager.primary-terminal-kitty = mkTerminal { desktopEntryName = "kitty"; - packageFor = pkgs: pkgs.kitty; + packageFor = pkgs: kittySingleInstance pkgs; terminalModule = config.flake.modules.homeManager.terminal-kitty; }; } diff --git a/modules/profiles/workstation-base.nix b/modules/profiles/workstation-base.nix index 6808b29..8ba689f 100644 --- a/modules/profiles/workstation-base.nix +++ b/modules/profiles/workstation-base.nix @@ -54,8 +54,8 @@ in homeModules.sops homeModules.git homeModules.ssh-client - homeModules.primary-terminal-foot - homeModules.terminal-kitty + homeModules.primary-terminal-kitty + homeModules.terminal-foot homeModules.theme homeModules.vicinae homeModules.noctalia