1{
2 lib,
3 pkgs,
4 config,
5 ...
6}:
7
8let
9 cfg = config.services.taler;
10 settingsFormat = pkgs.formats.ini { };
11in
12
13{
14 # TODO turn this into a generic taler-like service thingy?
15 options.services.taler = {
16 enable = lib.mkEnableOption "the GNU Taler system" // lib.mkOption { internal = true; };
17 includes = lib.mkOption {
18 type = lib.types.listOf lib.types.path;
19 default = [ ];
20 description = ''
21 Files to include into the config file using Taler's `@inline@` directive.
22
23 This allows including arbitrary INI files, including imperatively managed ones.
24 '';
25 };
26 settings = lib.mkOption {
27 description = ''
28 Global configuration options for the taler config file.
29
30 For a list of all possible options, please see the man page [`taler.conf(5)`](https://docs.taler.net/manpages/taler.conf.5.html)
31 '';
32 type = lib.types.submodule {
33 freeformType = settingsFormat.type;
34 options = {
35 taler = {
36 CURRENCY = lib.mkOption {
37 type = lib.types.nonEmptyStr;
38 description = ''
39 The currency which taler services will operate with. This cannot be changed later.
40 '';
41 };
42 CURRENCY_ROUND_UNIT = lib.mkOption {
43 type = lib.types.str;
44 default = "${cfg.settings.taler.CURRENCY}:0.01";
45 defaultText = lib.literalExpression ''
46 "''${config.services.taler.settings.taler.CURRENCY}:0.01"
47 '';
48 description = ''
49 Smallest amount in this currency that can be transferred using the underlying RTGS.
50
51 You should probably not touch this.
52 '';
53 };
54 };
55 };
56 };
57 default = { };
58 };
59 runtimeDir = lib.mkOption {
60 type = lib.types.str;
61 default = "/run/taler-system-runtime/";
62 description = ''
63 Runtime directory shared between the taler services.
64
65 Crypto helpers put their sockets here for instance and the httpd
66 connects to them.
67 '';
68 };
69 };
70
71 config = lib.mkIf cfg.enable {
72 services.taler.settings.PATHS = {
73 TALER_DATA_HOME = "\${STATE_DIRECTORY}/";
74 TALER_CACHE_HOME = "\${CACHE_DIRECTORY}/";
75 TALER_RUNTIME_DIR = cfg.runtimeDir;
76 };
77
78 environment.etc."taler/taler.conf".source =
79 let
80 includes = pkgs.writers.writeText "includes.conf" (
81 lib.concatStringsSep "\n" (map (include: "@inline@ ${include}") cfg.includes)
82 );
83 generatedConfig = settingsFormat.generate "generated-taler.conf" cfg.settings;
84 in
85 pkgs.runCommand "taler.conf" { } ''
86 cat ${includes} > $out
87 echo >> $out
88 echo >> $out
89 cat ${generatedConfig} >> $out
90 '';
91
92 };
93}