@@ -8,7 +8,7 @@ let
88 builtins.substring 0 1 x == "/" # absolute path
99 || builtins.substring 0 1 x == "." # relative path
1010 || builtins.match "[.*:.*]" == null; # not machine:path
11−
11+
1212 mkExcludeFile = cfg:
1313 # Write each exclude pattern to a new line
1414 pkgs.writeText "excludefile" (concatStringsSep "\n" cfg.exclude);
@@ -104,12 +104,12 @@ let
104104 install = "install -o ${cfg.user} -g ${cfg.group}";
105105 in
106106 nameValuePair "borgbackup-job-${name}" (stringAfter [ "users" ] (''
107− # Eensure that the home directory already exists
107+ # Ensure that the home directory already exists
108108 # We can't assert createHome == true because that's not the case for root
109− cd "${config.users.users.${cfg.user}.home}"
109+ cd "${config.users.users.${cfg.user}.home}"
110110 ${install} -d .config/borg
111111 ${install} -d .cache/borg
112− '' + optionalString (isLocalPath cfg.repo) ''
112+ '' + optionalString (isLocalPath cfg.repo && !cfg.removableDevice) ''
113113 ${install} -d ${escapeShellArg cfg.repo}
114114 ''));
115115
@@ -163,6 +163,13 @@ let
163163 + " without at least one public key";
164164 };
165165
166+ mkRemovableDeviceAssertions = name: cfg: {
167+ assertion = !(isLocalPath cfg.repo) -> !cfg.removableDevice;
168+ message = ''
169+ borgbackup.repos.${name}: repo isn't a local path, thus it can't be a removable device!
170+ '';
171+ };
172+
166173in {
167174 meta.maintainers = with maintainers; [ dotlambda ];
168175
@@ -202,6 +209,12 @@ in {
202209 example = "user@machine:/path/to/repo";
203210 };
204211
212+ removableDevice = mkOption {
213+ type = types.bool;
214+ default = false;
215+ description = "Whether the repo (which must be local) is a removable device.";
216+ };
217+
205218 archiveBaseName = mkOption {
206219 type = types.strMatching "[^/{}]+";
207220 default = "${globalConfig.networking.hostName}-${name}";
@@ -511,7 +524,6 @@ in {
511524 type = types.attrsOf (types.submodule (
512525 { ... }: {
513526 options = {
514−
515527 path = mkOption {
516528 type = types.path;
517529 description = ''
@@ -598,7 +610,8 @@ in {
598610 (with config.services.borgbackup; {
599611 assertions =
600612 mapAttrsToList mkPassAssertion jobs
601− ++ mapAttrsToList mkKeysAssertion repos;
613+ ++ mapAttrsToList mkKeysAssertion repos
614+ ++ mapAttrsToList mkRemovableDeviceAssertions jobs;
602615
603616 system.activationScripts = mapAttrs' mkActivationScript jobs;
604617