mirror of
https://github.com/nix-community/home-manager
synced 2024-12-25 03:09: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:
parent
b2af81413f
commit
0402cca9d8
8 changed files with 95 additions and 26 deletions
|
@ -4,7 +4,9 @@ with lib;
|
|||
|
||||
let
|
||||
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 {
|
||||
options = {
|
||||
programs.alacritty = {
|
||||
|
@ -18,7 +20,7 @@ in {
|
|||
};
|
||||
|
||||
settings = mkOption {
|
||||
type = yamlFormat.type;
|
||||
type = tomlFormat.type;
|
||||
default = { };
|
||||
example = literalExpression ''
|
||||
{
|
||||
|
@ -26,7 +28,7 @@ in {
|
|||
lines = 3;
|
||||
columns = 200;
|
||||
};
|
||||
key_bindings = [
|
||||
keyboard.bindings = [
|
||||
{
|
||||
key = "K";
|
||||
mods = "Control";
|
||||
|
@ -37,27 +39,37 @@ in {
|
|||
'';
|
||||
description = ''
|
||||
Configuration written to
|
||||
{file}`$XDG_CONFIG_HOME/alacritty/alacritty.yml`. See
|
||||
<https://github.com/alacritty/alacritty/blob/master/alacritty.yml>
|
||||
for the default configuration.
|
||||
{file}`$XDG_CONFIG_HOME/alacritty/alacritty.yml` or
|
||||
{file}`$XDG_CONFIG_HOME/alacritty/alacritty.toml`
|
||||
(the latter being used for alacritty 0.13 and later).
|
||||
See <https://github.com/alacritty/alacritty/tree/master#configuration>
|
||||
for more info.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = mkMerge [
|
||||
(mkIf cfg.enable {
|
||||
home.packages = [ cfg.package ];
|
||||
config = mkIf cfg.enable {
|
||||
home.packages = [ cfg.package ];
|
||||
|
||||
xdg.configFile."alacritty/alacritty.yml" = mkIf (cfg.settings != { }) {
|
||||
# TODO: Replace by the generate function but need to figure out how to
|
||||
# handle the escaping first.
|
||||
#
|
||||
# source = yamlFormat.generate "alacritty.yml" cfg.settings;
|
||||
|
||||
text =
|
||||
replaceStrings [ "\\\\" ] [ "\\" ] (builtins.toJSON cfg.settings);
|
||||
};
|
||||
})
|
||||
];
|
||||
xdg.configFile."alacritty/${configFileName}" =
|
||||
lib.mkIf (cfg.settings != { }) (lib.mkMerge [
|
||||
(lib.mkIf useToml {
|
||||
source =
|
||||
(tomlFormat.generate configFileName cfg.settings).overrideAttrs
|
||||
(finalAttrs: prevAttrs: {
|
||||
buildCommand = lib.concatStringsSep "\n" [
|
||||
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);
|
||||
})
|
||||
]);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2,4 +2,5 @@
|
|||
alacritty-example-settings = ./example-settings.nix;
|
||||
alacritty-empty-settings = ./empty-settings.nix;
|
||||
alacritty-merging-settings = ./settings-merging.nix;
|
||||
alacritty-toml-config = ./toml_config.nix;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
[[keyboard.bindings]]
|
||||
chars = "\x0c"
|
||||
key = "K"
|
||||
mods = "Control"
|
||||
|
||||
[window.dimensions]
|
||||
columns = 200
|
||||
lines = 3
|
|
@ -1 +0,0 @@
|
|||
{"key_bindings":[{"chars":"\x0c","key":"K","mods":"Control"}],"window":{"dimensions":{"columns":200,"lines":3}}}
|
|
@ -6,7 +6,7 @@ with lib;
|
|||
config = {
|
||||
programs.alacritty = {
|
||||
enable = true;
|
||||
package = config.lib.test.mkStubPackage { };
|
||||
package = config.lib.test.mkStubPackage { version = "0.13.0"; };
|
||||
|
||||
settings = {
|
||||
window.dimensions = {
|
||||
|
@ -14,7 +14,7 @@ with lib;
|
|||
columns = 200;
|
||||
};
|
||||
|
||||
key_bindings = [{
|
||||
keyboard.bindings = [{
|
||||
key = "K";
|
||||
mods = "Control";
|
||||
chars = "\\x0c";
|
||||
|
@ -24,8 +24,8 @@ with lib;
|
|||
|
||||
nmt.script = ''
|
||||
assertFileContent \
|
||||
home-files/.config/alacritty/alacritty.yml \
|
||||
${./example-settings-expected.yml}
|
||||
home-files/.config/alacritty/alacritty.toml \
|
||||
${./example-settings-expected.toml}
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ with lib;
|
|||
config = {
|
||||
programs.alacritty = {
|
||||
enable = true;
|
||||
package = config.lib.test.mkStubPackage { };
|
||||
package = config.lib.test.mkStubPackage { version = "0.12.3"; };
|
||||
|
||||
settings = {
|
||||
window.dimensions = {
|
||||
|
|
15
tests/modules/programs/alacritty/settings-toml-expected.toml
Normal file
15
tests/modules/programs/alacritty/settings-toml-expected.toml
Normal 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
|
34
tests/modules/programs/alacritty/toml_config.nix
Normal file
34
tests/modules/programs/alacritty/toml_config.nix
Normal 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}
|
||||
'';
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue