From 2954aa29441a1a98901362e4d35515875761ad65 Mon Sep 17 00:00:00 2001 From: Jess Date: Mon, 19 Jan 2026 13:26:39 +1300 Subject: [PATCH] rclone: add `autoMount` option --- modules/programs/rclone.nix | 6 ++- tests/integration/standalone/rclone/mount.nix | 37 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/modules/programs/rclone.nix b/modules/programs/rclone.nix index 275cc615..a660db89 100644 --- a/modules/programs/rclone.nix +++ b/modules/programs/rclone.nix @@ -113,6 +113,10 @@ in options = { enable = lib.mkEnableOption "this mount"; + autoMount = lib.mkEnableOption "automatic mounting" // { + default = true; + }; + logLevel = lib.mkOption { type = lib.types.nullOr ( lib.types.enum [ @@ -381,7 +385,7 @@ in Restart = "on-failure"; }; - Install.WantedBy = [ "default.target" ]; + Install.WantedBy = lib.optional mount.autoMount "default.target"; } ) ) (lib.attrsToList remote.mounts) diff --git a/tests/integration/standalone/rclone/mount.nix b/tests/integration/standalone/rclone/mount.nix index 70938a33..ff9e662d 100644 --- a/tests/integration/standalone/rclone/mount.nix +++ b/tests/integration/standalone/rclone/mount.nix @@ -41,6 +41,23 @@ let }; }; }; + + non-automounted-remote = { + config = { + type = "sftp"; + host = "remote"; + user = "alice"; + key_pem = "${keyPem}"; + known_hosts = "${sshKeys.snakeOilEd25519PublicKey}"; + }; + mounts = { + "/home/alice/even-more-files" = { + enable = true; + autoMount = false; + mountPoint = "/home/alice/even-more-files"; + }; + }; + }; }; } ''; @@ -120,5 +137,25 @@ in expected = "started" assert expected in test_log, \ f"Mounted file does not have expected contents. Expected {test_log} to contain \"{expected}\"" + + with subtest("Non-automounted mounts aren't started"): + svc_name = "rclone-mount:.home.alice.even-more-files@non-automounted-remote.service" + + _status, out = machine.systemctl(f"show -p WantedBy --value {svc_name}", "alice") + assert not "default.target" in out, \ + f"Non-automounted service, {svc_name}, contains \"WantedBy\" default.target" + + fail_as_alice("ls /home/alice/even-more-files") + + succeed_as_alice( + "mkdir /home/alice/even-more-files", + box=remote + ) + + status, _out = machine.systemctl(f"start {svc_name}", "alice") + assert status == 0, \ + f"Failed to start {svc_name}" + + succeed_as_alice("ls /home/alice/even-more-files") ''; }