2020-10-12 00:22:58 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.alacritty;
|
2024-01-05 11:06:15 +00:00
|
|
|
useToml = lib.versionAtLeast cfg.package.version "0.13";
|
|
|
|
tomlFormat = pkgs.formats.toml { };
|
|
|
|
configFileName = "alacritty.${if useToml then "toml" else "yml"}";
|
2020-10-12 00:22:58 +00:00
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
programs.alacritty = {
|
|
|
|
enable = mkEnableOption "Alacritty";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.alacritty;
|
2021-11-04 16:42:44 +00:00
|
|
|
defaultText = literalExpression "pkgs.alacritty";
|
2020-10-12 00:22:58 +00:00
|
|
|
description = "The Alacritty package to install.";
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
2024-01-05 11:06:15 +00:00
|
|
|
type = tomlFormat.type;
|
2020-10-12 00:22:58 +00:00
|
|
|
default = { };
|
2021-11-04 16:42:44 +00:00
|
|
|
example = literalExpression ''
|
2020-10-12 00:22:58 +00:00
|
|
|
{
|
|
|
|
window.dimensions = {
|
|
|
|
lines = 3;
|
|
|
|
columns = 200;
|
|
|
|
};
|
2024-01-05 11:06:15 +00:00
|
|
|
keyboard.bindings = [
|
2020-10-12 00:22:58 +00:00
|
|
|
{
|
|
|
|
key = "K";
|
|
|
|
mods = "Control";
|
|
|
|
chars = "\\x0c";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Configuration written to
|
2024-01-05 11:06:15 +00:00
|
|
|
{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.
|
2020-10-12 00:22:58 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-01-05 11:06:15 +00:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
home.packages = [ cfg.package ];
|
2020-10-12 00:22:58 +00:00
|
|
|
|
2024-01-05 11:06:15 +00:00
|
|
|
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);
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
};
|
2020-10-12 00:22:58 +00:00
|
|
|
}
|