diff --git a/modules/misc/news/2025/11/2025-11-03_22-56-50.nix b/modules/misc/news/2025/11/2025-11-03_22-56-50.nix new file mode 100644 index 000000000..d78de2292 --- /dev/null +++ b/modules/misc/news/2025/11/2025-11-03_22-56-50.nix @@ -0,0 +1,14 @@ +{ config, pkgs, ... }: +{ + time = "2025-11-03T21:56:50+00:00"; + condition = config.programs.ghostty.enable && pkgs.stdenv.hostPlatform.isLinux; + message = '' + Ghostty: now enables the user systemd service by default. + + Running Ghostty via these systemd units is the recommended way to run + Ghostty. The two most important benefits provided by Ghostty's systemd + integrations are: instantaneous launching and centralized logging. + + See https://ghostty.org/docs/linux/systemd for all details + ''; +} diff --git a/modules/programs/ghostty.nix b/modules/programs/ghostty.nix index 43f3d99fe..38cfadf1a 100644 --- a/modules/programs/ghostty.nix +++ b/modules/programs/ghostty.nix @@ -114,6 +114,24 @@ in defaultText = lib.literalMD "`true` if programs.ghostty.package is not null"; }; + systemd = lib.mkOption { + type = lib.types.submodule { + options = { + enable = lib.mkEnableOption "the Ghostty systemd user service" // { + default = pkgs.stdenv.hostPlatform.isLinux; + defaultText = lib.literalMD "`true` on Linux, `false` otherwise"; + }; + }; + }; + default = { }; + description = '' + Configuration for Ghostty's systemd integration. + This enables additional speed and features. + + See for more information. + ''; + }; + enableBashIntegration = mkShellIntegrationOption ( lib.hm.shell.mkBashIntegrationOption { inherit config; } ); @@ -195,6 +213,22 @@ in }; }) + (lib.mkIf cfg.systemd.enable { + assertions = [ + { + assertion = cfg.systemd.enable -> cfg.package != null; + message = "programs.ghostty.systemd.enable cannot be true when programs.ghostty.package is null"; + } + { + assertion = cfg.systemd.enable -> pkgs.stdenv.hostPlatform.isLinux; + message = "Ghostty systemd integration cannot be enabled for non-linux platforms"; + } + ]; + xdg.configFile."systemd/user/app-com.mitchellh.ghostty.service".source = + "${cfg.package}/share/systemd/user/app-com.mitchellh.ghostty.service"; + dbus.packages = [ cfg.package ]; + }) + (lib.mkIf cfg.enableBashIntegration { # Make order 101 to be placed exactly after bash completions, as Ghostty # documentation suggests sourcing the script as soon as possible diff --git a/tests/modules/programs/ghostty/empty-settings.nix b/tests/modules/programs/ghostty/empty-settings.nix index 1ea025eb5..d74972a4a 100644 --- a/tests/modules/programs/ghostty/empty-settings.nix +++ b/tests/modules/programs/ghostty/empty-settings.nix @@ -1,5 +1,9 @@ +{ config, ... }: { - programs.ghostty.enable = true; + programs.ghostty = { + enable = true; + package = config.lib.test.mkStubPackage { outPath = null; }; + }; nmt.script = '' assertPathNotExists home-files/.config/ghostty/config diff --git a/tests/modules/programs/ghostty/example-settings.nix b/tests/modules/programs/ghostty/example-settings.nix index 18b64b4fe..b45094d2f 100644 --- a/tests/modules/programs/ghostty/example-settings.nix +++ b/tests/modules/programs/ghostty/example-settings.nix @@ -2,7 +2,7 @@ { programs.ghostty = { enable = true; - package = config.lib.test.mkStubPackage { }; + package = config.lib.test.mkStubPackage { outPath = null; }; settings = { theme = "catppuccin-mocha"; diff --git a/tests/modules/programs/ghostty/example-theme.nix b/tests/modules/programs/ghostty/example-theme.nix index 29f40a897..320b073a1 100644 --- a/tests/modules/programs/ghostty/example-theme.nix +++ b/tests/modules/programs/ghostty/example-theme.nix @@ -1,6 +1,8 @@ +{ config, ... }: { programs.ghostty = { enable = true; + package = config.lib.test.mkStubPackage { outPath = null; }; themes = { catppuccin-mocha = {