From f4d01c1d87c7c2ec909549165d5a8338f1bd3315 Mon Sep 17 00:00:00 2001 From: reesilva Date: Wed, 8 Jul 2026 22:39:14 +0200 Subject: [PATCH] posting: add module posting: add news --- .../misc/news/2026/07/2026-07-08_22-43-29.nix | 12 +++ modules/programs/posting.nix | 97 +++++++++++++++++++ .../programs/posting/configuration.nix | 39 ++++++++ tests/modules/programs/posting/default.nix | 4 + .../programs/posting/empty-settings.nix | 10 ++ .../programs/posting/expected-config.yaml | 7 ++ .../programs/posting/expected-theme.yaml | 9 ++ 7 files changed, 178 insertions(+) create mode 100644 modules/misc/news/2026/07/2026-07-08_22-43-29.nix create mode 100644 modules/programs/posting.nix create mode 100644 tests/modules/programs/posting/configuration.nix create mode 100644 tests/modules/programs/posting/default.nix create mode 100644 tests/modules/programs/posting/empty-settings.nix create mode 100644 tests/modules/programs/posting/expected-config.yaml create mode 100644 tests/modules/programs/posting/expected-theme.yaml diff --git a/modules/misc/news/2026/07/2026-07-08_22-43-29.nix b/modules/misc/news/2026/07/2026-07-08_22-43-29.nix new file mode 100644 index 000000000..e1f580d66 --- /dev/null +++ b/modules/misc/news/2026/07/2026-07-08_22-43-29.nix @@ -0,0 +1,12 @@ +{ + time = "2026-07-08T20:43:23+00:00"; + condition = true; + message = '' + A new module is available: 'programs.posting'. + + Posting is an open-source terminal-based API client for developing + and testing APIs. The module supports configuration via + `programs.posting.settings` and custom themes via + `programs.posting.themes`. + ''; +} diff --git a/modules/programs/posting.nix b/modules/programs/posting.nix new file mode 100644 index 000000000..d487571fa --- /dev/null +++ b/modules/programs/posting.nix @@ -0,0 +1,97 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + cfg = config.programs.posting; + yamlFormat = pkgs.formats.yaml { }; +in +{ + meta.maintainers = [ lib.hm.maintainers.reesilva ]; + + options.programs.posting = { + enable = lib.mkEnableOption "Posting"; + + package = lib.mkPackageOption pkgs "posting" { nullable = true; }; + + settings = lib.mkOption { + inherit (yamlFormat) type; + default = { }; + example = lib.literalExpression '' + { + theme = "custom"; + layout = "horizontal"; + response = { + prettify_json = false; + }; + } + ''; + description = '' + Configuration written to + {file}`$XDG_CONFIG_HOME/posting/config.yaml`. + + See + for supported values. + ''; + }; + + themes = lib.mkOption { + type = + with lib.types; + attrsOf (oneOf [ + yamlFormat.type + path + lines + ]); + default = { }; + example = lib.literalExpression '' + { + custom = { + name = "custom"; + primary = "#4e78c4"; + secondary = "#f39c12"; + accent = "#e74c3c"; + background = "#0e1726"; + surface = "#17202a"; + error = "#e74c3c"; + success = "#2ecc71"; + warning = "#f1c40f"; + }; + } + ''; + description = '' + Each theme is written to + {file}`$XDG_DATA_HOME/posting/themes/NAME.yaml`. + + See + for more information. + ''; + }; + }; + + config = lib.mkIf cfg.enable { + home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; + + xdg.configFile."posting/config.yaml" = lib.mkIf (cfg.settings != { }) { + source = yamlFormat.generate "posting-config.yaml" cfg.settings; + }; + + xdg.dataFile = lib.mkIf (cfg.themes != { }) ( + lib.mapAttrs' ( + name: value: + lib.nameValuePair "posting/themes/${name}.yaml" { + source = + if builtins.isPath value || lib.isStorePath value then + value + else if lib.isString value then + pkgs.writeText "posting-theme-${name}.yaml" value + else + yamlFormat.generate "posting-theme-${name}.yaml" value; + } + ) cfg.themes + ); + }; +} diff --git a/tests/modules/programs/posting/configuration.nix b/tests/modules/programs/posting/configuration.nix new file mode 100644 index 000000000..2ea8c7306 --- /dev/null +++ b/tests/modules/programs/posting/configuration.nix @@ -0,0 +1,39 @@ +{ + programs.posting = { + enable = true; + settings = { + animation = "basic"; + heading = { + show_host = false; + }; + layout = "horizontal"; + response = { + prettify_json = false; + }; + theme = "custom"; + }; + themes = { + custom = { + name = "custom"; + primary = "#4e78c4"; + secondary = "#f39c12"; + accent = "#e74c3c"; + background = "#0e1726"; + surface = "#17202a"; + error = "#e74c3c"; + success = "#2ecc71"; + warning = "#f1c40f"; + }; + }; + }; + + nmt.script = '' + assertFileExists home-files/.config/posting/config.yaml + assertFileContent home-files/.config/posting/config.yaml \ + ${./expected-config.yaml} + + assertFileExists home-files/.local/share/posting/themes/custom.yaml + assertFileContent home-files/.local/share/posting/themes/custom.yaml \ + ${./expected-theme.yaml} + ''; +} diff --git a/tests/modules/programs/posting/default.nix b/tests/modules/programs/posting/default.nix new file mode 100644 index 000000000..10795e93e --- /dev/null +++ b/tests/modules/programs/posting/default.nix @@ -0,0 +1,4 @@ +{ + posting-empty-settings = ./empty-settings.nix; + posting-configuration = ./configuration.nix; +} diff --git a/tests/modules/programs/posting/empty-settings.nix b/tests/modules/programs/posting/empty-settings.nix new file mode 100644 index 000000000..751fc93da --- /dev/null +++ b/tests/modules/programs/posting/empty-settings.nix @@ -0,0 +1,10 @@ +{ + programs.posting = { + enable = true; + }; + + nmt.script = '' + assertPathNotExists home-files/.config/posting/config.yaml + assertPathNotExists home-files/.local/share/posting + ''; +} diff --git a/tests/modules/programs/posting/expected-config.yaml b/tests/modules/programs/posting/expected-config.yaml new file mode 100644 index 000000000..b7d59c808 --- /dev/null +++ b/tests/modules/programs/posting/expected-config.yaml @@ -0,0 +1,7 @@ +animation: basic +heading: + show_host: false +layout: horizontal +response: + prettify_json: false +theme: custom diff --git a/tests/modules/programs/posting/expected-theme.yaml b/tests/modules/programs/posting/expected-theme.yaml new file mode 100644 index 000000000..4d83648d5 --- /dev/null +++ b/tests/modules/programs/posting/expected-theme.yaml @@ -0,0 +1,9 @@ +accent: '#e74c3c' +background: '#0e1726' +error: '#e74c3c' +name: custom +primary: '#4e78c4' +secondary: '#f39c12' +success: '#2ecc71' +surface: '#17202a' +warning: '#f1c40f'