aboutsummaryrefslogtreecommitdiff
path: root/modules/backup/web.nix
diff options
context:
space:
mode:
authorMax Audron <audron@cocaine.farm>2026-01-07 13:14:18 +0100
committerMax Audron <audron@cocaine.farm>2026-01-07 13:14:18 +0100
commitcdae0fb511851bf703a6fce3db2062b02b0e4c05 (patch)
tree985608c2e6943cb986ba02b4d0c30e886ff2d287 /modules/backup/web.nix
parentteamspeak switcharoo (diff)
add kopia module
Diffstat (limited to 'modules/backup/web.nix')
-rw-r--r--modules/backup/web.nix75
1 files changed, 75 insertions, 0 deletions
diff --git a/modules/backup/web.nix b/modules/backup/web.nix
new file mode 100644
index 0000000..9937315
--- /dev/null
+++ b/modules/backup/web.nix
@@ -0,0 +1,75 @@
+{
+ pkgs,
+ lib,
+ config,
+ mkInstanceServices,
+ ...
+}:
+let
+ instanceType = lib.types.submodule {
+ options = {
+ web = {
+ enable = lib.mkEnableOption "enable Kopia web interface";
+ guiAddress = lib.mkOption {
+ type = lib.types.str;
+ default = "127.0.0.1:51515";
+ };
+ serverUsername = lib.mkOption {
+ type = lib.types.str;
+ default = "admin";
+ description = "Username for the Kopia web server(basic auth).";
+ };
+ environmentFile = lib.mkOption {
+ type = lib.types.nullOr lib.types.path;
+ default = null;
+ description = "File containing environment variables for kopia web server like password.";
+ };
+ };
+ };
+ };
+in
+{
+ options.services.kopia.instances = lib.mkOption {
+ type = lib.types.attrsOf instanceType;
+ };
+
+ config = lib.mkIf config.services.kopia.enable {
+ # systemd service for repositories open
+ systemd.services =
+ let
+ mkWebService =
+ # refactor with mkRepositoryArgs
+ name: instance:
+ lib.attrsets.nameValuePair "kopia-web-${name}" {
+ description = "Kopia S3 web service";
+ wants = [
+ "kopia-repository-${name}.service"
+ ];
+ after = [ "kopia-repository-${name}.service" ];
+ environment = {
+ KOPIA_SERVER_USERNAME = instance.web.serverUsername;
+ };
+ script = ''
+ export KOPIA_SERVER_USERNAME=${instance.web.serverUsername}
+ # Start Kopia web server
+ ${pkgs.kopia}/bin/kopia server start --insecure --address ${instance.web.guiAddress}
+ '';
+ serviceConfig = {
+ Type = "simple";
+ User = "${instance.user}";
+ WorkingDirectory = "~";
+ SetLoginEnvironment = true;
+ EnvironmentFile = lib.mkIf (instance.web.environmentFile != null) instance.web.environmentFile;
+ # retry on failure
+ Restart = "on-failure";
+ # wait 30 seconds before restarting
+ RestartSec = "30";
+ # limit the number of restarts to 5 in 1 day
+ StartLimitIntervalSec = "1d";
+ StartLimitBurst = "5";
+ };
+ };
+ in
+ mkInstanceServices config.services.kopia.instances mkWebService;
+ };
+}