diff --git a/modules/programs/kitty.nix b/modules/programs/kitty.nix index 3fa4452e6..df794860d 100644 --- a/modules/programs/kitty.nix +++ b/modules/programs/kitty.nix @@ -25,10 +25,26 @@ let mkKeyValue = key: command: "map ${key} ${command}"; }; + toKittyEnv = + generators.toKeyValue { mkKeyValue = name: value: "env ${name}=${value}"; }; + in { options.programs.kitty = { enable = mkEnableOption "Kitty terminal emulator"; + darwinLaunchOptions = mkOption { + type = types.nullOr (types.listOf types.str); + default = null; + description = "Command-line options to use when launched by Mac OS GUI"; + example = literalExample '' + [ + "--single-instance" + "--directory=/tmp/my-dir" + "--listen-on=unix:/tmp/my-socket" + ] + ''; + }; + settings = mkOption { type = types.attrsOf eitherStrBoolInt; default = { }; @@ -65,6 +81,17 @@ in { ''; }; + environment = mkOption { + type = types.attrsOf types.str; + default = { }; + description = "Environment variables to set or override."; + example = literalExample '' + { + "LS_COLORS" = "1"; + } + ''; + }; + extraConfig = mkOption { default = ""; type = types.lines; @@ -73,6 +100,14 @@ in { }; config = mkIf cfg.enable { + assertions = [{ + assertion = (cfg.darwinLaunchOptions != null) + -> pkgs.stdenv.hostPlatform.isDarwin; + message = '' + The 'programs.kitty.darwinLaunchOptions' option is only available on darwin. + ''; + }]; + home.packages = [ pkgs.kitty ] ++ optionalPackage cfg.font; xdg.configFile."kitty/kitty.conf".text = '' @@ -89,7 +124,14 @@ in { ${toKittyKeybindings cfg.keybindings} + ${toKittyEnv cfg.environment} + ${cfg.extraConfig} ''; + + xdg.configFile."kitty/macos-launch-services-cmdline" = + mkIf (cfg.darwinLaunchOptions != null) { + text = concatStringsSep " " cfg.darwinLaunchOptions; + }; }; } diff --git a/tests/modules/programs/kitty/example-macos-launch-services-cmdline b/tests/modules/programs/kitty/example-macos-launch-services-cmdline new file mode 100644 index 000000000..e104109ee --- /dev/null +++ b/tests/modules/programs/kitty/example-macos-launch-services-cmdline @@ -0,0 +1 @@ +--single-instance --directory=/tmp/my-dir --listen-on=unix:/tmp/my-socket \ No newline at end of file diff --git a/tests/modules/programs/kitty/example-settings-expected.conf b/tests/modules/programs/kitty/example-settings-expected.conf index 23cd3a85a..0afd7a9a0 100644 --- a/tests/modules/programs/kitty/example-settings-expected.conf +++ b/tests/modules/programs/kitty/example-settings-expected.conf @@ -14,4 +14,7 @@ map ctrl+c copy_or_interrupt map ctrl+f>2 set_font_size 20 +env LS_COLORS=1 + + diff --git a/tests/modules/programs/kitty/example-settings.nix b/tests/modules/programs/kitty/example-settings.nix index 8b5c0c330..1f3b82b98 100644 --- a/tests/modules/programs/kitty/example-settings.nix +++ b/tests/modules/programs/kitty/example-settings.nix @@ -6,6 +6,13 @@ with lib; config = { programs.kitty = { enable = true; + + darwinLaunchOptions = lib.mkIf pkgs.stdenv.hostPlatform.isDarwin [ + "--single-instance" + "--directory=/tmp/my-dir" + "--listen-on=unix:/tmp/my-socket" + ]; + settings = { scrollback_lines = 10000; enable_audio_bell = false; @@ -19,6 +26,8 @@ with lib; "ctrl+c" = "copy_or_interrupt"; "ctrl+f>2" = "set_font_size 20"; }; + + environment = { LS_COLORS = "1"; }; }; nixpkgs.overlays = @@ -29,6 +38,10 @@ with lib; assertFileContent \ home-files/.config/kitty/kitty.conf \ ${./example-settings-expected.conf} + '' + lib.optionalString pkgs.stdenv.hostPlatform.isDarwin '' + assertFileContent \ + home-files/.config/kitty/macos-launch-services-cmdline \ + ${./example-macos-launch-services-cmdline} ''; }; }