nixos/modules/restic.nix

44 lines
1.1 KiB
Nix
Raw Normal View History

{
lib,
config,
...
}: let
cfg = config.services.resticConfigured;
in {
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;
description = "Whether to open the firewall for port ${builtins.toString cfg.port}";
};
2021-06-15 17:25:16 +02:00
};
config = lib.mkIf cfg.enable {
services.restic.server = {
enable = true;
dataDir = cfg.rootDir;
listenAddress = "0.0.0.0:${builtins.toString cfg.port}";
extraFlags = ["--no-auth"];
};
networking.firewall.allowedTCPPorts =
lib.mkIf cfg.openFirewall [cfg.port];
# 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"];
};
};
2021-06-15 17:25:16 +02:00
}