Merge pull request 'localbackup: rename mountHook/umountHook to preMountHook/postUnmountHook' (#1050) from Mic92-main into main
This commit is contained in:
commit
4ff262fd60
@ -115,10 +115,10 @@
|
|||||||
|
|
||||||
clan.localbackup.targets.hdd = {
|
clan.localbackup.targets.hdd = {
|
||||||
directory = "/mnt/external-disk";
|
directory = "/mnt/external-disk";
|
||||||
mountHook = ''
|
preMountHook = ''
|
||||||
touch /run/mount-external-disk
|
touch /run/mount-external-disk
|
||||||
'';
|
'';
|
||||||
unmountHook = ''
|
postUnmountHook = ''
|
||||||
touch /run/unmount-external-disk
|
touch /run/unmount-external-disk
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
@ -43,7 +43,7 @@ in
|
|||||||
targets = lib.mkOption {
|
targets = lib.mkOption {
|
||||||
type = lib.types.attrsOf (
|
type = lib.types.attrsOf (
|
||||||
lib.types.submodule (
|
lib.types.submodule (
|
||||||
{ name, config, ... }:
|
{ name, ... }:
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
name = lib.mkOption {
|
name = lib.mkOption {
|
||||||
@ -60,14 +60,24 @@ in
|
|||||||
default = null;
|
default = null;
|
||||||
description = "mountpoint of the directory to backup. If set, the directory will be mounted before the backup and unmounted afterwards";
|
description = "mountpoint of the directory to backup. If set, the directory will be mounted before the backup and unmounted afterwards";
|
||||||
};
|
};
|
||||||
mountHook = lib.mkOption {
|
preMountHook = lib.mkOption {
|
||||||
type = lib.types.nullOr lib.types.lines;
|
type = lib.types.nullOr lib.types.lines;
|
||||||
default = if config.mountpoint != null then "mount ${config.mountpoint}" else null;
|
default = null;
|
||||||
description = "Shell commands to run before the directory is mounted";
|
description = "Shell commands to run before the directory is mounted";
|
||||||
};
|
};
|
||||||
unmountHook = lib.mkOption {
|
postMountHook = lib.mkOption {
|
||||||
type = lib.types.nullOr lib.types.lines;
|
type = lib.types.nullOr lib.types.lines;
|
||||||
default = if config.mountpoint != null then "umount ${config.mountpoint}" else null;
|
default = null;
|
||||||
|
description = "Shell commands to run after the directory is mounted";
|
||||||
|
};
|
||||||
|
preUnmountHook = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.lines;
|
||||||
|
default = null;
|
||||||
|
description = "Shell commands to run before the directory is unmounted";
|
||||||
|
};
|
||||||
|
postUnmountHook = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.lines;
|
||||||
|
default = null;
|
||||||
description = "Shell commands to run after the directory is unmounted";
|
description = "Shell commands to run after the directory is unmounted";
|
||||||
};
|
};
|
||||||
preBackupHook = lib.mkOption {
|
preBackupHook = lib.mkOption {
|
||||||
@ -182,16 +192,26 @@ in
|
|||||||
name: target:
|
name: target:
|
||||||
pkgs.writeShellScriptBin ("localbackup-mount-" + name) ''
|
pkgs.writeShellScriptBin ("localbackup-mount-" + name) ''
|
||||||
set -efu -o pipefail
|
set -efu -o pipefail
|
||||||
${target.mountHook}
|
${lib.optionalString (target.preMountHook != null) target.preMountHook}
|
||||||
|
${lib.optionalString (target.mountpoint != null) ''
|
||||||
|
if ! ${pkgs.util-linux}/bin/mountpoint -q ${lib.escapeShellArg target.mountpoint}; then
|
||||||
|
${pkgs.util-linux}/bin/mount ${lib.escapeShellArg target.mountpoint}
|
||||||
|
fi
|
||||||
|
''}
|
||||||
|
${lib.optionalString (target.postMountHook != null) target.postMountHook}
|
||||||
''
|
''
|
||||||
) (lib.filterAttrs (_name: target: target.mountHook != null) cfg.targets))
|
) cfg.targets)
|
||||||
++ lib.mapAttrsToList (
|
++ lib.mapAttrsToList (
|
||||||
name: target:
|
name: target:
|
||||||
pkgs.writeShellScriptBin ("localbackup-unmount-" + name) ''
|
pkgs.writeShellScriptBin ("localbackup-unmount-" + name) ''
|
||||||
set -efu -o pipefail
|
set -efu -o pipefail
|
||||||
${target.unmountHook}
|
${lib.optionalString (target.preUnmountHook != null) target.preUnmountHook}
|
||||||
|
${lib.optionalString (
|
||||||
|
target.mountpoint != null
|
||||||
|
) "${pkgs.util-linux}/bin/umount ${lib.escapeShellArg target.mountpoint}"}
|
||||||
|
${lib.optionalString (target.postUnmountHook != null) target.postUnmountHook}
|
||||||
''
|
''
|
||||||
) (lib.filterAttrs (_name: target: target.unmountHook != null) cfg.targets);
|
) cfg.targets;
|
||||||
|
|
||||||
clanCore.backups.providers.localbackup = {
|
clanCore.backups.providers.localbackup = {
|
||||||
# TODO list needs to run locally or on the remote machine
|
# TODO list needs to run locally or on the remote machine
|
||||||
|
Loading…
Reference in New Issue
Block a user