From d04e52b0c05afb41139e313dba9b62d1b4878245 Mon Sep 17 00:00:00 2001 From: Philipp Dargel Date: Thu, 17 Jun 2021 17:06:47 +0200 Subject: [PATCH] terminator: add module (#2063) added configuration for terminator --- .github/CODEOWNERS | 2 + modules/lib/maintainers.nix | 6 ++ modules/modules.nix | 1 + modules/programs/terminator.nix | 70 +++++++++++++++++++ tests/default.nix | 1 + .../programs/terminator/config-file.nix | 22 ++++++ tests/modules/programs/terminator/default.nix | 1 + 7 files changed, 103 insertions(+) create mode 100644 modules/programs/terminator.nix create mode 100644 tests/modules/programs/terminator/config-file.nix create mode 100644 tests/modules/programs/terminator/default.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 3356d1cfb..ad40dd705 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -178,6 +178,8 @@ /modules/programs/starship.nix @marsam +/modules/programs/terminator.nix @chisui + /modules/programs/texlive.nix @rycee /modules/programs/topgrade.nix @msfjarvis diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index 32f883d91..8a06ea11c 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -25,6 +25,12 @@ github = "cwyc"; githubId = 16950437; }; + chisui = { + name = "Philipp Dargel"; + email = "chisui@users.noreply.github.com"; + github = "chisui"; + githubId = 4526429; + }; olmokramer = { name = "Olmo Kramer"; email = "olmokramer@users.noreply.github.com"; diff --git a/modules/modules.nix b/modules/modules.nix index 0e9c4327b..dc539184f 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -137,6 +137,7 @@ let (loadModule ./programs/termite.nix { }) (loadModule ./programs/texlive.nix { }) (loadModule ./programs/tmux.nix { }) + (loadModule ./programs/terminator.nix { condition = hostPlatform.isLinux; }) (loadModule ./programs/topgrade.nix { }) (loadModule ./programs/urxvt.nix { }) (loadModule ./programs/vim.nix { }) diff --git a/modules/programs/terminator.nix b/modules/programs/terminator.nix new file mode 100644 index 000000000..d100a9cd9 --- /dev/null +++ b/modules/programs/terminator.nix @@ -0,0 +1,70 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.terminator; + + toValue = val: + if val == null then + "None" + else if val == true then + "True" + else if val == false then + "False" + else + ''"${toString val}"''; + + toConfigObject = let + toKey = depth: key: + if depth == 0 then key else toKey (depth - 1) "[${key}]"; + toConfigObjectLevel = depth: obj: + flatten (mapAttrsToList (key: val: + if isAttrs val then + [ (toKey depth key) ] ++ toConfigObjectLevel (depth + 1) val + else + [ "${key} = ${toValue val}" ]) obj); + in obj: concatStringsSep "\n" (toConfigObjectLevel 1 obj); + +in { + meta.maintainers = [ maintainers.chisui ]; + + options.programs.terminator = { + enable = mkEnableOption "terminator, a tiling terminal emulator"; + + package = mkOption { + type = types.package; + default = pkgs.terminator; + example = literalExample "pkgs.terminator"; + description = "terminator package to install."; + }; + + config = mkOption { + default = { }; + description = '' + configuration for terminator. + + For a list of all possible options refer to the + + terminator_config + 5 + + man page. + ''; + type = types.attrsOf types.anything; + example = literalExample '' + { + global_config.borderless = true; + profiles.default.background_color = "#002b36"; + } + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + xdg.configFile."terminator/config" = + mkIf (cfg.config != { }) { text = toConfigObject cfg.config; }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 95b339686..f08e8eb21 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -108,6 +108,7 @@ import nmt { ./modules/programs/rbw ./modules/programs/rofi ./modules/programs/rofi-pass + ./modules/programs/terminator ./modules/programs/waybar ./modules/services/barrier ./modules/services/dropbox diff --git a/tests/modules/programs/terminator/config-file.nix b/tests/modules/programs/terminator/config-file.nix new file mode 100644 index 000000000..b6f0538af --- /dev/null +++ b/tests/modules/programs/terminator/config-file.nix @@ -0,0 +1,22 @@ +{ config, lib, pkgs, ... }: { + config = { + programs.terminator = { + enable = true; + config = { + global_config.borderless = true; + profiles.default.background_color = "#002b36"; + }; + }; + + nmt.script = '' + assertFileContent home-files/.config/terminator/config ${ + pkgs.writeText "expected" '' + [global_config] + borderless = True + [profiles] + [[default]] + background_color = "#002b36"'' + } + ''; + }; +} diff --git a/tests/modules/programs/terminator/default.nix b/tests/modules/programs/terminator/default.nix new file mode 100644 index 000000000..4d53e534c --- /dev/null +++ b/tests/modules/programs/terminator/default.nix @@ -0,0 +1 @@ +{ terminator-config-file = ./config-file.nix; }