Skip to content

Commit 4a75ef3

Browse files
authored
nixos/garage: add user-given path to ReadWritePaths (NixOS#373114)
2 parents 151b7f7 + 97f2724 commit 4a75ef3

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

nixos/modules/services/web-servers/garage.nix

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,14 @@ let
1111
cfg = config.services.garage;
1212
toml = pkgs.formats.toml { };
1313
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;
2114
in
2215
{
2316
meta = {
2417
doc = ./garage.md;
25-
maintainers = [ maintainers.mjm ];
18+
maintainers = with lib.maintainers; [
19+
mjm
20+
cything
21+
];
2622
};
2723

2824
options.services.garage = {
@@ -44,13 +40,13 @@ in
4440
};
4541

4642
logLevel = mkOption {
47-
type = types.enum ([
43+
type = types.enum [
4844
"error"
4945
"warn"
5046
"info"
5147
"debug"
5248
"trace"
53-
]);
49+
];
5450
default = "info";
5551
example = "debug";
5652
description = "Garage log level, see <https://garagehq.deuxfleurs.fr/documentation/quick-start/#launching-the-garage-server> for examples.";
@@ -125,18 +121,32 @@ in
125121
restartTriggers = [
126122
configFile
127123
] ++ (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+
};
140150
environment = {
141151
RUST_LOG = lib.mkDefault "garage=${cfg.logLevel}";
142152
} // cfg.extraEnvironment;

0 commit comments

Comments
 (0)