mirror of
https://github.com/nix-community/home-manager
synced 2024-11-10 21:29:48 +01:00
kitty: remove IFD
With this change the theme check happens at activation time. An integration test is also added to verify the functionality. Fixes #5110
This commit is contained in:
parent
2cf3abce03
commit
ecaed80b18
8 changed files with 185 additions and 27 deletions
|
@ -1,9 +1,6 @@
|
|||
{ config, lib, options, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
|
||||
cfg = config.news;
|
||||
|
||||
hostPlatform = pkgs.stdenv.hostPlatform;
|
||||
|
@ -44,7 +41,6 @@ let
|
|||
|
||||
config = { id = mkDefault (builtins.hashString "sha256" config.message); };
|
||||
});
|
||||
|
||||
in {
|
||||
meta.maintainers = [ maintainers.rycee ];
|
||||
|
||||
|
@ -1724,6 +1720,20 @@ in {
|
|||
editor).
|
||||
'';
|
||||
}
|
||||
|
||||
{
|
||||
time = "2024-09-20T07:00:11+00:00";
|
||||
condition = config.programs.kitty.theme != null;
|
||||
message = ''
|
||||
The option 'programs.kitty.theme' has been deprecated, please use
|
||||
'programs.kitty.themeFile' instead.
|
||||
|
||||
The 'programs.kitty.themeFile' option expects the file name of a
|
||||
theme from `kitty-themes`, without the `.conf` suffix. See
|
||||
<https://github.com/kovidgoyal/kitty-themes/tree/master/themes> for a
|
||||
list of themes.
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
with lib;
|
||||
|
||||
let
|
||||
|
||||
cfg = config.programs.kitty;
|
||||
|
||||
eitherStrBoolInt = with types; either str (either bool int);
|
||||
|
@ -57,6 +56,26 @@ let
|
|||
'';
|
||||
};
|
||||
in {
|
||||
imports = [
|
||||
(mkChangedOptionModule [ "programs" "kitty" "theme" ] [
|
||||
"programs"
|
||||
"kitty"
|
||||
"themeFile"
|
||||
] (config:
|
||||
let value = getAttrFromPath [ "programs" "kitty" "theme" ] config;
|
||||
in if value != null then
|
||||
(let
|
||||
matching = filter (x: x.name == value) (builtins.fromJSON
|
||||
(builtins.readFile
|
||||
"${pkgs.kitty-themes}/share/kitty-themes/themes.json"));
|
||||
in throwIf (length matching == 0)
|
||||
"kitty-themes does not contain a theme named ${value}"
|
||||
strings.removeSuffix ".conf"
|
||||
(strings.removePrefix "themes/" (head matching).file))
|
||||
else
|
||||
null))
|
||||
];
|
||||
|
||||
options.programs.kitty = {
|
||||
enable = mkEnableOption "Kitty terminal emulator";
|
||||
|
||||
|
@ -100,16 +119,16 @@ in {
|
|||
'';
|
||||
};
|
||||
|
||||
theme = mkOption {
|
||||
themeFile = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Apply a Kitty color theme. This option takes the friendly name of
|
||||
any theme given by the command {command}`kitty +kitten themes`.
|
||||
See <https://github.com/kovidgoyal/kitty-themes>
|
||||
for more details.
|
||||
Apply a Kitty color theme. This option takes the file name of a theme
|
||||
in `kitty-themes`, without the `.conf` suffix. See
|
||||
<https://github.com/kovidgoyal/kitty-themes/tree/master/themes> for a
|
||||
list of themes.
|
||||
'';
|
||||
example = "Space Gray Eighties";
|
||||
example = "SpaceGray_Eighties";
|
||||
};
|
||||
|
||||
font = mkOption {
|
||||
|
@ -146,11 +165,11 @@ in {
|
|||
type = types.str;
|
||||
default = "no-rc";
|
||||
example = "no-cursor";
|
||||
apply = (o:
|
||||
apply = o:
|
||||
let
|
||||
modes = splitString " " o;
|
||||
filtered = filter (m: m != "no-rc") modes;
|
||||
in concatStringsSep " " (concatLists [ [ "no-rc" ] filtered ]));
|
||||
in concatStringsSep " " (concatLists [ [ "no-rc" ] filtered ]);
|
||||
description = ''
|
||||
Set the mode of the shell integration. This accepts the same options
|
||||
as the `shell_integration` option of Kitty. Note that
|
||||
|
@ -184,24 +203,15 @@ in {
|
|||
text = ''
|
||||
# Generated by Home Manager.
|
||||
# See https://sw.kovidgoyal.net/kitty/conf.html
|
||||
'' + concatStringsSep "\n" ([
|
||||
|
||||
'' + concatStringsSep "\n" [
|
||||
(optionalString (cfg.font != null) ''
|
||||
font_family ${cfg.font.name}
|
||||
${optionalString (cfg.font.size != null)
|
||||
"font_size ${toString cfg.font.size}"}
|
||||
'')
|
||||
|
||||
(optionalString (cfg.theme != null) ''
|
||||
include ${pkgs.kitty-themes}/share/kitty-themes/${
|
||||
let
|
||||
matching = filter (x: x.name == cfg.theme) (builtins.fromJSON
|
||||
(builtins.readFile
|
||||
"${pkgs.kitty-themes}/share/kitty-themes/themes.json"));
|
||||
in throwIf (length matching == 0)
|
||||
"kitty-themes does not contain a theme named ${cfg.theme}"
|
||||
(head matching).file
|
||||
}
|
||||
(optionalString (cfg.themeFile != null) ''
|
||||
include ${pkgs.kitty-themes}/share/kitty-themes/themes/${cfg.themeFile}.conf
|
||||
'')
|
||||
''
|
||||
# Shell integration is sourced and configured manually
|
||||
|
@ -211,13 +221,23 @@ in {
|
|||
(toKittyKeybindings cfg.keybindings)
|
||||
(toKittyEnv cfg.environment)
|
||||
cfg.extraConfig
|
||||
]);
|
||||
];
|
||||
} // optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
|
||||
onChange = ''
|
||||
${pkgs.procps}/bin/pkill -USR1 -u $USER kitty || true
|
||||
'';
|
||||
};
|
||||
|
||||
home.activation.checkKittyTheme = mkIf (cfg.themeFile != null) (let
|
||||
themePath =
|
||||
"${pkgs.kitty-themes}/share/kitty-themes/themes/${cfg.themeFile}.conf";
|
||||
in hm.dag.entryBefore [ "writeBoundary" ] ''
|
||||
if [[ ! -f "${themePath}" ]]; then
|
||||
errorEcho "kitty-themes does not contain the theme file ${themePath}!"
|
||||
exit 1
|
||||
fi
|
||||
'');
|
||||
|
||||
xdg.configFile."kitty/macos-launch-services-cmdline" = mkIf
|
||||
(cfg.darwinLaunchOptions != null && pkgs.stdenv.hostPlatform.isDarwin) {
|
||||
text = concatStringsSep " " cfg.darwinLaunchOptions;
|
||||
|
|
|
@ -10,6 +10,7 @@ let
|
|||
};
|
||||
|
||||
tests = {
|
||||
kitty = runTest ./standalone/kitty.nix;
|
||||
nixos-basics = runTest ./nixos/basics.nix;
|
||||
standalone-flake-basics = runTest ./standalone/flake-basics.nix;
|
||||
standalone-standard-basics = runTest ./standalone/standard-basics.nix;
|
||||
|
|
13
tests/integration/standalone/kitty-theme-bad-home.nix
Normal file
13
tests/integration/standalone/kitty-theme-bad-home.nix
Normal file
|
@ -0,0 +1,13 @@
|
|||
{ ... }: {
|
||||
home.username = "alice";
|
||||
home.homeDirectory = "/home/alice";
|
||||
home.stateVersion = "24.05";
|
||||
|
||||
# Let Home Manager install and manage itself.
|
||||
programs.home-manager.enable = true;
|
||||
|
||||
programs.kitty = {
|
||||
enable = true;
|
||||
themeFile = "No Such Theme";
|
||||
};
|
||||
}
|
14
tests/integration/standalone/kitty-theme-good-home.nix
Normal file
14
tests/integration/standalone/kitty-theme-good-home.nix
Normal file
|
@ -0,0 +1,14 @@
|
|||
{ ... }: {
|
||||
home.username = "alice";
|
||||
home.homeDirectory = "/home/alice";
|
||||
|
||||
home.stateVersion = "24.05"; # Please read the comment before changing.
|
||||
|
||||
# Let Home Manager install and manage itself.
|
||||
programs.home-manager.enable = true;
|
||||
|
||||
programs.kitty = {
|
||||
enable = true;
|
||||
themeFile = "SpaceGray_Eighties";
|
||||
};
|
||||
}
|
73
tests/integration/standalone/kitty.nix
Normal file
73
tests/integration/standalone/kitty.nix
Normal file
|
@ -0,0 +1,73 @@
|
|||
{ pkgs, ... }: {
|
||||
name = "kitty-theme-path";
|
||||
meta.maintainers = [ pkgs.lib.maintainers.rycee ];
|
||||
|
||||
nodes.machine = { ... }: {
|
||||
imports = [ "${pkgs.path}/nixos/modules/installer/cd-dvd/channel.nix" ];
|
||||
virtualisation.memorySize = 2048;
|
||||
users.users.alice = {
|
||||
isNormalUser = true;
|
||||
description = "Alice Foobar";
|
||||
password = "foobar";
|
||||
uid = 1000;
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
start_all()
|
||||
machine.wait_for_unit("network.target")
|
||||
machine.wait_for_unit("multi-user.target")
|
||||
|
||||
home_manager = "${../../..}"
|
||||
|
||||
def login_as_alice():
|
||||
machine.wait_until_tty_matches("1", "login: ")
|
||||
machine.send_chars("alice\n")
|
||||
machine.wait_until_tty_matches("1", "Password: ")
|
||||
machine.send_chars("foobar\n")
|
||||
machine.wait_until_tty_matches("1", "alice\\@machine")
|
||||
|
||||
def logout_alice():
|
||||
machine.send_chars("exit\n")
|
||||
|
||||
def alice_cmd(cmd):
|
||||
return f"su -l alice --shell /bin/sh -c $'export XDG_RUNTIME_DIR=/run/user/$UID ; {cmd}'"
|
||||
|
||||
def succeed_as_alice(cmd):
|
||||
return machine.succeed(alice_cmd(cmd))
|
||||
|
||||
def fail_as_alice(cmd):
|
||||
return machine.fail(alice_cmd(cmd))
|
||||
|
||||
# Create a persistent login so that Alice has a systemd session.
|
||||
login_as_alice()
|
||||
|
||||
# Set up a home-manager channel.
|
||||
succeed_as_alice(" ; ".join([
|
||||
"mkdir -p /home/alice/.nix-defexpr/channels",
|
||||
f"ln -s {home_manager} /home/alice/.nix-defexpr/channels/home-manager"
|
||||
]))
|
||||
|
||||
succeed_as_alice("nix-shell \"<home-manager>\" -A install")
|
||||
|
||||
with subtest("Switch to Bad Kitty"):
|
||||
succeed_as_alice("cp ${
|
||||
./kitty-theme-bad-home.nix
|
||||
} /home/alice/.config/home-manager/home.nix")
|
||||
|
||||
actual = fail_as_alice("home-manager switch")
|
||||
expected = "kitty-themes does not contain the theme file"
|
||||
assert expected in actual, \
|
||||
f"expected home-manager switch to contain {expected}, but got {actual}"
|
||||
|
||||
with subtest("Switch to Good Kitty"):
|
||||
succeed_as_alice("cp ${
|
||||
./kitty-theme-good-home.nix
|
||||
} /home/alice/.config/home-manager/home.nix")
|
||||
|
||||
actual = succeed_as_alice("home-manager switch")
|
||||
expected = "Activating checkKittyTheme"
|
||||
assert expected in actual, \
|
||||
f"expected home-manager switch to contain {expected}, but got {actual}"
|
||||
'';
|
||||
}
|
|
@ -1 +1,4 @@
|
|||
{ kitty-example-settings = ./example-settings.nix; }
|
||||
{
|
||||
kitty-example-settings = ./example-settings.nix;
|
||||
kitty-theme-to-themeFile = ./theme-to-themeFile.nix;
|
||||
}
|
||||
|
|
24
tests/modules/programs/kitty/theme-to-themeFile.nix
Normal file
24
tests/modules/programs/kitty/theme-to-themeFile.nix
Normal file
|
@ -0,0 +1,24 @@
|
|||
{ config, lib, pkgs, options, ... }: {
|
||||
config = {
|
||||
programs.kitty = {
|
||||
enable = true;
|
||||
theme = "Space Gray Eighties";
|
||||
};
|
||||
|
||||
test.stubs.kitty = { };
|
||||
|
||||
test.asserts.warnings.enable = true;
|
||||
test.asserts.warnings.expected = [
|
||||
("The option `programs.kitty.theme' defined in ${
|
||||
lib.showFiles options.programs.kitty.theme.files
|
||||
} has been changed to `programs.kitty.themeFile' that has a different"
|
||||
+ " type. Please read `programs.kitty.themeFile' documentation and"
|
||||
+ " update your configuration accordingly.")
|
||||
];
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists home-files/.config/kitty/kitty.conf
|
||||
assertFileRegex home-files/.config/kitty/kitty.conf "^include .*themes/SpaceGray_Eighties\.conf$"
|
||||
'';
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue