3
0
Fork 0
forked from mirrors/nixpkgs

lib/types: add ints.positive.

For values that are positive, but cannot be 0.
This commit is contained in:
Profpatsch 2017-10-31 17:30:15 +01:00
parent 1158910676
commit 462c048c77
5 changed files with 25 additions and 0 deletions

View file

@ -65,6 +65,8 @@ checkConfigError 'The option .* defined in .* does not exist.' config.enable ./d
# unsigned
checkConfigOutput "42" config.value ./declare-int-unsigned-value.nix ./define-value-int-positive.nix
checkConfigError 'The option value .* in .* is not of type.*unsigned integer.*' config.value ./declare-int-unsigned-value.nix ./define-value-int-negative.nix
# positive
checkConfigError 'The option value .* in .* is not of type.*positive integer.*' config.value ./declare-int-positive-value.nix ./define-value-int-zero.nix
# between
checkConfigOutput "42" config.value ./declare-int-between-value.nix ./define-value-int-positive.nix
checkConfigError 'The option value .* in .* is not of type.*between.*-21 and 43.*inclusive.*' config.value ./declare-int-between-value.nix ./define-value-int-negative.nix

View file

@ -0,0 +1,9 @@
{ lib, ... }:
{
options = {
value = lib.mkOption {
type = lib.types.ints.positive;
};
};
}

View file

@ -0,0 +1,3 @@
{
value = 0;
}

View file

@ -151,6 +151,10 @@ rec {
name = "unsignedInt";
description = "unsigned integer, meaning >=0";
};
positive = addCheck types.int (x: x > 0) // {
name = "positiveInt";
description = "positive integer, meaning >0";
};
u8 = unsign 8 256;
u16 = unsign 16 65536;
u32 = unsign 32 4294967296;

View file

@ -78,6 +78,13 @@
for 8 bits).
</para></listitem>
</varlistentry>
<varlistentry>
<term>
<varname>types.ints.positive</varname>
</term>
<listitem><para>A positive integer (that is > 0).
</para></listitem>
</varlistentry>
</variablelist>
<para>String-related types:</para>