fork/home-manager
git clone https://git.julia.blue/fork/home-manager
a4218048
master
1{ config , pkgs , ...} : 2 3let 4 5boolToString = bool :if bool then "true" else "false" ; 6backups = config . programs . borgmatic . backups ; 7 8in { 9programs . borgmatic = { 10enable = true ; 11backups = { 12main = { 13location = { 14sourceDirectories = [ "/my-stuff-to-backup" ]; 15repositories = [ 16"/mnt/disk1" 17{ path = "/mnt/disk2" ; } 18{ 19path = "/mnt/disk3" ; 20label = "disk3" ; 21} 22]; 23extraConfig = { 24one_file_system = true ; 25exclude_patterns = [ "*.swp" ]; 26}; 27}; 28 29storage = { 30encryptionPasscommand = "fetch-the-password.sh" ; 31extraConfig = { checkpoint_interval = 200 ; }; 32}; 33 34retention = { 35keepWithin = "14d" ; 36keepSecondly = 12 ; 37extraConfig = { prefix = "hostname" ; }; 38}; 39 40consistency = { 41checks = [ 42{ 43name = "repository" ; 44frequency = "2 weeks" ; 45} 46{ 47name = "archives" ; 48frequency = "4 weeks" ; 49} 50]; 51 52extraConfig = { prefix = "hostname" ; }; 53}; 54 55output = { extraConfig = { color = false ; }; }; 56 57hooks = { 58extraConfig = { before_actions = [ "echo Starting actions." ]; }; 59}; 60}; 61}; 62}; 63 64test . stubs . borgmatic = { }; 65 66nmt . script = '' 67config_file = $ TESTED /home-files/.config/borgmatic.d/main.yaml 68assertFileExists $ config_file 69 70declare -A expectations 71 72expectations [source_directories[0]]= " ${ 73builtins . elemAt backups . main . location . sourceDirectories 0 74} " 75expectations[repositories[0].path]=" ${ 76( builtins . elemAt backups . main . location . repositories 0 ). path 77} " 78expectations[repositories[1].path]=" ${ 79( builtins . elemAt backups . main . location . repositories 1 ). path 80} " 81expectations[repositories[2].path]=" ${ 82( builtins . elemAt backups . main . location . repositories 2 ). path 83} " 84expectations[repositories[2].label]=" ${ 85( builtins . elemAt backups . main . location . repositories 2 ). label 86} " 87expectations[one_file_system]=" ${ 88boolToString backups . main . location . extraConfig . one_file_system 89} " 90expectations[exclude_patterns[0]]=" ${ 91builtins . elemAt backups . main . location . extraConfig . exclude_patterns 0 92} " 93 94expectations[encryption_passcommand]=" ${ backups . main . storage . encryptionPasscommand } " 95expectations[checkpoint_interval]=" ${ 96toString backups . main . storage . extraConfig . checkpoint_interval 97} " 98 99expectations[keep_within]=" ${ backups . main . retention . keepWithin } " 100expectations[keep_secondly]=" ${ 101toString backups . main . retention . keepSecondly 102} " 103expectations[prefix]=" ${ backups . main . retention . extraConfig . prefix } " 104 105expectations[checks[0].name]=" ${ 106( builtins . elemAt backups . main . consistency . checks 0 ). name 107} " 108expectations[checks[0].frequency]=" ${ 109( builtins . elemAt backups . main . consistency . checks 0 ). frequency 110} " 111expectations[checks[1].name]=" ${ 112( builtins . elemAt backups . main . consistency . checks 1 ). name 113} " 114expectations[checks[1].frequency]=" ${ 115( builtins . elemAt backups . main . consistency . checks 1 ). frequency 116} " 117expectations[prefix]=" ${ backups . main . consistency . extraConfig . prefix } " 118expectations[color]=" ${ boolToString backups . main . output . extraConfig . color } " 119expectations[before_actions[0]]=" ${ 120builtins . elemAt backups . main . hooks . extraConfig . before_actions 0 121} " 122 123yq= ${ pkgs . yq-go } /bin/yq 124 125for filter in "'' $ { !expectations[@]} "; do 126expected_value="'' $ { expectations [ $ filter ]}" 127actual_value=" $( $ yq ". $ filter " $ config_file ) " 128 129if [[ " $ actual_value " != " $ expected_value " ]]; then 130fail " Expected '$filter' to be '$expected_value' but was '$actual_value'" 131fi 132done 133 134one_file_system= $( $ yq ".one_file_system" $ config_file ) 135if [[ $ one_file_system != "true" ]]; then 136fail "Expected one_file_system to be true but it was $ one_file_system " 137fi 138'' ; 139}