diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index 6d50bbab5..9d12e96fd 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -180,6 +180,7 @@ Makefile @thiagokokada
/modules/programs/lazygit.nix @kalhauge
/modules/programs/ledger.nix @marsam
+/tests/modules/programs/ledger @marsam
/modules/programs/less.nix @pamplemousse
/tests/modules/programs/less @pamplemousse
diff --git a/modules/programs/ledger.nix b/modules/programs/ledger.nix
index c51ed7d12..ae9fb3680 100644
--- a/modules/programs/ledger.nix
+++ b/modules/programs/ledger.nix
@@ -6,6 +6,15 @@ let
cfg = config.programs.ledger;
+ cfgText = generators.toKeyValue {
+ mkKeyValue = key: value:
+ if isBool value then
+ optionalString value "--${key}"
+ else
+ "--${key} ${toString value}";
+ listsAsDuplicateKeys = true;
+ } cfg.settings;
+
in {
meta.maintainers = [ maintainers.marsam ];
@@ -14,6 +23,26 @@ in {
package = mkPackageOption pkgs "ledger" { };
+ settings = mkOption {
+ type = with types; attrsOf (oneOf [ bool int str (listOf str) ]);
+ default = { };
+ example = {
+ sort = "date";
+ date-format = "%Y-%m-%d";
+ strict = true;
+ file = [
+ "~/finances/journal.ledger"
+ "~/finances/assets.ledger"
+ "~/finances/income.ledger"
+ ];
+ };
+ description = ''
+ Configuration written to $XDG_CONFIG_HOME/ledger/ledgerrc.
+ See
+ for explanation about possible values.
+ '';
+ };
+
extraConfig = mkOption {
type = types.lines;
default = "";
@@ -23,9 +52,8 @@ in {
--date-format %Y-%m-%d
'';
description = ''
- Configuration written to $XDG_CONFIG_HOME/ledger/ledgerrc.
- See
- for explanation about possible values.
+ Extra configuration to add to
+ $XDG_CONFIG_HOME/ledger/ledgerrc.
'';
};
};
@@ -34,6 +62,8 @@ in {
home.packages = [ cfg.package ];
xdg.configFile."ledger/ledgerrc" =
- mkIf (cfg.extraConfig != "") { text = cfg.extraConfig; };
+ mkIf (cfg.settings != { } || cfg.extraConfig != "") {
+ text = cfgText + cfg.extraConfig;
+ };
};
}
diff --git a/tests/default.nix b/tests/default.nix
index f2e20d248..c4e009eb1 100644
--- a/tests/default.nix
+++ b/tests/default.nix
@@ -86,6 +86,7 @@ import nmt {
./modules/programs/k9s
./modules/programs/kakoune
./modules/programs/kitty
+ ./modules/programs/ledger
./modules/programs/less
./modules/programs/lf
./modules/programs/lieer
diff --git a/tests/modules/programs/ledger/default.nix b/tests/modules/programs/ledger/default.nix
new file mode 100644
index 000000000..d7556a0bb
--- /dev/null
+++ b/tests/modules/programs/ledger/default.nix
@@ -0,0 +1 @@
+{ ledger = ./ledger.nix; }
diff --git a/tests/modules/programs/ledger/ledger.nix b/tests/modules/programs/ledger/ledger.nix
new file mode 100644
index 000000000..f120a654d
--- /dev/null
+++ b/tests/modules/programs/ledger/ledger.nix
@@ -0,0 +1,35 @@
+{ ... }:
+
+{
+ programs.ledger = {
+ enable = true;
+ settings = {
+ sort = "date";
+ strict = true;
+ pedantic = true;
+ leeway = 30;
+ date-format = "%Y-%m-%d";
+ file = [
+ "~/finances/journal.ledger"
+ "~/finances/assets.ledger"
+ "~/finances/income.ledger"
+ ];
+ };
+ };
+
+ test.stubs.ledger = { };
+
+ nmt.script = ''
+ assertFileContent home-files/.config/ledger/ledgerrc \
+ ${builtins.toFile "ledger-expected-settings" ''
+ --date-format %Y-%m-%d
+ --file ~/finances/journal.ledger
+ --file ~/finances/assets.ledger
+ --file ~/finances/income.ledger
+ --leeway 30
+ --pedantic
+ --sort date
+ --strict
+ ''}
+ '';
+}