about summary refs log tree commit diff
path: root/lib/tests/modules
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2024-01-28 14:09:27 +0100
committerRobert Hensing <robert@roberthensing.nl>2024-01-28 14:09:27 +0100
commitb78ba9bc68b003288d56bab62693ea28e2cdfd76 (patch)
tree39c14a9f4260f7c2cee7cb25816613a4eb58bc82 /lib/tests/modules
parent0e756e65d5b1134e1364a731b583e233385ac7ae (diff)
downloadnixlib-b78ba9bc68b003288d56bab62693ea28e2cdfd76.tar
nixlib-b78ba9bc68b003288d56bab62693ea28e2cdfd76.tar.gz
nixlib-b78ba9bc68b003288d56bab62693ea28e2cdfd76.tar.bz2
nixlib-b78ba9bc68b003288d56bab62693ea28e2cdfd76.tar.lz
nixlib-b78ba9bc68b003288d56bab62693ea28e2cdfd76.tar.xz
nixlib-b78ba9bc68b003288d56bab62693ea28e2cdfd76.tar.zst
nixlib-b78ba9bc68b003288d56bab62693ea28e2cdfd76.zip
lib.types.unique: Check inner type deeply
This doesn't change uniq. Why not?

- In NixOS it seems that uniq is only used with
  simple types that are fully checked by t.check.

- It exists for much longer and is used more widely.

- I believe we should deprecate it, because unique was
  already better.

- unique can be a proving ground.
Diffstat (limited to 'lib/tests/modules')
-rw-r--r--lib/tests/modules/types-unique.nix27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/tests/modules/types-unique.nix b/lib/tests/modules/types-unique.nix
new file mode 100644
index 000000000000..115be0126975
--- /dev/null
+++ b/lib/tests/modules/types-unique.nix
@@ -0,0 +1,27 @@
+{ lib, ... }:
+let
+  inherit (lib) mkOption types;
+in
+{
+  options.examples = mkOption {
+    type = types.lazyAttrsOf
+      (types.unique
+        { message = "We require a single definition, because seeing the whole value at once helps us maintain critical invariants of our system."; }
+        (types.attrsOf types.str));
+  };
+  imports = [
+    { examples.merged = { b = "bee"; }; }
+    { examples.override = lib.mkForce { b = "bee"; }; }
+  ];
+  config.examples = {
+    merged = {
+      a = "aye";
+    };
+    override = {
+      a = "aye";
+    };
+    badLazyType = {
+      a = true;
+    };
+  };
+}