1# Global configuration for freetds environment.
2
3{
4 config,
5 lib,
6 pkgs,
7 ...
8}:
9
10let
11
12 cfg = config.environment.freetds;
13
14in
15{
16 ###### interface
17
18 options = {
19
20 environment.freetds = lib.mkOption {
21 type = lib.types.attrsOf lib.types.str;
22 default = { };
23 example = lib.literalExpression ''
24 { MYDATABASE = '''
25 host = 10.0.2.100
26 port = 1433
27 tds version = 7.2
28 ''';
29 }
30 '';
31 description = ''
32 Configure freetds database entries. Each attribute denotes
33 a section within freetds.conf, and the value (a string) is the config
34 content for that section. When at least one entry is configured
35 the global environment variables FREETDSCONF, FREETDS and SYBASE
36 will be configured to allow the programs that use freetds to find the
37 library and config.
38 '';
39
40 };
41
42 };
43
44 ###### implementation
45
46 config = lib.mkIf (builtins.length (builtins.attrNames cfg) > 0) {
47
48 environment.variables.FREETDSCONF = "/etc/freetds.conf";
49 environment.variables.FREETDS = "/etc/freetds.conf";
50 environment.variables.SYBASE = "${pkgs.freetds}";
51
52 environment.etc."freetds.conf" = {
53 text = (
54 lib.concatStrings (
55 lib.mapAttrsToList (name: value: ''
56 [${name}]
57 ${value}
58 '') cfg
59 )
60 );
61 };
62
63 };
64
65}