From 60ccfa9913e47016bd8cb25a19e7ac09887362a5 Mon Sep 17 00:00:00 2001 From: Anund Date: Wed, 8 Jan 2025 01:45:07 +1100 Subject: [PATCH] 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. --- modules/programs/ghostty.nix | 38 ++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/modules/programs/ghostty.nix b/modules/programs/ghostty.nix index 9ebaa7b30c0e..bbb1abc006a3 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 = + "On darwin set this to null to manage ghostty config while ghostty is not present in nixpkgs."; + }; settings = lib.mkOption { inherit (keyValue) type; @@ -78,7 +82,7 @@ in { installBatSyntax = lib.mkEnableOption "installation of Ghostty configuration syntax for bat" // { - default = true; + default = (cfg.package != null); }; enableBashIntegration = lib.mkEnableOption '' @@ -108,7 +112,7 @@ in { config = lib.mkIf cfg.enable (lib.mkMerge [ { - home.packages = [ cfg.package ]; + home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; programs.ghostty.settings = lib.mkIf cfg.clearDefaultKeybinds { keybind = lib.mkBefore [ "clear" ]; @@ -116,27 +120,45 @@ 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 = lib.elem "vim" cfg.package.outputs or [ ]; + message = "ghostty.package does not have a vim output or is null"; + }]; + + programs.vim.plugins = lib.mkIf (cfg.package != null) [ cfg.package.vim ]; }) (lib.mkIf cfg.installBatSyntax { - programs.bat = { + assertions = [{ + assertion = cfg.package != null; + message = "cannot install bat syntax while .package is null"; + }]; + + programs.bat = lib.mkIf (cfg.package != null) { syntaxes.ghostty = { src = cfg.package; file = "share/bat/syntaxes/ghostty.sublime-syntax";