lib/types: Introduce types.raw for unprocessed values

Changed files
+73
lib
tests
nixos
doc
manual
development
from_md
+6
lib/tests/modules.sh
···
checkConfigError 'The option .int.a. is used but not defined' config.int.a ./emptyValues.nix
checkConfigError 'The option .nonEmptyList.a. is used but not defined' config.nonEmptyList.a ./emptyValues.nix
+
## types.raw
+
checkConfigOutput "{ foo = <CODE>; }" config.unprocessedNesting ./raw.nix
+
checkConfigOutput "10" config.processedToplevel ./raw.nix
+
checkConfigError "The option .multiple. is defined multiple times" config.multiple ./raw.nix
+
checkConfigOutput "bar" config.priorities ./raw.nix
+
cat <<EOF
====== module tests ======
$pass Pass
+30
lib/tests/modules/raw.nix
···
+
{ lib, ... }: {
+
+
options = {
+
processedToplevel = lib.mkOption {
+
type = lib.types.raw;
+
};
+
unprocessedNesting = lib.mkOption {
+
type = lib.types.raw;
+
};
+
multiple = lib.mkOption {
+
type = lib.types.raw;
+
};
+
priorities = lib.mkOption {
+
type = lib.types.raw;
+
};
+
};
+
+
config = {
+
processedToplevel = lib.mkIf true 10;
+
unprocessedNesting.foo = throw "foo";
+
multiple = lib.mkMerge [
+
"foo"
+
"foo"
+
];
+
priorities = lib.mkMerge [
+
"foo"
+
(lib.mkForce "bar")
+
];
+
};
+
}
+7
lib/types.nix
···
# nixos/doc/manual/development/option-types.xml!
types = rec {
+
raw = mkOptionType rec {
+
name = "raw";
+
description = "raw value";
+
check = value: true;
+
merge = mergeOneOption;
+
};
+
anything = mkOptionType {
name = "anything";
description = "anything";
+11
nixos/doc/manual/development/option-types.section.md
···
```
:::
+
`types.raw`
+
+
: A type which doesn't do any checking, merging or nested evaluation. It
+
accepts a single arbitrary value that is not recursed into, making it
+
useful for values coming from outside the module system, such as package
+
sets or arbitrary data. Options of this type are still evaluated according
+
to priorities and conditionals, so `mkForce`, `mkIf` and co. still work on
+
the option value itself, but not for any value nested within it. This type
+
should only be used when checking, merging and nested evaluation are not
+
desirable.
+
`types.attrs`
: A free-form attribute set.
+19
nixos/doc/manual/from_md/development/option-types.section.xml
···
</varlistentry>
<varlistentry>
<term>
+
<literal>types.raw</literal>
+
</term>
+
<listitem>
+
<para>
+
A type which doesn’t do any checking, merging or nested
+
evaluation. It accepts a single arbitrary value that is not
+
recursed into, making it useful for values coming from
+
outside the module system, such as package sets or arbitrary
+
data. Options of this type are still evaluated according to
+
priorities and conditionals, so <literal>mkForce</literal>,
+
<literal>mkIf</literal> and co. still work on the option
+
value itself, but not for any value nested within it. This
+
type should only be used when checking, merging and nested
+
evaluation are not desirable.
+
</para>
+
</listitem>
+
</varlistentry>
+
<varlistentry>
+
<term>
<literal>types.attrs</literal>
</term>
<listitem>