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