Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions modules/collection/programs/chawan.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
config,
lib,
pkgs,
...
}: let
inherit (lib.modules) mkIf;
inherit (lib.options) mkOption mkEnableOption mkPackageOption;

toml = pkgs.formats.toml {};

cfg = config.rum.programs.chawan;
in {
options.rum.programs.chawan = {
enable = mkEnableOption "chawan";

package = mkPackageOption pkgs "chawan" {nullable = true;};

settings = mkOption {
type = toml.type;
default = {};
example = {
buffer = {
images = true;
autofocus = true;
};
page."C-k" = "() => pager.load('ddg:')";
};
description = ''
Configuration written to {file}`$XDG_CONFIG_HOME/chawan/config.toml`.
Please reference [chawan's documentation] for config options.

[chawan's documentation]: https://git.sr.ht/~bptato/chawan/tree/master/doc/config.md
'';
};
};

config = mkIf cfg.enable {
packages = mkIf (cfg.package != null) [cfg.package];
xdg.config.files."chawan/config.toml" = mkIf (cfg.settings != {}) {
source = toml.generate "chawan-config.toml" cfg.settings;
};
};
}
36 changes: 36 additions & 0 deletions modules/tests/collection/programs/chawan/chawan.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
let
settings = {
buffer = {
images = true;
autofocus = true;
};
page."C-k" = "() => pager.load('ddg:')";
};
in {
name = "programs-chawan";
nodes.machine = {
hjem.users.bob.rum = {
programs.chawan = {
enable = true;
inherit settings;
};
};
};

testScript =
#python
''
# Waiting for our user to load.
machine.succeed("loginctl enable-linger bob")
machine.wait_for_unit("default.target")

confPath = "/home/bob/.config/chawan/config.toml"

# Checks if the chawan config file exists in the expected place.
machine.succeed("[ -r %s ]" % confPath)

# Assert that the generated config is applied correctly.
machine.copy_from_host("${./expected_config}", "/home/bob/expected_config")
machine.succeed("diff -u -Z -b -B %s /home/bob/expected_config" % confPath)
'';
}
6 changes: 6 additions & 0 deletions modules/tests/collection/programs/chawan/expected_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[buffer]
autofocus = true
images = true

[page]
C-k = "() => pager.load('ddg:')"