mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-09 03:56:04 +01:00
kitty: remove with lib
This commit is contained in:
parent
2d731a33b1
commit
c90cd85b04
1 changed files with 27 additions and 24 deletions
|
|
@ -1,29 +1,30 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
let
|
let
|
||||||
|
inherit (lib)
|
||||||
|
literalExpression mkEnableOption mkIf mkOption optionalString types;
|
||||||
|
|
||||||
cfg = config.programs.kitty;
|
cfg = config.programs.kitty;
|
||||||
|
|
||||||
settingsValueType = with types; oneOf [ str bool int float ];
|
settingsValueType = with types; oneOf [ str bool int float ];
|
||||||
|
|
||||||
optionalPackage = opt:
|
optionalPackage = opt:
|
||||||
optional (opt != null && opt.package != null) opt.package;
|
lib.optional (opt != null && opt.package != null) opt.package;
|
||||||
|
|
||||||
toKittyConfig = generators.toKeyValue {
|
toKittyConfig = lib.generators.toKeyValue {
|
||||||
mkKeyValue = key: value:
|
mkKeyValue = key: value:
|
||||||
let
|
let
|
||||||
value' =
|
value' =
|
||||||
(if isBool value then lib.hm.booleans.yesNo else toString) value;
|
(if lib.isBool value then lib.hm.booleans.yesNo else toString) value;
|
||||||
in "${key} ${value'}";
|
in "${key} ${value'}";
|
||||||
};
|
};
|
||||||
|
|
||||||
toKittyKeybindings = generators.toKeyValue {
|
toKittyKeybindings = lib.generators.toKeyValue {
|
||||||
mkKeyValue = key: command: "map ${key} ${command}";
|
mkKeyValue = key: command: "map ${key} ${command}";
|
||||||
};
|
};
|
||||||
|
|
||||||
toKittyEnv =
|
toKittyEnv = lib.generators.toKeyValue {
|
||||||
generators.toKeyValue { mkKeyValue = name: value: "env ${name}=${value}"; };
|
mkKeyValue = name: value: "env ${name}=${value}";
|
||||||
|
};
|
||||||
|
|
||||||
shellIntegrationInit = {
|
shellIntegrationInit = {
|
||||||
bash = ''
|
bash = ''
|
||||||
|
|
@ -50,28 +51,29 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
shellIntegrationDefaultOpt = {
|
shellIntegrationDefaultOpt = {
|
||||||
default = !(elem "disabled" (splitString " " cfg.shellIntegration.mode));
|
default =
|
||||||
|
!(lib.elem "disabled" (lib.splitString " " cfg.shellIntegration.mode));
|
||||||
defaultText = literalExpression ''
|
defaultText = literalExpression ''
|
||||||
!(elem "disabled" (splitString " " config.programs.kitty.shellIntegration.mode))
|
!(elem "disabled" (splitString " " config.programs.kitty.shellIntegration.mode))
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
in {
|
in {
|
||||||
imports = [
|
imports = [
|
||||||
(mkChangedOptionModule [ "programs" "kitty" "theme" ] [
|
(lib.mkChangedOptionModule [ "programs" "kitty" "theme" ] [
|
||||||
"programs"
|
"programs"
|
||||||
"kitty"
|
"kitty"
|
||||||
"themeFile"
|
"themeFile"
|
||||||
] (config:
|
] (config:
|
||||||
let value = getAttrFromPath [ "programs" "kitty" "theme" ] config;
|
let value = lib.getAttrFromPath [ "programs" "kitty" "theme" ] config;
|
||||||
in if value != null then
|
in if value != null then
|
||||||
(let
|
(let
|
||||||
matching = filter (x: x.name == value) (builtins.fromJSON
|
matching = lib.filter (x: x.name == value) (builtins.fromJSON
|
||||||
(builtins.readFile
|
(builtins.readFile
|
||||||
"${pkgs.kitty-themes}/share/kitty-themes/themes.json"));
|
"${pkgs.kitty-themes}/share/kitty-themes/themes.json"));
|
||||||
in throwIf (length matching == 0)
|
in lib.throwIf (lib.length matching == 0)
|
||||||
"kitty-themes does not contain a theme named ${value}"
|
"kitty-themes does not contain a theme named ${value}"
|
||||||
strings.removeSuffix ".conf"
|
lib.strings.removeSuffix ".conf"
|
||||||
(strings.removePrefix "themes/" (head matching).file))
|
(lib.strings.removePrefix "themes/" (lib.head matching).file))
|
||||||
else
|
else
|
||||||
null))
|
null))
|
||||||
];
|
];
|
||||||
|
|
@ -134,7 +136,7 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
font = mkOption {
|
font = mkOption {
|
||||||
type = types.nullOr hm.types.fontType;
|
type = types.nullOr lib.hm.types.fontType;
|
||||||
default = null;
|
default = null;
|
||||||
description = "The font to use.";
|
description = "The font to use.";
|
||||||
};
|
};
|
||||||
|
|
@ -169,9 +171,10 @@ in {
|
||||||
example = "no-cursor";
|
example = "no-cursor";
|
||||||
apply = o:
|
apply = o:
|
||||||
let
|
let
|
||||||
modes = splitString " " o;
|
modes = lib.splitString " " o;
|
||||||
filtered = filter (m: m != "no-rc") modes;
|
filtered = lib.filter (m: m != "no-rc") modes;
|
||||||
in concatStringsSep " " (concatLists [ [ "no-rc" ] filtered ]);
|
in lib.concatStringsSep " "
|
||||||
|
(lib.concatLists [ [ "no-rc" ] filtered ]);
|
||||||
description = ''
|
description = ''
|
||||||
Set the mode of the shell integration. This accepts the same options
|
Set the mode of the shell integration. This accepts the same options
|
||||||
as the `shell_integration` option of Kitty. Note that
|
as the `shell_integration` option of Kitty. Note that
|
||||||
|
|
@ -205,7 +208,7 @@ in {
|
||||||
text = ''
|
text = ''
|
||||||
# Generated by Home Manager.
|
# Generated by Home Manager.
|
||||||
# See https://sw.kovidgoyal.net/kitty/conf.html
|
# See https://sw.kovidgoyal.net/kitty/conf.html
|
||||||
'' + concatStringsSep "\n" [
|
'' + lib.concatStringsSep "\n" [
|
||||||
(optionalString (cfg.font != null) ''
|
(optionalString (cfg.font != null) ''
|
||||||
font_family ${cfg.font.name}
|
font_family ${cfg.font.name}
|
||||||
${optionalString (cfg.font.size != null)
|
${optionalString (cfg.font.size != null)
|
||||||
|
|
@ -224,7 +227,7 @@ in {
|
||||||
(toKittyEnv cfg.environment)
|
(toKittyEnv cfg.environment)
|
||||||
cfg.extraConfig
|
cfg.extraConfig
|
||||||
];
|
];
|
||||||
} // optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
|
} // lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
|
||||||
onChange = ''
|
onChange = ''
|
||||||
${pkgs.procps}/bin/pkill -USR1 -u $USER kitty || true
|
${pkgs.procps}/bin/pkill -USR1 -u $USER kitty || true
|
||||||
'';
|
'';
|
||||||
|
|
@ -233,7 +236,7 @@ in {
|
||||||
home.activation.checkKittyTheme = mkIf (cfg.themeFile != null) (let
|
home.activation.checkKittyTheme = mkIf (cfg.themeFile != null) (let
|
||||||
themePath =
|
themePath =
|
||||||
"${pkgs.kitty-themes}/share/kitty-themes/themes/${cfg.themeFile}.conf";
|
"${pkgs.kitty-themes}/share/kitty-themes/themes/${cfg.themeFile}.conf";
|
||||||
in hm.dag.entryBefore [ "writeBoundary" ] ''
|
in lib.hm.dag.entryBefore [ "writeBoundary" ] ''
|
||||||
if [[ ! -f "${themePath}" ]]; then
|
if [[ ! -f "${themePath}" ]]; then
|
||||||
errorEcho "kitty-themes does not contain the theme file ${themePath}!"
|
errorEcho "kitty-themes does not contain the theme file ${themePath}!"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
@ -242,7 +245,7 @@ in {
|
||||||
|
|
||||||
xdg.configFile."kitty/macos-launch-services-cmdline" = mkIf
|
xdg.configFile."kitty/macos-launch-services-cmdline" = mkIf
|
||||||
(cfg.darwinLaunchOptions != null && pkgs.stdenv.hostPlatform.isDarwin) {
|
(cfg.darwinLaunchOptions != null && pkgs.stdenv.hostPlatform.isDarwin) {
|
||||||
text = concatStringsSep " " cfg.darwinLaunchOptions;
|
text = lib.concatStringsSep " " cfg.darwinLaunchOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
programs.bash.initExtra =
|
programs.bash.initExtra =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue