mirror of
https://github.com/nix-community/home-manager.git
synced 2025-12-09 18:41:06 +01:00
borgmatic: optionally exclude HM symlinks from backup
Co-authored-by: Naïm Favier <n@monade.li> Co-authored-by: Robert Helgesson <robert@rycee.net>
This commit is contained in:
parent
2ddd4e151d
commit
a8f5ca239f
5 changed files with 171 additions and 3 deletions
|
|
@ -1 +1,7 @@
|
|||
{ borgmatic-program-basic-configuration = ./basic-configuration.nix; }
|
||||
{
|
||||
borgmatic-program-basic-configuration = ./basic-configuration.nix;
|
||||
borgmatic-program-include-hm-symlinks = ./include-hm-symlinks.nix;
|
||||
borgmatic-program-exclude-hm-symlinks = ./exclude-hm-symlinks.nix;
|
||||
borgmatic-program-exclude-hm-symlinks-nothing-else =
|
||||
./exclude-hm-symlinks-nothing-else.nix;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
let
|
||||
backups = config.programs.borgmatic.backups;
|
||||
excludeFile = pkgs.writeText "excludeFile.txt" "/foo/bar";
|
||||
in {
|
||||
config = {
|
||||
programs.borgmatic = {
|
||||
enable = true;
|
||||
backups = {
|
||||
main = {
|
||||
location = {
|
||||
sourceDirectories = [ "/my-stuff-to-backup" ];
|
||||
repositories = [ "/mnt/disk1" ];
|
||||
excludeHomeManagerSymlinks = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
test.stubs.borgmatic = { };
|
||||
|
||||
nmt.script = ''
|
||||
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
|
||||
assertFileExists $config_file
|
||||
|
||||
yq=${pkgs.yq-go}/bin/yq
|
||||
|
||||
hmExclusionsFile=$($yq '.location.exclude_from[0]' $config_file)
|
||||
expected_content='/home/hm-user/.config/borgmatic.d/main.yaml'
|
||||
|
||||
grep --quiet "$expected_content" "$hmExclusionsFile"
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "Expected to find $expected_content in file $hmExclusionsFile but didn't" >&2
|
||||
exit 1
|
||||
fi
|
||||
'';
|
||||
};
|
||||
}
|
||||
54
tests/modules/programs/borgmatic/exclude-hm-symlinks.nix
Normal file
54
tests/modules/programs/borgmatic/exclude-hm-symlinks.nix
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
let
|
||||
backups = config.programs.borgmatic.backups;
|
||||
excludeFile = pkgs.writeText "excludeFile.txt" "/foo/bar";
|
||||
in {
|
||||
config = {
|
||||
programs.borgmatic = {
|
||||
enable = true;
|
||||
backups = {
|
||||
main = {
|
||||
location = {
|
||||
sourceDirectories = [ "/my-stuff-to-backup" ];
|
||||
repositories = [ "/mnt/disk1" ];
|
||||
excludeHomeManagerSymlinks = true;
|
||||
extraConfig = { exclude_from = [ (toString excludeFile) ]; };
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
test.stubs.borgmatic = { };
|
||||
|
||||
nmt.script = ''
|
||||
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
|
||||
assertFileExists $config_file
|
||||
|
||||
declare -A expectations
|
||||
|
||||
expectations[location.exclude_from[0]]="${excludeFile}"
|
||||
|
||||
yq=${pkgs.yq-go}/bin/yq
|
||||
|
||||
for filter in "''${!expectations[@]}"; do
|
||||
expected_value="''${expectations[$filter]}"
|
||||
actual_value="$($yq ".$filter" $config_file)"
|
||||
|
||||
if [[ "$actual_value" != "$expected_value" ]]; then
|
||||
fail "Expected '$filter' to be '$expected_value' but was '$actual_value'"
|
||||
fi
|
||||
done
|
||||
|
||||
hmExclusionsFile=$($yq '.location.exclude_from[1]' $config_file)
|
||||
expected_content='/home/hm-user/.config/borgmatic.d/main.yaml'
|
||||
|
||||
grep --quiet "$expected_content" "$hmExclusionsFile"
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "Expected to find $expected_content in file $hmExclusionsFile but didn't" >&2
|
||||
exit 1
|
||||
fi
|
||||
'';
|
||||
};
|
||||
}
|
||||
45
tests/modules/programs/borgmatic/include-hm-symlinks.nix
Normal file
45
tests/modules/programs/borgmatic/include-hm-symlinks.nix
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
let
|
||||
backups = config.programs.borgmatic.backups;
|
||||
excludeFile = pkgs.writeText "excludeFile.txt" "/foo/bar";
|
||||
in {
|
||||
config = {
|
||||
programs.borgmatic = {
|
||||
enable = true;
|
||||
backups = {
|
||||
main = {
|
||||
location = {
|
||||
sourceDirectories = [ "/my-stuff-to-backup" ];
|
||||
repositories = [ "/mnt/disk1" ];
|
||||
excludeHomeManagerSymlinks = false;
|
||||
extraConfig = { exclude_from = [ (toString excludeFile) ]; };
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
test.stubs.borgmatic = { };
|
||||
|
||||
nmt.script = ''
|
||||
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
|
||||
assertFileExists $config_file
|
||||
|
||||
declare -A expectations
|
||||
|
||||
expectations[location.exclude_from[0]]="${excludeFile}"
|
||||
|
||||
yq=${pkgs.yq-go}/bin/yq
|
||||
|
||||
for filter in "''${!expectations[@]}"; do
|
||||
expected_value="''${expectations[$filter]}"
|
||||
actual_value="$($yq ".$filter" $config_file)"
|
||||
|
||||
if [[ "$actual_value" != "$expected_value" ]]; then
|
||||
fail "Expected '$filter' to be '$expected_value' but was '$actual_value'"
|
||||
fi
|
||||
done
|
||||
|
||||
'';
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue