New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib/types: add signed/unsigned integer types #27965
Changes from all commits
89233cb
aa6bb13
5134bc0
af2c2de
2a30e24
610b98a
66f9c60
5985336
bc12d9a
e361d74
4bc58bd
467f6cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ lib, ... }: | ||
|
||
{ | ||
options = { | ||
value = lib.mkOption { | ||
type = lib.types.ints.between (-21) 43; | ||
}; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ lib, ... }: | ||
|
||
{ | ||
options = { | ||
value = lib.mkOption { | ||
type = lib.types.ints.positive; | ||
}; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ lib, ... }: | ||
|
||
{ | ||
options = { | ||
value = lib.mkOption { | ||
type = lib.types.ints.unsigned; | ||
}; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
value = -23; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
value = 42; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
value = 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,10 +22,6 @@ | |
<listitem><para>A boolean, its values can be <literal>true</literal> or | ||
<literal>false</literal>.</para></listitem> | ||
</varlistentry> | ||
<varlistentry> | ||
<term><varname>types.int</varname></term> | ||
<listitem><para>An integer.</para></listitem> | ||
</varlistentry> | ||
<varlistentry> | ||
<term><varname>types.path</varname></term> | ||
<listitem><para>A filesystem path, defined as anything that when coerced to | ||
|
@@ -39,7 +35,59 @@ | |
</varlistentry> | ||
</variablelist> | ||
|
||
<para>String related types:</para> | ||
<para>Integer-related types:</para> | ||
|
||
<variablelist> | ||
<varlistentry> | ||
<term><varname>types.int</varname></term> | ||
<listitem><para>A signed integer.</para></listitem> | ||
</varlistentry> | ||
<varlistentry> | ||
<term> | ||
<varname>types.ints.{s8, s16, s32}</varname> | ||
</term> | ||
<listitem> | ||
<para>Signed integers with a fixed length (8, 16 or 32 bits). | ||
They go from | ||
<inlineequation><mathphrase>−2<superscript>n</superscript>/2</mathphrase> | ||
</inlineequation> to <inlineequation> | ||
<mathphrase>2<superscript>n</superscript>/2−1</mathphrase> | ||
</inlineequation> | ||
respectively (e.g. <literal>−128</literal> to <literal>127</literal> | ||
for 8 bits). | ||
</para></listitem> | ||
</varlistentry> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind breaking these out, and specifying exactly their min/max? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if that’d improve the description, since those are based on byte-lengths anyway. |
||
<varlistentry> | ||
<term> | ||
<varname>types.ints.unsigned</varname> | ||
</term> | ||
<listitem><para>An unsigned integer (that is >= 0). | ||
</para></listitem> | ||
</varlistentry> | ||
<varlistentry> | ||
<term> | ||
<varname>types.ints.{u8, u16, u32}</varname> | ||
</term> | ||
<listitem> | ||
<para>Unsigned integers with a fixed length (8, 16 or 32 bits). | ||
They go from | ||
<inlineequation><mathphrase>0</mathphrase></inlineequation> to <inlineequation> | ||
<mathphrase>2<superscript>n</superscript>−1</mathphrase> | ||
</inlineequation> | ||
respectively (e.g. <literal>0</literal> to <literal>255</literal> | ||
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> | ||
|
||
<variablelist> | ||
<varlistentry> | ||
|
@@ -68,7 +116,7 @@ | |
|
||
<section><title>Value Types</title> | ||
|
||
<para>Value types are type that take a value parameter.</para> | ||
<para>Value types are types that take a value parameter.</para> | ||
|
||
<variablelist> | ||
<varlistentry> | ||
|
@@ -84,6 +132,17 @@ | |
<replaceable>sep</replaceable>, e.g. <literal>types.separatedString | ||
"|"</literal>.</para></listitem> | ||
</varlistentry> | ||
<varlistentry> | ||
<term> | ||
<varname>types.ints.between</varname> | ||
<replaceable>lowest</replaceable> | ||
<replaceable>highest</replaceable> | ||
</term> | ||
<listitem><para>An integer between <replaceable>lowest</replaceable> | ||
and <replaceable>highest</replaceable> (both inclusive). | ||
Useful for creating types like <literal>types.port</literal>. | ||
</para></listitem> | ||
</varlistentry> | ||
<varlistentry> | ||
<term><varname>types.submodule</varname> <replaceable>o</replaceable></term> | ||
<listitem><para>A set of sub options <replaceable>o</replaceable>. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I understand we are moving away from asymmetrical quoting?
This set of commit changes the quoting within comments as well, please revert to do only one type of quotation mark.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are? My impression was Eelco would like to keep the “special” quoting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
heh. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unicode quotes have practical implications that make them undesirable.
See NixOS/rfcs#4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
` is not unicode, though.