|
15 | 15 | }: |
16 | 16 | let |
17 | 17 | cfg = config.environment; |
| 18 | + |
| 19 | + etcEntry = |
| 20 | + { name, ... }: |
| 21 | + { |
| 22 | + options = { |
| 23 | + enable = lib.mkOption { |
| 24 | + type = lib.types.bool; |
| 25 | + description = '' |
| 26 | + Whether this /etc file should be generated. This option allows specific /etc files to be disabled. |
| 27 | + ''; |
| 28 | + default = true; |
| 29 | + }; |
| 30 | + |
| 31 | + source = lib.mkOption { |
| 32 | + type = lib.types.path; |
| 33 | + description = '' |
| 34 | + Path of the source file. |
| 35 | + ''; |
| 36 | + }; |
| 37 | + |
| 38 | + target = lib.mkOption { |
| 39 | + type = lib.types.str; |
| 40 | + description = '' |
| 41 | + Name of symlink (relative to `/etc`). Defaults to the attribute name. |
| 42 | + ''; |
| 43 | + default = name; |
| 44 | + }; |
| 45 | + |
| 46 | + mode = lib.mkOption { |
| 47 | + type = lib.types.str; |
| 48 | + description = '' |
| 49 | + If set to something else than symlink, the file is copied instead of symlinked, with the given file mode. |
| 50 | + ''; |
| 51 | + default = "symlink"; |
| 52 | + }; |
| 53 | + |
| 54 | + user = lib.mkOption { |
| 55 | + type = lib.types.str; |
| 56 | + description = '' |
| 57 | + User name of file owner. |
| 58 | +
|
| 59 | + Only takes effect when the file is copied (that is, the mode is not symlink). |
| 60 | +
|
| 61 | + When services.userborn.enable, this option has no effect. You have to assign a uid instead. Otherwise this option takes precedence over uid. |
| 62 | + ''; |
| 63 | + default = "+0"; |
| 64 | + }; |
| 65 | + |
| 66 | + group = lib.mkOption { |
| 67 | + type = lib.types.str; |
| 68 | + description = '' |
| 69 | + Group name of file owner. |
| 70 | +
|
| 71 | + Only takes effect when the file is copied (that is, the mode is not symlink). |
| 72 | +
|
| 73 | + When services.userborn.enable, this option has no effect. You have to assign a gid instead. Otherwise this option takes precedence over gid. |
| 74 | + ''; |
| 75 | + default = "+0"; |
| 76 | + }; |
| 77 | + |
| 78 | + uid = lib.mkOption { |
| 79 | + type = lib.types.str; |
| 80 | + description = '' |
| 81 | + UID of created file. Only takes effect when the file is copied (that is, the mode is not 'symlink'). |
| 82 | + ''; |
| 83 | + default = "0"; |
| 84 | + }; |
| 85 | + |
| 86 | + gid = lib.mkOption { |
| 87 | + type = lib.types.str; |
| 88 | + description = '' |
| 89 | + GID of created file. Only takes effect when the file is copied (that is, the mode is not ‘symlink’). |
| 90 | + ''; |
| 91 | + default = "0"; |
| 92 | + }; |
| 93 | + }; |
| 94 | + }; |
18 | 95 | in |
19 | 96 | { |
20 | 97 | options.environment = { |
|
64 | 141 | default = [ ]; |
65 | 142 | type = with lib.types; listOf package; |
66 | 143 | }; |
| 144 | + |
| 145 | + etc = lib.mkOption { |
| 146 | + type = lib.types.attrsOf (lib.types.submodule etcEntry); |
| 147 | + default = { }; |
| 148 | + }; |
67 | 149 | }; |
68 | 150 |
|
69 | 151 | config = { |
|
105 | 187 | mkdir -pm 0555 /var/empty |
106 | 188 | '' |
107 | 189 | ); |
| 190 | + |
| 191 | + init.services.environment-etc = { |
| 192 | + enabled = true; |
| 193 | + execStart = |
| 194 | + let |
| 195 | + start = pkgs.writers.writeHaskell "environment-etc-start" { |
| 196 | + libraries = with pkgs.haskellPackages; [ |
| 197 | + unix |
| 198 | + directory |
| 199 | + filepath |
| 200 | + aeson |
| 201 | + unordered-containers |
| 202 | + ]; |
| 203 | + } (builtins.readFile ./environment.hs); |
| 204 | + in |
| 205 | + "${start} ${pkgs.writers.writeJSON "environment-etc.json" cfg.etc}"; |
| 206 | + }; |
108 | 207 | }; |
109 | 208 | } |
0 commit comments