mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-01-21 14:01:34 +01:00
restic: Rename option resticBackups to restic.backups
This commit is contained in:
parent
9ec0c676be
commit
ba78828f4f
10 changed files with 17 additions and 17 deletions
57
modules/system/services/restic/restore.nix
Normal file
57
modules/system/services/restic/restore.nix
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
backupsWithRestoreCommand =
|
||||
config.custom.services.restic.backups
|
||||
|> lib.filterAttrs (_: value: value.enable)
|
||||
|> lib.filterAttrs (_: value: value.restoreCommand.enable);
|
||||
in
|
||||
{
|
||||
options.custom.services.restic.backups = lib.mkOption {
|
||||
type = lib.types.attrsOf (
|
||||
lib.types.submodule {
|
||||
options.restoreCommand = {
|
||||
enable = lib.mkEnableOption "" // {
|
||||
default = true;
|
||||
};
|
||||
preRestore = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "";
|
||||
};
|
||||
postRestore = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "";
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
config = {
|
||||
environment.systemPackages =
|
||||
backupsWithRestoreCommand
|
||||
|> lib.mapAttrsToList (
|
||||
name: value:
|
||||
pkgs.writeShellApplication {
|
||||
name = "restic-restore-${name}";
|
||||
text =
|
||||
let
|
||||
inherit (value) conflictingService;
|
||||
inherit (value.restoreCommand) preRestore postRestore;
|
||||
hasconflictingService = conflictingService != null;
|
||||
in
|
||||
''
|
||||
${lib.optionalString hasconflictingService "systemctl stop ${conflictingService}"}
|
||||
${preRestore}
|
||||
restic-${name} restore latest --target /
|
||||
${postRestore}
|
||||
${lib.optionalString hasconflictingService "systemctl start ${conflictingService}"}
|
||||
'';
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue