From d71828a7dd0dc53cf3994e8737c84b4180cc6dfa Mon Sep 17 00:00:00 2001 From: anund Date: Wed, 29 Jan 2025 18:47:05 +0000 Subject: [PATCH] ghostty: allow darwin users to manager their config (#6300) * ghostty: allow darwin users to manager their config Currently nixpkgs does not contain a package defintion for ghostty compatible with Darwin. Darwin users may still want to use this module to manage their config or share config between systems. This carries over behaviour from the beta period where this same technique was used. see: https://github.com/clo4/ghostty-hm-module/blob/887e13a6e7acf5ffaab0119d96e476d84db90904/module.nix#L167-L173 Also improves validation to cover theme files. * ghostty: guard all package access with isLinux ghostty is currently marked as broken in nixpkgs. Darwin users still want to manage ghostty config via home-manager. Avoiding installing the package and any extra files that depend on the package outside Linux allows this. * ghostty: allow nullable --- modules/programs/ghostty.nix | 41 +++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/modules/programs/ghostty.nix b/modules/programs/ghostty.nix index 06b138c61..5f820da75 100644 --- a/modules/programs/ghostty.nix +++ b/modules/programs/ghostty.nix @@ -13,7 +13,11 @@ in { options.programs.ghostty = { enable = lib.mkEnableOption "Ghostty"; - package = lib.mkPackageOption pkgs "ghostty" { }; + package = lib.mkPackageOption pkgs "ghostty" { + nullable = true; + extraDescription = + "Set programs.ghostty.package to null on platfroms where ghostty is not available or marked broken"; + }; settings = lib.mkOption { inherit (keyValue) type; @@ -82,7 +86,9 @@ in { installBatSyntax = lib.mkEnableOption "installation of Ghostty configuration syntax for bat" // { - default = true; + default = cfg.package != null; + defaultText = + lib.literalMD "`true` if programs.ghostty.package is not null"; }; enableBashIntegration = lib.mkEnableOption '' @@ -112,7 +118,7 @@ in { config = lib.mkIf cfg.enable (lib.mkMerge [ { - home.packages = [ cfg.package ]; + home.packages = lib.optionals (cfg.package != null) [ cfg.package ]; programs.ghostty.settings = lib.mkIf cfg.clearDefaultKeybinds { keybind = lib.mkBefore [ "clear" ]; @@ -120,27 +126,46 @@ in { # MacOS also supports XDG configuration directory, so we use it for both # Linux and macOS to reduce complexity - xdg.configFile = lib.mkMerge [ + xdg.configFile = let + validate = file: + lib.mkIf (cfg.package != null) "${ + lib.getExe cfg.package + } +validate-config --config-file=${config.xdg.configHome}/ghostty/${file}"; + in lib.mkMerge [ { "ghostty/config" = lib.mkIf (cfg.settings != { }) { source = keyValue.generate "ghostty-config" cfg.settings; - onChange = "${lib.getExe cfg.package} +validate-config"; + onChange = validate "config"; }; } (lib.mkIf (cfg.themes != { }) (lib.mapAttrs' (name: value: { name = "ghostty/themes/${name}"; - value.source = keyValue.generate "ghostty-${name}-theme" value; + value = { + source = keyValue.generate "ghostty-${name}-theme" value; + onChange = validate "themes/${name}"; + }; }) cfg.themes)) ]; } (lib.mkIf cfg.installVimSyntax { - programs.vim.plugins = [ cfg.package.vim ]; + assertions = [{ + assertion = cfg.installVimSyntax -> cfg.package != null; + message = + "programs.ghostty.installVimSyntax cannot be enabled when programs.ghostty.package is null"; + }]; + programs.vim.plugins = + lib.optionals (cfg.package != null) [ cfg.package.vim ]; }) (lib.mkIf cfg.installBatSyntax { - programs.bat = { + assertions = [{ + assertion = cfg.installBatSyntax -> cfg.package != null; + message = + "programs.ghostty.installBatSyntax cannot be enabled when programs.ghostty.package is null"; + }]; + programs.bat = lib.mkIf (cfg.package != null) { syntaxes.ghostty = { src = cfg.package; file = "share/bat/syntaxes/ghostty.sublime-syntax";