From 7853236fae80bb625c319df8d730cad2a5584f26 Mon Sep 17 00:00:00 2001 From: Jess Date: Sun, 23 Mar 2025 12:33:23 +1300 Subject: [PATCH] rclone: ensure remotes have a type field --- modules/programs/rclone.nix | 11 ++++++++++- tests/integration/standalone/rclone/default.nix | 15 +++++++++++++++ tests/integration/standalone/rclone/no-type.nix | 9 +++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/integration/standalone/rclone/no-type.nix diff --git a/modules/programs/rclone.nix b/modules/programs/rclone.nix index 55b2bf99a..7d0b87315 100644 --- a/modules/programs/rclone.nix +++ b/modules/programs/rclone.nix @@ -17,7 +17,16 @@ in { options = { config = lib.mkOption { type = with lib.types; - attrsOf (nullOr (oneOf [ bool int float str ])); + let + baseType = attrsOf (nullOr (oneOf [ bool int float str ])); + + # Should we verify whether type constitutes a valid remote? + remoteConfigType = addCheck baseType (lib.hasAttr "type") // { + name = "rcloneRemoteConfig"; + description = + "An attribute set containing a remote type and options."; + }; + in remoteConfigType; default = { }; description = '' Regular configuration options as described in rclone's documentation diff --git a/tests/integration/standalone/rclone/default.nix b/tests/integration/standalone/rclone/default.nix index de4684efc..75b5e6ff0 100644 --- a/tests/integration/standalone/rclone/default.nix +++ b/tests/integration/standalone/rclone/default.nix @@ -98,6 +98,21 @@ ./secrets-with-whitespace.conf } /home/alice/.config/rclone/rclone.conf") + with subtest("Un-typed remote"): + succeed_as_alice("install -m644 ${ + ./no-type.nix + } /home/alice/.config/home-manager/test-remote.nix") + + actual = fail_as_alice("home-manager switch") + expected = "Activating createRcloneConfig" + assert expected not in actual, \ + f"expected home-manager switch to contain {expected}, but got {actual}" + + expected = "An attribute set containing a remote type and options." + assert expected not in actual, \ + f"expected home-manager switch to contain {expected}, but got {actual}" + + # TODO: verify correct activation order with the agenix and sops hm modules logout_alice() diff --git a/tests/integration/standalone/rclone/no-type.nix b/tests/integration/standalone/rclone/no-type.nix new file mode 100644 index 000000000..bce7adc2e --- /dev/null +++ b/tests/integration/standalone/rclone/no-type.nix @@ -0,0 +1,9 @@ +{ + programs.rclone.remotes = { + alices-cool-remote-v4.config = { + description = "this value does not have a type"; + some-key = "value pairs"; + another-key-value = "pair"; + }; + }; +}