mirror of
https://github.com/nix-community/home-manager
synced 2024-11-26 21:19:45 +01:00
ledger: add structural settings
option (#3661)
This commit is contained in:
parent
010c269877
commit
b365342adb
5 changed files with 72 additions and 4 deletions
1
.github/CODEOWNERS
vendored
1
.github/CODEOWNERS
vendored
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
1
tests/modules/programs/ledger/default.nix
Normal file
1
tests/modules/programs/ledger/default.nix
Normal file
|
@ -0,0 +1 @@
|
|||
{ ledger = ./ledger.nix; }
|
35
tests/modules/programs/ledger/ledger.nix
Normal file
35
tests/modules/programs/ledger/ledger.nix
Normal 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
|
||||
''}
|
||||
'';
|
||||
}
|
Loading…
Reference in a new issue