diff --git a/modules/programs/rclone.nix b/modules/programs/rclone.nix index 8f85fc09..275cc615 100644 --- a/modules/programs/rclone.nix +++ b/modules/programs/rclone.nix @@ -356,8 +356,8 @@ in mount-path = name; mount = value; in - [ - (lib.nameValuePair "rclone-mount:${replaceSlashes mount-path}@${remote-name}" { + lib.optional mount.enable ( + lib.nameValuePair "rclone-mount:${replaceSlashes mount-path}@${remote-name}" { Unit = { Description = "Rclone FUSE daemon for ${remote-name}:${mount-path}"; }; @@ -382,8 +382,8 @@ in }; Install.WantedBy = [ "default.target" ]; - }) - ] + } + ) ) (lib.attrsToList remote.mounts) ) ( diff --git a/tests/integration/standalone/rclone/mount.nix b/tests/integration/standalone/rclone/mount.nix index 357ffc36..70938a33 100644 --- a/tests/integration/standalone/rclone/mount.nix +++ b/tests/integration/standalone/rclone/mount.nix @@ -26,6 +26,21 @@ let }; }; }; + + alices-disabled-remote = { + config = { + type = "sftp"; + host = "remote"; + user = "alice"; + key_pem = "${keyPem}"; + known_hosts = "${sshKeys.snakeOilEd25519PublicKey}"; + }; + mounts = { + "/home/alice/other-files" = { + mountPoint = "/home/alice/other-files"; + }; + }; + }; }; } ''; @@ -43,6 +58,23 @@ in remote.wait_for_unit("network.target") remote.wait_for_unit("multi-user.target") + succeed_as_alice( + "mkdir -p /home/alice/.ssh", + "install -m644 ${module} /home/alice/.config/home-manager/test-remote.nix" + ) + + actual = succeed_as_alice("home-manager switch") + expected = "rclone-config.service" + assert "Starting units: " in actual and expected in actual, \ + f"expected home-manager switch to contain {expected}, but got {actual}" + + with subtest("Disabled remotes aren't created"): + svc_name = "rclone-mount:.home.alice.other-files@alices-disabled-remote.service" + + status, out = machine.systemctl(f"status {svc_name}", "alice") + assert status != 0, \ + f"The disabled mount {svc_name} was created" + with subtest("Mount a remote (sftp)"): # https://rclone.org/commands/rclone_mount/#vfs-directory-cache # Sending a SIGHUP evicts every dcache entry @@ -55,16 +87,6 @@ in box=remote ) - succeed_as_alice( - "mkdir -p /home/alice/.ssh", - "install -m644 ${module} /home/alice/.config/home-manager/test-remote.nix" - ) - - actual = succeed_as_alice("home-manager switch") - expected = "rclone-config.service" - assert "Starting units: " in actual and expected in actual, \ - f"expected home-manager switch to contain {expected}, but got {actual}" - # remote -> machine succeed_as_alice( "mkdir /home/alice/files",