|
11 | 11 | cfg = config.services.garage; |
12 | 12 | toml = pkgs.formats.toml { }; |
13 | 13 | configFile = toml.generate "garage.toml" cfg.settings; |
14 | | - |
15 | | - anyHasPrefix = |
16 | | - prefix: strOrList: |
17 | | - if isString strOrList then |
18 | | - hasPrefix prefix strOrList |
19 | | - else |
20 | | - any ({ path, ... }: hasPrefix prefix path) strOrList; |
21 | 14 | in |
22 | 15 | { |
23 | 16 | meta = { |
24 | 17 | doc = ./garage.md; |
25 | | - maintainers = [ maintainers.mjm ]; |
| 18 | + maintainers = with lib.maintainers; [ |
| 19 | + mjm |
| 20 | + cything |
| 21 | + ]; |
26 | 22 | }; |
27 | 23 |
|
28 | 24 | options.services.garage = { |
|
44 | 40 | }; |
45 | 41 |
|
46 | 42 | logLevel = mkOption { |
47 | | - type = types.enum ([ |
| 43 | + type = types.enum [ |
48 | 44 | "error" |
49 | 45 | "warn" |
50 | 46 | "info" |
51 | 47 | "debug" |
52 | 48 | "trace" |
53 | | - ]); |
| 49 | + ]; |
54 | 50 | default = "info"; |
55 | 51 | example = "debug"; |
56 | 52 | description = "Garage log level, see <https://garagehq.deuxfleurs.fr/documentation/quick-start/#launching-the-garage-server> for examples."; |
|
125 | 121 | restartTriggers = [ |
126 | 122 | configFile |
127 | 123 | ] ++ (lib.optional (cfg.environmentFile != null) cfg.environmentFile); |
128 | | - serviceConfig = { |
129 | | - ExecStart = "${cfg.package}/bin/garage server"; |
130 | | - |
131 | | - StateDirectory = mkIf ( |
132 | | - anyHasPrefix "/var/lib/garage" cfg.settings.data_dir |
133 | | - || hasPrefix "/var/lib/garage" cfg.settings.metadata_dir |
134 | | - ) "garage"; |
135 | | - DynamicUser = lib.mkDefault true; |
136 | | - ProtectHome = true; |
137 | | - NoNewPrivileges = true; |
138 | | - EnvironmentFile = lib.optional (cfg.environmentFile != null) cfg.environmentFile; |
139 | | - }; |
| 124 | + serviceConfig = |
| 125 | + let |
| 126 | + paths = lib.flatten ( |
| 127 | + with cfg.settings; |
| 128 | + [ |
| 129 | + metadata_dir |
| 130 | + ] |
| 131 | + # data_dir can either be a string or a list of attrs |
| 132 | + # if data_dir is a list, the actual path will in in the `path` attribute of each item |
| 133 | + # see https://garagehq.deuxfleurs.fr/documentation/reference-manual/configuration/#data_dir |
| 134 | + ++ lib.optional (lib.isList data_dir) (map (item: item.path) data_dir) |
| 135 | + ++ lib.optional (lib.isString data_dir) [ data_dir ] |
| 136 | + ); |
| 137 | + isDefault = lib.hasPrefix "/var/lib/garage"; |
| 138 | + isDefaultStateDirectory = lib.any isDefault paths; |
| 139 | + in |
| 140 | + { |
| 141 | + ExecStart = "${cfg.package}/bin/garage server"; |
| 142 | + |
| 143 | + StateDirectory = lib.mkIf isDefaultStateDirectory "garage"; |
| 144 | + DynamicUser = lib.mkDefault true; |
| 145 | + ProtectHome = true; |
| 146 | + NoNewPrivileges = true; |
| 147 | + EnvironmentFile = lib.optional (cfg.environmentFile != null) cfg.environmentFile; |
| 148 | + ReadWritePaths = lib.filter (x: !(isDefault x)) (lib.flatten [ paths ]); |
| 149 | + }; |
140 | 150 | environment = { |
141 | 151 | RUST_LOG = lib.mkDefault "garage=${cfg.logLevel}"; |
142 | 152 | } // cfg.extraEnvironment; |
|
0 commit comments