nixos/borgbackup: Add option `wrapper` (#447400)

authored by scrumplex.net and committed by GitHub 756483bb 6d1ceb6c

+27 -4
+15 -4
nixos/modules/services/backup/borgbackup.nix
··· 216 '' 217 ); 218 219 mkBorgWrapper = 220 name: cfg: 221 - mkWrapperDrv { 222 original = lib.getExe config.services.borgbackup.package; 223 - name = "borg-job-${name}"; 224 set = { 225 BORG_REPO = cfg.repo; 226 } 227 // (mkPassEnv cfg) 228 // cfg.environment; 229 - }; 230 231 # Paths listed in ReadWritePaths must exist before service is started 232 mkTmpfiles = ··· 486 for the specified {option}`paths`. 487 ''; 488 default = "root"; 489 }; 490 491 encryption.mode = lib.mkOption { ··· 898 environment.systemPackages = [ 899 config.services.borgbackup.package 900 ] 901 - ++ (lib.mapAttrsToList mkBorgWrapper jobs); 902 } 903 ); 904 }
··· 216 '' 217 ); 218 219 + # Returns a singleton list, due to usage of lib.optional 220 mkBorgWrapper = 221 name: cfg: 222 + lib.optional (cfg.wrapper != "" && cfg.wrapper != null) (mkWrapperDrv { 223 original = lib.getExe config.services.borgbackup.package; 224 + name = cfg.wrapper; 225 set = { 226 BORG_REPO = cfg.repo; 227 } 228 // (mkPassEnv cfg) 229 // cfg.environment; 230 + }); 231 232 # Paths listed in ReadWritePaths must exist before service is started 233 mkTmpfiles = ··· 487 for the specified {option}`paths`. 488 ''; 489 default = "root"; 490 + }; 491 + 492 + wrapper = lib.mkOption { 493 + type = with lib.types; nullOr str; 494 + description = '' 495 + Name of the wrapper that is installed into {env}`PATH`. 496 + Set to `null` or `""` to disable it altogether. 497 + ''; 498 + default = "borg-job-${name}"; 499 + defaultText = "borg-job-<name>"; 500 }; 501 502 encryption.mode = lib.mkOption { ··· 909 environment.systemPackages = [ 910 config.services.borgbackup.package 911 ] 912 + ++ (lib.flatten (lib.mapAttrsToList mkBorgWrapper jobs)); 913 } 914 ); 915 }
+12
nixos/tests/borgbackup.nix
··· 79 "--exclude-if-present" 80 ".dont backup" 81 ]; 82 postHook = "echo post"; 83 startAt = [ ]; # Do not run automatically 84 }; ··· 87 paths = dataDir; 88 repo = localRepoMount; 89 encryption.mode = "none"; 90 startAt = [ ]; 91 }; 92 ··· 211 "cat /mnt/borg/${dataDir}/${keepFile}" 212 ) 213 214 with subtest("localMount"): 215 # the file system for the repo should not be already mounted 216 client.fail("mount | grep ${localRepoMount}") ··· 222 # Make sure exactly one archive has been created 223 assert int(client.succeed("{} list '${localRepoMount}' | wc -l".format(borg))) > 0 224 225 with subtest("remote"): 226 borg = "BORG_RSH='ssh -oStrictHostKeyChecking=no -i /root/id_ed25519' borg" 227 server.wait_for_unit("sshd.service") ··· 231 232 # Make sure we can't access repos other than the specified one 233 client.fail("{} list borg\@server:wrong".format(borg)) 234 235 # TODO: Make sure that data is actually deleted 236
··· 79 "--exclude-if-present" 80 ".dont backup" 81 ]; 82 + 83 + wrapper = "borg-main"; 84 postHook = "echo post"; 85 startAt = [ ]; # Do not run automatically 86 }; ··· 89 paths = dataDir; 90 repo = localRepoMount; 91 encryption.mode = "none"; 92 + wrapper = null; 93 startAt = [ ]; 94 }; 95 ··· 214 "cat /mnt/borg/${dataDir}/${keepFile}" 215 ) 216 217 + # Make sure custom wrapper name works 218 + client.succeed("command -v borg-main") 219 + 220 with subtest("localMount"): 221 # the file system for the repo should not be already mounted 222 client.fail("mount | grep ${localRepoMount}") ··· 228 # Make sure exactly one archive has been created 229 assert int(client.succeed("{} list '${localRepoMount}' | wc -l".format(borg))) > 0 230 231 + # Make sure disabling wrapper works 232 + client.fail("command -v borg-job-localMount") 233 + 234 with subtest("remote"): 235 borg = "BORG_RSH='ssh -oStrictHostKeyChecking=no -i /root/id_ed25519' borg" 236 server.wait_for_unit("sshd.service") ··· 240 241 # Make sure we can't access repos other than the specified one 242 client.fail("{} list borg\@server:wrong".format(borg)) 243 + 244 + # Make sure default wrapper works 245 + client.succeed("command -v borg-job-remote") 246 247 # TODO: Make sure that data is actually deleted 248