From f092a9220220e390c76605b6c4e2238774050f8b Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Mon, 18 Sep 2023 17:42:22 -0300 Subject: [PATCH] programs.rio: add module (#4118) Adds a programs.rio module to control Rio installation and configuration, a gpu accelerated terminal Signed-off-by: Otavio Salvador --- modules/lib/maintainers.nix | 6 +++ modules/misc/news.nix | 9 ++++ modules/modules.nix | 1 + modules/programs/rio.nix | 52 +++++++++++++++++++ tests/default.nix | 1 + tests/modules/programs/rio/default.nix | 4 ++ tests/modules/programs/rio/empty-settings.nix | 11 ++++ .../modules/programs/rio/example-settings.nix | 32 ++++++++++++ 8 files changed, 116 insertions(+) create mode 100644 modules/programs/rio.nix create mode 100644 tests/modules/programs/rio/default.nix create mode 100644 tests/modules/programs/rio/empty-settings.nix create mode 100644 tests/modules/programs/rio/example-settings.nix diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index 05d55b678..bcaa6e484 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -299,6 +299,12 @@ github = "nurelin"; githubId = 5276274; }; + otavio = { + email = "otavio.salvador@ossystems.com.br"; + github = "otavio"; + githubId = 25278; + name = "Otavio Salvador"; + }; pltanton = { name = "pltanton"; email = "plotnikovanton@gmail.com"; diff --git a/modules/misc/news.nix b/modules/misc/news.nix index e2b29cde4..34d2aad19 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1221,6 +1221,15 @@ in A new module is available: 'programs.eza'. ''; } + + { + time = "2023-09-18T11:44:11+00:00"; + message = '' + A new module is available: 'programs.rio'. + + Rio is a hardware-accelerated GPU terminal emulator powered by WebGPU. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 9f1bd3762..944d3d5bd 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -178,6 +178,7 @@ let ./programs/qutebrowser.nix ./programs/rbw.nix ./programs/readline.nix + ./programs/rio.nix ./programs/ripgrep.nix ./programs/rofi-pass.nix ./programs/rofi.nix diff --git a/modules/programs/rio.nix b/modules/programs/rio.nix new file mode 100644 index 000000000..6d66c99d6 --- /dev/null +++ b/modules/programs/rio.nix @@ -0,0 +1,52 @@ +{ lib, pkgs, config, ... }: +let + cfg = config.programs.rio; + + settingsFormat = pkgs.formats.toml { }; + + inherit (pkgs.stdenv.hostPlatform) isDarwin; +in { + options.programs.rio = { + enable = lib.mkEnableOption null // { + description = lib.mdDoc '' + Enable Rio, a terminal built to run everywhere, as a native desktop applications by + Rust/WebGPU or even in the browsers powered by WebAssembly/WebGPU. + ''; + }; + + package = lib.mkPackageOption pkgs "rio" { }; + + settings = lib.mkOption { + type = settingsFormat.type; + default = { }; + description = '' + Configuration written to $XDG_CONFIG_HOME/rio/config.toml on Linux or + $HOME/Library/Application Support/rio/config.toml on Darwin. See + for options. + ''; + }; + }; + meta.maintainers = [ lib.maintainers.otavio ]; + + config = lib.mkIf cfg.enable (lib.mkMerge [ + { + home.packages = [ cfg.package ]; + } + + # Only manage configuration if not empty + (lib.mkIf (cfg.settings != { } && !isDarwin) { + xdg.configFile."rio/config.toml".source = if lib.isPath cfg.settings then + cfg.settings + else + settingsFormat.generate "rio.toml" cfg.settings; + }) + + (lib.mkIf (cfg.settings != { } && isDarwin) { + home.file."Library/Application Support/rio/config.toml".source = + if lib.isPath cfg.settings then + cfg.settings + else + settingsFormat.generate "rio.toml" cfg.settings; + }) + ]); +} diff --git a/tests/default.nix b/tests/default.nix index 178bee05b..ecbbd726c 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -124,6 +124,7 @@ import nmt { ./modules/programs/qcal ./modules/programs/qutebrowser ./modules/programs/readline + ./modules/programs/rio ./modules/programs/ripgrep ./modules/programs/rtx ./modules/programs/sagemath diff --git a/tests/modules/programs/rio/default.nix b/tests/modules/programs/rio/default.nix new file mode 100644 index 000000000..a6aba7fe1 --- /dev/null +++ b/tests/modules/programs/rio/default.nix @@ -0,0 +1,4 @@ +{ + rio-example-settings = ./example-settings.nix; + rio-empty-settings = ./empty-settings.nix; +} diff --git a/tests/modules/programs/rio/empty-settings.nix b/tests/modules/programs/rio/empty-settings.nix new file mode 100644 index 000000000..064fc98fa --- /dev/null +++ b/tests/modules/programs/rio/empty-settings.nix @@ -0,0 +1,11 @@ +_: + +{ + programs.rio.enable = true; + + test.stubs.rio = { }; + + nmt.script = '' + assertPathNotExists home-files/.config/rio + ''; +} diff --git a/tests/modules/programs/rio/example-settings.nix b/tests/modules/programs/rio/example-settings.nix new file mode 100644 index 000000000..f3e116f03 --- /dev/null +++ b/tests/modules/programs/rio/example-settings.nix @@ -0,0 +1,32 @@ +{ config, pkgs, ... }: + +let + inherit (pkgs.stdenv.hostPlatform) isDarwin; + + path = if isDarwin then + "Library/Application Support/rio/config.toml" + else + ".config/rio/config.toml"; + + expected = pkgs.writeText "rio-expected.toml" '' + cursor = "_" + padding-x = 0 + performance = "Low" + ''; +in { + programs.rio = { + enable = true; + package = config.lib.test.mkStubPackage { }; + + settings = { + cursor = "_"; + performance = "Low"; + padding-x = 0; + }; + }; + + nmt.script = '' + assertFileExists home-files/"${path}" + assertFileContent home-files/"${path}" '${expected}' + ''; +}