Files
lux/modules/capabilities/terminal.nix
T
2026-04-29 12:26:38 +02:00

209 lines
6.7 KiB
Nix

{ 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,
packageFor,
terminalModule,
}:
{ config, pkgs, ... }:
let
package = packageFor pkgs;
in
{
imports = [ terminalModule ];
config = {
meta.desktop.terminal = {
inherit desktopEntryName package;
};
xdg.terminal-exec = {
enable = true;
settings.default = [ config.meta.desktop.terminal.desktopId ];
};
};
};
in
{
flake.modules.homeManager.terminal-foot =
{
lib,
pkgs,
...
}:
let
repoTheme = repo.theme.kanagawa;
palette = repoTheme.palette;
hex = lib.removePrefix "#";
in
{
programs.foot = {
enable = true;
package = pkgs.foot;
settings = {
main = {
font = "JetBrains Mono:style=Medium:size=11:fontfeatures=-liga:fontfeatures=-calt";
font-bold = "JetBrains Mono:style=Bold:size=11:fontfeatures=-liga:fontfeatures=-calt";
font-italic = "JetBrains Mono:style=Medium Italic:size=11:fontfeatures=-liga:fontfeatures=-calt";
font-bold-italic = "JetBrains Mono:style=Bold Italic:size=11:fontfeatures=-liga:fontfeatures=-calt";
gamma-correct-blending = "yes";
pad = "3x3";
# vertical-letter-offset = -1;
# letter-spacing = -0.2;
};
tweak.box-drawing-base-thickness = 0.1;
bell.system = "no";
scrollback.lines = 10000;
text-bindings."\\x0a" = "Shift+Return Shift+KP_Enter";
colors-dark = {
background = hex palette.background;
foreground = hex palette.foreground;
selection-background = hex palette.selectionBackground;
selection-foreground = hex palette.selectionForeground;
urls = hex palette.url;
cursor = "${hex palette.background} ${hex palette.cursor}";
regular0 = hex palette.terminal.color0;
regular1 = hex palette.terminal.color1;
regular2 = hex palette.terminal.color2;
regular3 = hex palette.terminal.color3;
regular4 = hex palette.terminal.color4;
regular5 = hex palette.terminal.color5;
regular6 = hex palette.terminal.color6;
regular7 = hex palette.terminal.color7;
bright0 = hex palette.terminal.color8;
bright1 = hex palette.terminal.color9;
bright2 = hex palette.terminal.color10;
bright3 = hex palette.terminal.color11;
bright4 = hex palette.terminal.color12;
bright5 = hex palette.terminal.color13;
bright6 = hex palette.terminal.color14;
bright7 = hex palette.terminal.color15;
"16" = hex palette.terminal.color16;
"17" = hex palette.terminal.color17;
};
};
};
};
flake.modules.homeManager.terminal-kitty =
{ pkgs, ... }:
let
repoTheme = repo.theme.kanagawa;
palette = repoTheme.palette;
in
{
programs.kitty = {
enable = true;
package = kittySingleInstance pkgs;
font = {
name = "JetBrains Mono";
size = 11;
};
settings = {
disable_ligatures = "always";
scrollback_lines = 10000;
enable_audio_bell = false;
confirm_os_window_close = 0;
window_padding_width = 3;
update_check_interval = 0;
};
keybindings."shift+enter" = "send_text all \\x0a";
extraConfig = ''
## name: ${repoTheme.displayName}
## license: MIT
## author: Tommaso Laurenzi
## upstream: https://github.com/rebelot/kanagawa.nvim/
background ${palette.background}
foreground ${palette.foreground}
selection_background ${palette.selectionBackground}
selection_foreground ${palette.selectionForeground}
url_color ${palette.url}
cursor ${palette.cursor}
active_tab_background ${palette.background}
active_tab_foreground ${palette.selectionForeground}
inactive_tab_background ${palette.background}
inactive_tab_foreground ${palette.muted}
color0 ${palette.terminal.color0}
color1 ${palette.terminal.color1}
color2 ${palette.terminal.color2}
color3 ${palette.terminal.color3}
color4 ${palette.terminal.color4}
color5 ${palette.terminal.color5}
color6 ${palette.terminal.color6}
color7 ${palette.terminal.color7}
color8 ${palette.terminal.color8}
color9 ${palette.terminal.color9}
color10 ${palette.terminal.color10}
color11 ${palette.terminal.color11}
color12 ${palette.terminal.color12}
color13 ${palette.terminal.color13}
color14 ${palette.terminal.color14}
color15 ${palette.terminal.color15}
color16 ${palette.terminal.color16}
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 {
desktopEntryName = "foot";
packageFor = pkgs: pkgs.foot;
terminalModule = config.flake.modules.homeManager.terminal-foot;
};
flake.modules.homeManager.primary-terminal-kitty = mkTerminal {
desktopEntryName = "kitty";
packageFor = pkgs: kittySingleInstance pkgs;
terminalModule = config.flake.modules.homeManager.terminal-kitty;
};
}