mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-13 21:50:33 +03:00
nixos/borgbackup: add option to allow removable devices
When having backup jobs that persist to a removable device like an external HDD, the directory shouldn't be created by an activation script as this might confuse auto-mounting tools such as udiskie(8). In this case the job will simply fail, with the former approach udiskie ran into some issues as the path `/run/media/ma27/backup` was already there and owned by root.
This commit is contained in:
parent
593867effb
commit
2dfc67517a
1 changed files with 19 additions and 6 deletions
|
@ -8,7 +8,7 @@ let
|
||||||
builtins.substring 0 1 x == "/" # absolute path
|
builtins.substring 0 1 x == "/" # absolute path
|
||||||
|| builtins.substring 0 1 x == "." # relative path
|
|| builtins.substring 0 1 x == "." # relative path
|
||||||
|| builtins.match "[.*:.*]" == null; # not machine:path
|
|| builtins.match "[.*:.*]" == null; # not machine:path
|
||||||
|
|
||||||
mkExcludeFile = cfg:
|
mkExcludeFile = cfg:
|
||||||
# Write each exclude pattern to a new line
|
# Write each exclude pattern to a new line
|
||||||
pkgs.writeText "excludefile" (concatStringsSep "\n" cfg.exclude);
|
pkgs.writeText "excludefile" (concatStringsSep "\n" cfg.exclude);
|
||||||
|
@ -104,12 +104,12 @@ let
|
||||||
install = "install -o ${cfg.user} -g ${cfg.group}";
|
install = "install -o ${cfg.user} -g ${cfg.group}";
|
||||||
in
|
in
|
||||||
nameValuePair "borgbackup-job-${name}" (stringAfter [ "users" ] (''
|
nameValuePair "borgbackup-job-${name}" (stringAfter [ "users" ] (''
|
||||||
# Eensure that the home directory already exists
|
# Ensure that the home directory already exists
|
||||||
# We can't assert createHome == true because that's not the case for root
|
# We can't assert createHome == true because that's not the case for root
|
||||||
cd "${config.users.users.${cfg.user}.home}"
|
cd "${config.users.users.${cfg.user}.home}"
|
||||||
${install} -d .config/borg
|
${install} -d .config/borg
|
||||||
${install} -d .cache/borg
|
${install} -d .cache/borg
|
||||||
'' + optionalString (isLocalPath cfg.repo) ''
|
'' + optionalString (isLocalPath cfg.repo && !cfg.removableDevice) ''
|
||||||
${install} -d ${escapeShellArg cfg.repo}
|
${install} -d ${escapeShellArg cfg.repo}
|
||||||
''));
|
''));
|
||||||
|
|
||||||
|
@ -163,6 +163,13 @@ let
|
||||||
+ " without at least one public key";
|
+ " without at least one public key";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mkRemovableDeviceAssertions = name: cfg: {
|
||||||
|
assertion = !(isLocalPath cfg.repo) -> !cfg.removableDevice;
|
||||||
|
message = ''
|
||||||
|
borgbackup.repos.${name}: repo isn't a local path, thus it can't be a removable device!
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
in {
|
in {
|
||||||
meta.maintainers = with maintainers; [ dotlambda ];
|
meta.maintainers = with maintainers; [ dotlambda ];
|
||||||
|
|
||||||
|
@ -202,6 +209,12 @@ in {
|
||||||
example = "user@machine:/path/to/repo";
|
example = "user@machine:/path/to/repo";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
removableDevice = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = "Whether the repo (which must be local) is a removable device.";
|
||||||
|
};
|
||||||
|
|
||||||
archiveBaseName = mkOption {
|
archiveBaseName = mkOption {
|
||||||
type = types.strMatching "[^/{}]+";
|
type = types.strMatching "[^/{}]+";
|
||||||
default = "${globalConfig.networking.hostName}-${name}";
|
default = "${globalConfig.networking.hostName}-${name}";
|
||||||
|
@ -511,7 +524,6 @@ in {
|
||||||
type = types.attrsOf (types.submodule (
|
type = types.attrsOf (types.submodule (
|
||||||
{ ... }: {
|
{ ... }: {
|
||||||
options = {
|
options = {
|
||||||
|
|
||||||
path = mkOption {
|
path = mkOption {
|
||||||
type = types.path;
|
type = types.path;
|
||||||
description = ''
|
description = ''
|
||||||
|
@ -598,7 +610,8 @@ in {
|
||||||
(with config.services.borgbackup; {
|
(with config.services.borgbackup; {
|
||||||
assertions =
|
assertions =
|
||||||
mapAttrsToList mkPassAssertion jobs
|
mapAttrsToList mkPassAssertion jobs
|
||||||
++ mapAttrsToList mkKeysAssertion repos;
|
++ mapAttrsToList mkKeysAssertion repos
|
||||||
|
++ mapAttrsToList mkRemovableDeviceAssertions jobs;
|
||||||
|
|
||||||
system.activationScripts = mapAttrs' mkActivationScript jobs;
|
system.activationScripts = mapAttrs' mkActivationScript jobs;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue