infrastructure/nixos-modules/qois/backup-server/default.nix
Fabian Hauser fef2377502
All checks were successful
CI / build (push) Successful in 13m53s
Commit files for public release
2024-10-02 16:57:36 +03:00

53 lines
1.2 KiB
Nix

{
config,
lib,
options,
pkgs,
self,
...
}:
let
cfg = config.qois.backup-server or { };
in
with lib;
{
options.qois.backup-server = {
enable = mkEnableOption "Enable backup hosting";
backupStorageRoot = mkOption {
type = with types; nullOr str;
default = "/mnt/backup";
example = "/mnt/nas/backup";
description = "Path where backups are stored if this host is used as a backup target.";
};
hosts = options.qois.meta.hosts // {
default = config.qois.meta.hosts;
};
};
config = lib.mkIf cfg.enable {
services.borgbackup.repos =
let
hasSshKey = hostName: cfg.hosts.${hostName}.sshKey != null;
mkRepo =
hostName:
(
let
name = "system-${hostName}";
in
{
inherit name;
value = {
path = "${cfg.backupStorageRoot}/${name}";
authorizedKeys = [ cfg.hosts.${hostName}.sshKey ];
};
}
);
hostsWithSshKeys = lib.filter hasSshKey (lib.attrNames cfg.hosts);
in
lib.listToAttrs (map mkRepo hostsWithSshKeys);
};
}