1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-26 19:59:47 +01:00

alacritty: make compatible with alacritty 0.13

The config file is in TOML from 0.13 onwards.
This commit is contained in:
r-vdp 2023-12-28 12:07:30 +01:00 committed by Mikilio
parent b2af81413f
commit 0402cca9d8
No known key found for this signature in database
GPG key ID: 5B2F1A890CF33F3F
8 changed files with 95 additions and 26 deletions

View file

@ -4,7 +4,9 @@ with lib;
let let
cfg = config.programs.alacritty; cfg = config.programs.alacritty;
yamlFormat = pkgs.formats.yaml { }; useToml = lib.versionAtLeast cfg.package.version "0.13";
tomlFormat = pkgs.formats.toml { };
configFileName = "alacritty.${if useToml then "toml" else "yml"}";
in { in {
options = { options = {
programs.alacritty = { programs.alacritty = {
@ -18,7 +20,7 @@ in {
}; };
settings = mkOption { settings = mkOption {
type = yamlFormat.type; type = tomlFormat.type;
default = { }; default = { };
example = literalExpression '' example = literalExpression ''
{ {
@ -26,7 +28,7 @@ in {
lines = 3; lines = 3;
columns = 200; columns = 200;
}; };
key_bindings = [ keyboard.bindings = [
{ {
key = "K"; key = "K";
mods = "Control"; mods = "Control";
@ -37,27 +39,37 @@ in {
''; '';
description = '' description = ''
Configuration written to Configuration written to
{file}`$XDG_CONFIG_HOME/alacritty/alacritty.yml`. See {file}`$XDG_CONFIG_HOME/alacritty/alacritty.yml` or
<https://github.com/alacritty/alacritty/blob/master/alacritty.yml> {file}`$XDG_CONFIG_HOME/alacritty/alacritty.toml`
for the default configuration. (the latter being used for alacritty 0.13 and later).
See <https://github.com/alacritty/alacritty/tree/master#configuration>
for more info.
''; '';
}; };
}; };
}; };
config = mkMerge [ config = mkIf cfg.enable {
(mkIf cfg.enable { home.packages = [ cfg.package ];
home.packages = [ cfg.package ];
xdg.configFile."alacritty/alacritty.yml" = mkIf (cfg.settings != { }) { xdg.configFile."alacritty/${configFileName}" =
# TODO: Replace by the generate function but need to figure out how to lib.mkIf (cfg.settings != { }) (lib.mkMerge [
# handle the escaping first. (lib.mkIf useToml {
# source =
# source = yamlFormat.generate "alacritty.yml" cfg.settings; (tomlFormat.generate configFileName cfg.settings).overrideAttrs
(finalAttrs: prevAttrs: {
text = buildCommand = lib.concatStringsSep "\n" [
replaceStrings [ "\\\\" ] [ "\\" ] (builtins.toJSON cfg.settings); prevAttrs.buildCommand
}; # TODO: why is this needed? Is there a better way to retain escape sequences?
}) "substituteInPlace $out --replace '\\\\' '\\'"
]; ];
});
})
# TODO remove this once we don't need to support Alacritty < 0.12 anymore
(lib.mkIf (!useToml) {
text =
replaceStrings [ "\\\\" ] [ "\\" ] (builtins.toJSON cfg.settings);
})
]);
};
} }

View file

@ -2,4 +2,5 @@
alacritty-example-settings = ./example-settings.nix; alacritty-example-settings = ./example-settings.nix;
alacritty-empty-settings = ./empty-settings.nix; alacritty-empty-settings = ./empty-settings.nix;
alacritty-merging-settings = ./settings-merging.nix; alacritty-merging-settings = ./settings-merging.nix;
alacritty-toml-config = ./toml_config.nix;
} }

View file

@ -0,0 +1,8 @@
[[keyboard.bindings]]
chars = "\x0c"
key = "K"
mods = "Control"
[window.dimensions]
columns = 200
lines = 3

View file

@ -1 +0,0 @@
{"key_bindings":[{"chars":"\x0c","key":"K","mods":"Control"}],"window":{"dimensions":{"columns":200,"lines":3}}}

View file

@ -6,7 +6,7 @@ with lib;
config = { config = {
programs.alacritty = { programs.alacritty = {
enable = true; enable = true;
package = config.lib.test.mkStubPackage { }; package = config.lib.test.mkStubPackage { version = "0.13.0"; };
settings = { settings = {
window.dimensions = { window.dimensions = {
@ -14,7 +14,7 @@ with lib;
columns = 200; columns = 200;
}; };
key_bindings = [{ keyboard.bindings = [{
key = "K"; key = "K";
mods = "Control"; mods = "Control";
chars = "\\x0c"; chars = "\\x0c";
@ -24,8 +24,8 @@ with lib;
nmt.script = '' nmt.script = ''
assertFileContent \ assertFileContent \
home-files/.config/alacritty/alacritty.yml \ home-files/.config/alacritty/alacritty.toml \
${./example-settings-expected.yml} ${./example-settings-expected.toml}
''; '';
}; };
} }

View file

@ -6,7 +6,7 @@ with lib;
config = { config = {
programs.alacritty = { programs.alacritty = {
enable = true; enable = true;
package = config.lib.test.mkStubPackage { }; package = config.lib.test.mkStubPackage { version = "0.12.3"; };
settings = { settings = {
window.dimensions = { window.dimensions = {

View file

@ -0,0 +1,15 @@
[font]
[font.bold]
family = "SFMono"
[font.normal]
family = "SFMono"
[[keyboard.bindings]]
chars = "\x0c"
key = "K"
mods = "Control"
[window.dimensions]
columns = 200
lines = 3

View file

@ -0,0 +1,34 @@
{ config, ... }:
{
config = {
programs.alacritty = {
enable = true;
package = config.lib.test.mkStubPackage { version = "0.13.0"; };
settings = {
window.dimensions = {
lines = 3;
columns = 200;
};
keyboard.bindings = [{
key = "K";
mods = "Control";
chars = "\\x0c";
}];
font = {
normal.family = "SFMono";
bold.family = "SFMono";
};
};
};
nmt.script = ''
assertFileContent \
home-files/.config/alacritty/alacritty.toml \
${./settings-toml-expected.toml}
'';
};
}