1
0
mirror of https://github.com/nix-community/home-manager synced 2024-06-03 05:23:32 +02:00
home-manager/modules/programs/alacritty.nix

76 lines
2.2 KiB
Nix
Raw Normal View History

2019-03-11 00:45:49 +01:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.alacritty;
useToml = lib.versionAtLeast cfg.package.version "0.13";
tomlFormat = pkgs.formats.toml { };
configFileName = "alacritty.${if useToml then "toml" else "yml"}";
2020-02-02 00:39:17 +01:00
in {
2019-03-11 00:45:49 +01:00
options = {
programs.alacritty = {
enable = mkEnableOption "Alacritty";
2019-03-11 00:45:49 +01:00
2020-07-03 19:09:35 +02:00
package = mkOption {
type = types.package;
default = pkgs.alacritty;
defaultText = literalExpression "pkgs.alacritty";
description = "The Alacritty package to install.";
2020-07-03 19:09:35 +02:00
};
2019-03-11 00:45:49 +01:00
settings = mkOption {
type = tomlFormat.type;
2020-02-02 00:39:17 +01:00
default = { };
example = literalExpression ''
2019-03-11 00:45:49 +01:00
{
window.dimensions = {
lines = 3;
columns = 200;
};
keyboard.bindings = [
2019-03-11 00:45:49 +01:00
{
key = "K";
mods = "Control";
chars = "\\u000c";
2019-03-11 00:45:49 +01:00
}
];
}
'';
description = ''
2019-03-11 00:45:49 +01:00
Configuration written to
{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.
2019-03-11 00:45:49 +01:00
'';
};
};
};
config = mkIf cfg.enable {
home.packages = [ cfg.package ];
2019-03-11 00:45:49 +01: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);
})
]);
};
2019-03-11 00:45:49 +01:00
}