From d2ed39f103edfaf3c711fee0f323558aaca7bd26 Mon Sep 17 00:00:00 2001 From: Tadeo Kondrak Date: Sun, 12 May 2019 20:08:23 -0600 Subject: [PATCH] alacritty: don't create file if settings is empty Also add a few test cases for the alacritty module. --- modules/programs/alacritty.nix | 13 +++++--- tests/default.nix | 1 + tests/modules/programs/alacritty/default.nix | 4 +++ .../programs/alacritty/empty-settings.nix | 13 ++++++++ .../alacritty/example-settings-expected.yml | 1 + .../programs/alacritty/example-settings.nix | 32 +++++++++++++++++++ 6 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 tests/modules/programs/alacritty/default.nix create mode 100644 tests/modules/programs/alacritty/empty-settings.nix create mode 100644 tests/modules/programs/alacritty/example-settings-expected.yml create mode 100644 tests/modules/programs/alacritty/example-settings.nix diff --git a/modules/programs/alacritty.nix b/modules/programs/alacritty.nix index a4e5e605..84675cb1 100644 --- a/modules/programs/alacritty.nix +++ b/modules/programs/alacritty.nix @@ -41,10 +41,13 @@ in }; }; - config = mkIf cfg.enable { - home.packages = [ pkgs.alacritty ]; + config = mkMerge [ + (mkIf cfg.enable { + home.packages = [ pkgs.alacritty ]; - xdg.configFile."alacritty/alacritty.yml".text = - replaceStrings ["\\\\"] ["\\"] (builtins.toJSON cfg.settings); - }; + xdg.configFile."alacritty/alacritty.yml" = mkIf (cfg.settings != {}) { + text = replaceStrings ["\\\\"] ["\\"] (builtins.toJSON cfg.settings); + }; + }) + ]; } diff --git a/tests/default.nix b/tests/default.nix index 91942a65..1fd12d34 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -36,6 +36,7 @@ import nmt { ) // import ./modules/home-environment // import ./modules/misc/fontconfig + // import ./modules/programs/alacritty // import ./modules/programs/bash // import ./modules/programs/ssh // import ./modules/programs/tmux diff --git a/tests/modules/programs/alacritty/default.nix b/tests/modules/programs/alacritty/default.nix new file mode 100644 index 00000000..f63e033d --- /dev/null +++ b/tests/modules/programs/alacritty/default.nix @@ -0,0 +1,4 @@ +{ + alacritty-example-settings = ./example-settings.nix; + alacritty-empty-settings = ./empty-settings.nix; +} diff --git a/tests/modules/programs/alacritty/empty-settings.nix b/tests/modules/programs/alacritty/empty-settings.nix new file mode 100644 index 00000000..f3f8486a --- /dev/null +++ b/tests/modules/programs/alacritty/empty-settings.nix @@ -0,0 +1,13 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.alacritty.enable = true; + + nmt.script = '' + assertPathNotExists home-files/.config/alacritty + ''; + }; +} diff --git a/tests/modules/programs/alacritty/example-settings-expected.yml b/tests/modules/programs/alacritty/example-settings-expected.yml new file mode 100644 index 00000000..06162419 --- /dev/null +++ b/tests/modules/programs/alacritty/example-settings-expected.yml @@ -0,0 +1 @@ +{"key_bindings":[{"chars":"\x0c","key":"K","mods":"Control"}],"window":{"dimensions":{"columns":200,"lines":3}}} \ No newline at end of file diff --git a/tests/modules/programs/alacritty/example-settings.nix b/tests/modules/programs/alacritty/example-settings.nix new file mode 100644 index 00000000..2c84710d --- /dev/null +++ b/tests/modules/programs/alacritty/example-settings.nix @@ -0,0 +1,32 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.alacritty = { + enable = true; + + settings = { + window.dimensions = { + lines = 3; + columns = 200; + }; + + key_bindings = [ + { + key = "K"; + mods = "Control"; + chars = "\\x0c"; + } + ]; + }; + }; + + nmt.script = '' + assertFileContent \ + home-files/.config/alacritty/alacritty.yml \ + ${./example-settings-expected.yml} + ''; + }; +}