1# Tests in: ../../../../tests/modular-service-etc/test.nix
2# This file is a function that returns a module.
3pkgs:
4{
5 lib,
6 name,
7 config,
8 options,
9 ...
10}:
11let
12 inherit (lib) mkOption types;
13in
14{
15 options = {
16 enable = mkOption {
17 type = types.bool;
18 default = true;
19 description = ''
20 Whether this configuration file should be generated.
21 This option allows specific configuration files to be disabled.
22 '';
23 };
24
25 name = mkOption {
26 type = types.str;
27 description = ''
28 Name of the configuration file (relative to the service's configuration directory). Defaults to the attribute name.
29 '';
30 };
31
32 path = mkOption {
33 type = types.str;
34 readOnly = true;
35 description = ''
36 The actual path where this configuration file will be available.
37 This is determined by the service manager implementation.
38
39 On NixOS it is an absolute path.
40 Other service managers may provide a relative path, in order to be unprivileged and/or relocatable.
41 '';
42 };
43
44 text = mkOption {
45 default = null;
46 type = types.nullOr types.lines;
47 description = "Text content of the configuration file.";
48 };
49
50 source = mkOption {
51 type = types.path;
52 description = "Path of the source file.";
53 };
54 };
55
56 config = {
57 name = lib.mkDefault name;
58 source = lib.mkIf (config.text != null) (
59 let
60 name' = "service-configdata-" + lib.replaceStrings [ "/" ] [ "-" ] name;
61 in
62 lib.mkDerivedConfig options.text (pkgs.writeText name')
63 );
64 };
65}