2022-03-23 13:10:18 +01:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
cfg = config.services.resticConfigured;
|
2022-01-13 21:23:36 +01:00
|
|
|
in {
|
2022-02-19 16:01:47 +01:00
|
|
|
options.services.resticConfigured = with lib; {
|
|
|
|
enable = mkEnableOption "Configured Restic rest server service";
|
|
|
|
rootDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "Path to use for storage";
|
|
|
|
};
|
|
|
|
port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 8000;
|
|
|
|
description = "Port to use for the rest server";
|
|
|
|
};
|
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-03-23 13:10:18 +01:00
|
|
|
description = "Whether to open the firewall for port ${builtins.toString cfg.port}";
|
2022-02-19 16:01:47 +01:00
|
|
|
};
|
2021-06-15 17:25:16 +02:00
|
|
|
};
|
2022-01-13 21:23:36 +01:00
|
|
|
|
2022-02-19 16:01:47 +01:00
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
services.restic.server = {
|
|
|
|
enable = true;
|
|
|
|
dataDir = cfg.rootDir;
|
|
|
|
listenAddress = "0.0.0.0:${builtins.toString cfg.port}";
|
2022-03-23 13:10:18 +01:00
|
|
|
extraFlags = ["--no-auth"];
|
2022-02-19 16:01:47 +01:00
|
|
|
};
|
2022-01-13 21:23:36 +01:00
|
|
|
|
2022-02-19 16:01:47 +01:00
|
|
|
networking.firewall.allowedTCPPorts =
|
2022-03-23 13:10:18 +01:00
|
|
|
lib.mkIf cfg.openFirewall [cfg.port];
|
2022-02-19 16:01:47 +01:00
|
|
|
|
|
|
|
# TODO: This should be moved
|
|
|
|
systemd.services.restic-rest-server.unitConfig = {
|
2022-09-26 17:11:16 +02:00
|
|
|
Requires = lib.mkForce ["network.target"];
|
|
|
|
After = lib.mkForce ["network.target"];
|
2022-02-19 16:01:47 +01:00
|
|
|
};
|
|
|
|
};
|
2021-06-15 17:25:16 +02:00
|
|
|
}
|