diff --git a/modules/misc/news/2025/10/2025-10-02_19-36-31.nix b/modules/misc/news/2025/10/2025-10-02_19-36-31.nix new file mode 100644 index 000000000..e39c77375 --- /dev/null +++ b/modules/misc/news/2025/10/2025-10-02_19-36-31.nix @@ -0,0 +1,14 @@ +{ + time = "2025-10-03T02:36:31+00:00"; + condition = true; + message = '' + A new module is available: `programs.asciinema` + + `asciinema` is a tool for recording, replaying, publishing, and live + streaming terminal session. + + This module enables declaring configuration via `.settings`, check the + official documentation for details; + https://docs.asciinema.org/manual/cli/quick-start/ + ''; +} diff --git a/modules/programs/asciinema.nix b/modules/programs/asciinema.nix new file mode 100644 index 000000000..3a015db44 --- /dev/null +++ b/modules/programs/asciinema.nix @@ -0,0 +1,82 @@ +{ + config, + lib, + pkgs, + ... +}: +let + inherit (lib) + mkEnableOption + mkIf + mkOption + mkPackageOption + ; + + formatter = pkgs.formats.toml { }; + + cfg = config.programs.asciinema; +in +{ + meta.maintainers = [ + lib.maintainers.S0AndS0 + ]; + + options.programs.asciinema = { + enable = mkEnableOption "Enable installing asciinema and writing configuration file"; + + package = mkPackageOption pkgs "asciinema" { + nullable = true; + }; + + settings = mkOption { + inherit (formatter) type; + + default = { }; + + example = { + server.url = "https://asciinema.example.com"; + + session = { + command = "/run/current-system/sw/bin/bash -l"; + capture_input = true; + capture_env = "SHELL,TERM,USER"; + idle_time_limit = 2; + pause_key = "^p"; + add_marker_key = "^x"; + prefix_key = "^a"; + }; + + playback = { + speed = 2; + pause_key = "^p"; + step_key = "s"; + next_marker_key = "m"; + }; + + notifications = { + enable = false; + command = ''tmux display-message "$TEXT"''; + }; + }; + + description = '' + Declare-able configurations for asciinema written to + {file}`$XDG_CONFIG_HOME/asciinema/config.toml`. + + + Check official docs for available configurations; + https://docs.asciinema.org/manual/cli/configuration/v3/#config-file + ''; + }; + }; + + config = mkIf cfg.enable { + xdg.configFile."asciinema/config.toml" = mkIf (cfg.settings != { }) { + source = formatter.generate "asciinema_config.toml" cfg.settings; + }; + + home.packages = mkIf (cfg.package != null) [ + cfg.package + ]; + }; +} diff --git a/tests/modules/programs/asciinema/default.nix b/tests/modules/programs/asciinema/default.nix new file mode 100644 index 000000000..42459f1e9 --- /dev/null +++ b/tests/modules/programs/asciinema/default.nix @@ -0,0 +1,3 @@ +{ + asciinema-settings = ./settings.nix; +} diff --git a/tests/modules/programs/asciinema/settings.nix b/tests/modules/programs/asciinema/settings.nix new file mode 100644 index 000000000..7c16b11f2 --- /dev/null +++ b/tests/modules/programs/asciinema/settings.nix @@ -0,0 +1,60 @@ +{ + programs.asciinema = { + enable = true; + + settings = { + server.url = "https://asciinema.example.com"; + + session = { + command = "/run/current-system/sw/bin/bash -l"; + capture_input = true; + capture_env = "SHELL,TERM,USER"; + idle_time_limit = 2; + pause_key = "^p"; + add_marker_key = "^x"; + prefix_key = "^a"; + }; + + playback = { + speed = 2; + pause_key = "^p"; + step_key = "s"; + next_marker_key = "m"; + }; + + notifications = { + enable = false; + command = ''tmux display-message "$TEXT"''; + }; + }; + }; + + ## TODO: check that `command` quote escaping doesn't break things + nmt.script = '' + assertFileExists home-files/.config/asciinema/config.toml + assertFileContent home-files/.config/asciinema/config.toml \ + ${builtins.toFile "expected.asciinema_config.toml" '' + [notifications] + command = "tmux display-message \"$TEXT\"" + enable = false + + [playback] + next_marker_key = "m" + pause_key = "^p" + speed = 2 + step_key = "s" + + [server] + url = "https://asciinema.example.com" + + [session] + add_marker_key = "^x" + capture_env = "SHELL,TERM,USER" + capture_input = true + command = "/run/current-system/sw/bin/bash -l" + idle_time_limit = 2 + pause_key = "^p" + prefix_key = "^a" + ''} + ''; +}