1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-27 12:19:48 +01:00

ledger: add structural settings option (#3661)

This commit is contained in:
Mario Rodas 2023-05-11 04:20:49 -05:00 committed by GitHub
parent 010c269877
commit b365342adb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 72 additions and 4 deletions

1
.github/CODEOWNERS vendored
View file

@ -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

View file

@ -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 <filename>$XDG_CONFIG_HOME/ledger/ledgerrc</filename>.
See <link xlink:href="https://www.ledger-cli.org/3.0/doc/ledger3.html#Detailed-Option-Description"/>
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 <filename>$XDG_CONFIG_HOME/ledger/ledgerrc</filename>.
See <link xlink:href="https://www.ledger-cli.org/3.0/doc/ledger3.html#Detailed-Option-Description"/>
for explanation about possible values.
Extra configuration to add to
<filename>$XDG_CONFIG_HOME/ledger/ledgerrc</filename>.
'';
};
};
@ -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;
};
};
}

View file

@ -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

View file

@ -0,0 +1 @@
{ ledger = ./ledger.nix; }

View file

@ -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
''}
'';
}