From 707cb75ed33c59b58e6e03af881a833f3538d3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Lafuente?= Date: Wed, 21 Sep 2022 22:59:50 +0200 Subject: [PATCH] tmate: add module --- .github/CODEOWNERS | 3 + modules/misc/news.nix | 7 +++ modules/modules.nix | 1 + modules/programs/tmate.nix | 80 ++++++++++++++++++++++++ tests/default.nix | 1 + tests/modules/programs/tmate/default.nix | 1 + tests/modules/programs/tmate/tmate.nix | 25 ++++++++ 7 files changed, 118 insertions(+) create mode 100644 modules/programs/tmate.nix create mode 100644 tests/modules/programs/tmate/default.nix create mode 100644 tests/modules/programs/tmate/tmate.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 15fbe8e49..945e1d427 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -298,6 +298,9 @@ Makefile @thiagokokada /modules/programs/tiny.nix @kmaasrud +/modules/programs/tmate.nix @jlesquembre +/tests/modules/programs/tmate @jlesquembre + /modules/programs/topgrade.nix @msfjarvis /tests/modules/programs/topgrade @msfjarvis diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 34729e852..72448faa0 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -712,6 +712,13 @@ in A new module is available: 'services.safeeyes'. ''; } + + { + time = "2022-09-25T22:22:17+00:00"; + message = '' + A new module is available: 'programs.tmate'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 08c0e5d84..e4a863a58 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -170,6 +170,7 @@ let ./programs/timidity.nix ./programs/tint2.nix ./programs/tiny.nix + ./programs/tmate.nix ./programs/tmux.nix ./programs/topgrade.nix ./programs/urxvt.nix diff --git a/modules/programs/tmate.nix b/modules/programs/tmate.nix new file mode 100644 index 000000000..6681baf6c --- /dev/null +++ b/modules/programs/tmate.nix @@ -0,0 +1,80 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.tmate; + +in { + meta.maintainers = [ maintainers.jlesquembre ]; + + options = { + programs.tmate = { + enable = mkEnableOption "tmate"; + + package = mkOption { + type = types.package; + default = pkgs.tmate; + defaultText = literalExpression "pkgs.tmate"; + example = literalExpression "pkgs.tmate"; + description = "The tmate package to install."; + }; + + host = mkOption { + type = with types; nullOr str; + default = null; + example = literalExpression "tmate.io"; + description = "Tmate server address."; + }; + + port = mkOption { + type = with types; nullOr port; + default = null; + example = 2222; + description = "Tmate server port."; + }; + + dsaFingerprint = mkOption { + type = with types; nullOr string; + default = null; + example = literalExpression + "SHA256:1111111111111111111111111111111111111111111"; + description = "Tmate server EdDSA key fingerprint."; + }; + + rsaFingerprint = mkOption { + type = with types; nullOr string; + default = null; + example = literalExpression + "SHA256:1111111111111111111111111111111111111111111"; + description = "Tmate server RSA key fingerprint."; + }; + + extraConfig = mkOption { + type = types.lines; + default = ""; + description = '' + Additional content written at the end of + ~/.tmate.conf. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + home.file.".tmate.conf".text = let + conf = + optional (cfg.host != null) ''set -g tmate-server-host "${cfg.host}"'' + ++ optional (cfg.port != null) + "set -g tmate-server-port ${builtins.toString cfg.port}" + ++ optional (cfg.dsaFingerprint != null) + ''set -g tmate-server-ed25519-fingerprint "${cfg.dsaFingerprint}"'' + ++ optional (cfg.rsaFingerprint != null) + ''set -g tmate-server-rsa-fingerprint "${cfg.rsaFingerprint}"'' + ++ optional (cfg.extraConfig != "") cfg.extraConfig; + in concatStringsSep "\n" conf + "\n"; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 0a09e61c2..40b82f681 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -114,6 +114,7 @@ import nmt { ./modules/programs/starship ./modules/programs/taskwarrior ./modules/programs/texlive + ./modules/programs/tmate ./modules/programs/tmux ./modules/programs/topgrade ./modules/programs/vscode diff --git a/tests/modules/programs/tmate/default.nix b/tests/modules/programs/tmate/default.nix new file mode 100644 index 000000000..c5e05d562 --- /dev/null +++ b/tests/modules/programs/tmate/default.nix @@ -0,0 +1 @@ +{ tmate = ./tmate.nix; } diff --git a/tests/modules/programs/tmate/tmate.nix b/tests/modules/programs/tmate/tmate.nix new file mode 100644 index 000000000..4beb84c11 --- /dev/null +++ b/tests/modules/programs/tmate/tmate.nix @@ -0,0 +1,25 @@ +{ config, lib, pkgs, ... }: + +{ + programs.tmate = { + enable = true; + port = 222; + dsaFingerprint = "SHA256:1111111111111111111111111111111111111111111"; + extraConfig = ''set tmate-session-name "session-name"''; + }; + + test.stubs.tmate = { }; + + nmt.script = let + expectedConfig = '' + set -g tmate-server-port 222 + set -g tmate-server-ed25519-fingerprint "SHA256:1111111111111111111111111111111111111111111" + set tmate-session-name "session-name" + ''; + in '' + assertFileExists home-files/.tmate.conf + assertFileContent home-files/.tmate.conf ${ + builtins.toFile "config" expectedConfig + } + ''; +}