From 2f1b912aa3bffc05558070d625cc33b32b6a5a4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20R=C3=B6ger?= Date: Sun, 6 Apr 2025 22:40:24 +0200 Subject: [PATCH] fix borg-server --- hosts/harbor/configuration.nix | 3 ++- modules/services/borg-server.nix | 16 +++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/hosts/harbor/configuration.nix b/hosts/harbor/configuration.nix index 13a9d41..571dda3 100644 --- a/hosts/harbor/configuration.nix +++ b/hosts/harbor/configuration.nix @@ -6,6 +6,7 @@ imports = [ ./hardware-configuration.nix ../../modules/services/nextcloud-instance.nix + ../../modules/services/borg-server.nix ]; # Secret management @@ -53,7 +54,7 @@ services.nextcloud-instance.instanceFQDN = "nextcloud.jroeger.de"; services.borg-server.enable = true; - services.borg-server.repositories.comfy-station.ssh_public_key = builtins.readFile (../../static/keys/ + "borg-jonas@comfy-station.pub"); + services.borg-server.repositories.comfy-station.ssh_public_key = builtins.readFile (../../static/keys + "/borg-jonas@comfy-station.pub"); # Allow unfree packages nixpkgs.config.allowUnfree = true; diff --git a/modules/services/borg-server.nix b/modules/services/borg-server.nix index 146840f..3edf832 100644 --- a/modules/services/borg-server.nix +++ b/modules/services/borg-server.nix @@ -8,6 +8,12 @@ in { options.services.borg-server = { enable = lib.mkEnableOption "Enable the borg server"; + package = lib.mkOption { + type = lib.types.package; + default = pkgs.borgbackup; + example = "pkgs.borgbackup"; + description = "The borg package to use"; + }; borg_user = lib.mkOption { type = lib.types.str; example = "borg"; @@ -25,6 +31,7 @@ in { options = { name = lib.mkOption { type = lib.types.nullOr (lib.types.strMatching "^[a-zA-Z0-9._-]+$"); + default = null; example = "borg-repo"; description = "The name of the borg repository. If null, use key of attrset"; }; @@ -45,11 +52,10 @@ in { home = cfg.repositories_path; createHome = true; extraGroups = ["borg"]; - openSSH.authorizedKeys.keys = builtins.attrValues ( - builtins.mapAttrs - (key: repo: "command=\"${pkgs.borg}/bin/borg serve --restrict-to-path=${cfg.repositories_path}/${repo.name or key}\", restrict ${repo.ssh_public_key}") - cfg.repositories - ); + openssh.authorizedKeys.keys = + lib.attrsets.mapAttrsToList + (key: repo: "command=\"${cfg.package}/bin/borg serve --restrict-to-path=${cfg.repositories_path}/${lib.defaultTo key repo.name}\", restrict ${repo.ssh_public_key}") + cfg.repositories; }; }; }