Skip to content

Commit

Permalink
+
Browse files Browse the repository at this point in the history
  • Loading branch information
oluceps committed Oct 19, 2024
1 parent d1d8936 commit 55ad5c3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
14 changes: 4 additions & 10 deletions hosts/hastur/backup.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@
services.rustic = {
backups = {
critic = {
profiles = [
"general"
"on-kaambl"
];
credentials = (
(map (lib.genCredPath config)) [
"general.toml"
"on-kaambl.toml"
]
);
profiles = lib.genAttrs [
"general.toml"
"on-kaambl.toml"
] (n: config.age.secrets.${n}.path);

timerConfig = {
OnCalendar = "*-*-* 2,14:00:00";
Expand Down
31 changes: 17 additions & 14 deletions modules/rustic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ let
cfg = config.services.rustic;
inherit (lib)
mkOption
foldl'
types
removeSuffix
mkPackageOption
mkEnableOption
attrNames
attrValues
mkIf
mapAttrs'
filterAttrs
nameValuePair
optional
;
inherit (utils.systemdUtils.unitOptions) unitOption;

in
{
# disabledModules = [ "services/networking/rustic.nix" ];
disabledModules = [ "services/backup/rustic-rs.nix" ];
options.services.rustic = {
backups = mkOption {
description = "list of rustic instance";
Expand All @@ -31,14 +33,9 @@ in
options = {
package = mkPackageOption pkgs "rustic" { };
profiles = mkOption {
type = with types; listOf str;
default = [ ];
description = "profiles";
};
credentials = mkOption {
type = with types; listOf str;
default = [ ];
description = "credential (profile) list";
type = with types; attrsOf str;
default = { };
description = "profiles file = path";
};
timerConfig = mkOption {
type = types.nullOr (types.attrsOf unitOption);
Expand All @@ -65,6 +62,12 @@ in
};
config = mkIf (cfg.backups != [ ]) {
environment.systemPackages = [ pkgs.rustic ];
environment.etc = mapAttrs' (name: path: {
name = "rustic/" + name;
value = {
source = path;
};
}) (foldl' (acc: i: acc // i.profiles) { } (attrValues cfg.backups));

systemd.services = mapAttrs' (
name: opts:
Expand All @@ -86,18 +89,18 @@ in
RuntimeDirectory = "rustic-backups-${name}";
CacheDirectory = "rustic-backups-${name}";
CacheDirectoryMode = "0700";
WorkingDirectory = "%E{CREDENTIALS_DIRECTORY}";
PrivateTmp = true;
ExecStart =
let
profileArgs = lib.concatStringsSep " " (map (i: "-P ${i}") opts.profiles);
profileArgs = lib.concatStringsSep " " (
map (i: "-P ${removeSuffix ".toml" i}") (attrNames opts.profiles)
);
baseCmd = (lib.getExe' opts.package "rustic") + " " + profileArgs;
in
map (n: baseCmd + " " + n) [
"backup"
"check"
];
LoadCredential = opts.credentials;
};
}
) cfg.backups;
Expand Down

0 comments on commit 55ad5c3

Please sign in to comment.