Skip to content

Commit c010709

Browse files
committed
lib/types: use unspecified instead of anything, add steppedInt and steppedIntBetween
1 parent 259e951 commit c010709

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

lib/types.nix

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
;
2626

2727
# keep-sorted start case=no block=yes newline_separated=yes
28-
attrs = delib.types.attrsOf delib.types.anything;
28+
attrs = delib.types.attrsOf delib.types.unspecified;
2929

3030
attrsLegacy = lib.types.attrs;
3131

32-
function = delib.types.functionTo delib.types.anything;
32+
function = delib.types.functionTo delib.types.unspecified;
3333

3434
# FIX https://github.com/NixOS/nixpkgs/issues/438933
3535
functionTo =
@@ -71,11 +71,18 @@
7171
nestedTypes.elemType = elemType;
7272
};
7373

74-
intBetween = lib.types.ints.between;
74+
intBetween =
75+
lowest: highest:
76+
assert lib.assertMsg (lowest <= highest) "intBetween: lowest must be smaller than highest";
77+
lib.types.addCheck delib.types.int (x: x >= lowest && x <= highest)
78+
// {
79+
name = "intBetween";
80+
description = "integer between ${toString lowest} and ${toString highest} (both inclusive)";
81+
};
7582

76-
lazyAttrs = delib.types.lazyAttrsOf delib.types.anything;
83+
lazyAttrs = delib.types.lazyAttrsOf delib.types.unspecified;
7784

78-
list = delib.types.listOf delib.types.anything;
85+
list = delib.types.listOf delib.types.unspecified;
7986

8087
null = lib.mkOptionType {
8188
name = "null";
@@ -87,5 +94,24 @@
8794
value = null;
8895
};
8996
};
97+
98+
steppedInt =
99+
step:
100+
assert lib.assertMsg (builtins.isInt step) "steppedInt: step must be an integer";
101+
lib.types.addCheck delib.types.int (x: x == x / step * step)
102+
// {
103+
name = "steppedInt";
104+
description = "integer that is a multiple of ${step}";
105+
};
106+
107+
steppedIntBetween =
108+
lowest: highest: step:
109+
assert lib.assertMsg (builtins.isInt step) "steppedInt: step must be an integer";
110+
assert lib.assertMsg (lowest <= highest) "intBetween: lowest must be smaller than highest";
111+
lib.types.addCheck delib.types.int (x: x >= lowest && x <= highest && x == x / step * step)
112+
// {
113+
name = "steppedIntBetween";
114+
description = "integer between ${toString lowest} and ${toString highest} (inclusive) that is a multiple of ${step}";
115+
};
90116
# keep-sorted end
91117
}

0 commit comments

Comments
 (0)