module system: revert "remove types.optionSet", just deprecate (#56857)
The explicit remove helped to uncover some hidden uses of `optionSet` in NixOps. However it makes life harder for end-users of NixOps - it will be impossible to deploy 19.03 systems with old NixOps, but there is no new release of NixOps with `optionSet` fixes. Also, "deprecation" process isn't well defined. Even that `optionSet` was declared "deprecated" for many years, it was never announced. Hence, I leave "deprecation" announce. Then, 3 releases after announce, we can announce removal of this feature. This type has to be removed, not `throw`-ed in runtime, because it makes some perfectly fine code to fail. For example: ``` $ nix-instantiate --eval -E '(import <nixpkgs/lib>).types' --strict trace: `types.list` is deprecated; use `types.listOf` instead error: types.optionSet is deprecated; use types.submodule instead (use '--show-trace' to show detailed location information) ```
This commit is contained in:
parent
cf1de3c2df
commit
60e8fcf0e5
|
@ -476,8 +476,22 @@ rec {
|
||||||
optionSet to options of type submodule. FIXME: remove
|
optionSet to options of type submodule. FIXME: remove
|
||||||
eventually. */
|
eventually. */
|
||||||
fixupOptionType = loc: opt:
|
fixupOptionType = loc: opt:
|
||||||
|
let
|
||||||
|
options = opt.options or
|
||||||
|
(throw "Option `${showOption loc'}' has type optionSet but has no option attribute, in ${showFiles opt.declarations}.");
|
||||||
|
f = tp:
|
||||||
|
let optionSetIn = type: (tp.name == type) && (tp.functor.wrapped.name == "optionSet");
|
||||||
|
in
|
||||||
|
if tp.name == "option set" || tp.name == "submodule" then
|
||||||
|
throw "The option ${showOption loc} uses submodules without a wrapping type, in ${showFiles opt.declarations}."
|
||||||
|
else if optionSetIn "attrsOf" then types.attrsOf (types.submodule options)
|
||||||
|
else if optionSetIn "loaOf" then types.loaOf (types.submodule options)
|
||||||
|
else if optionSetIn "listOf" then types.listOf (types.submodule options)
|
||||||
|
else if optionSetIn "nullOr" then types.nullOr (types.submodule options)
|
||||||
|
else tp;
|
||||||
|
in
|
||||||
if opt.type.getSubModules or null == null
|
if opt.type.getSubModules or null == null
|
||||||
then opt // { type = opt.type or types.unspecified; }
|
then opt // { type = f (opt.type or types.unspecified); }
|
||||||
else opt // { type = opt.type.substSubModules opt.options; options = []; };
|
else opt // { type = opt.type.substSubModules opt.options; options = []; };
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,8 @@ rec {
|
||||||
visible ? null,
|
visible ? null,
|
||||||
# Whether the option can be set only once
|
# Whether the option can be set only once
|
||||||
readOnly ? null,
|
readOnly ? null,
|
||||||
|
# Deprecated, used by types.optionSet.
|
||||||
|
options ? null
|
||||||
} @ attrs:
|
} @ attrs:
|
||||||
attrs // { _type = "option"; };
|
attrs // { _type = "option"; };
|
||||||
|
|
||||||
|
|
|
@ -469,8 +469,10 @@ rec {
|
||||||
# Obsolete alternative to configOf. It takes its option
|
# Obsolete alternative to configOf. It takes its option
|
||||||
# declarations from the ‘options’ attribute of containing option
|
# declarations from the ‘options’ attribute of containing option
|
||||||
# declaration.
|
# declaration.
|
||||||
optionSet = builtins.throw "types.optionSet is deprecated; use types.submodule instead" "optionSet";
|
optionSet = mkOptionType {
|
||||||
|
name = builtins.trace "types.optionSet is deprecated; use types.submodule instead" "optionSet";
|
||||||
|
description = "option set";
|
||||||
|
};
|
||||||
# Augment the given type with an additional type check function.
|
# Augment the given type with an additional type check function.
|
||||||
addCheck = elemType: check: elemType // { check = x: elemType.check x && check x; };
|
addCheck = elemType: check: elemType // { check = x: elemType.check x && check x; };
|
||||||
|
|
||||||
|
|
|
@ -456,8 +456,8 @@
|
||||||
</listitem>
|
</listitem>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Support for NixOS module system type <literal>types.optionSet</literal> and
|
NixOS module system type <literal>types.optionSet</literal> and
|
||||||
<literal>lib.mkOption</literal> argument <literal>options</literal> is removed.
|
<literal>lib.mkOption</literal> argument <literal>options</literal> are deprecated.
|
||||||
Use <literal>types.submodule</literal> instead.
|
Use <literal>types.submodule</literal> instead.
|
||||||
(<link xlink:href="https://github.com/NixOS/nixpkgs/pull/54637">#54637</link>)
|
(<link xlink:href="https://github.com/NixOS/nixpkgs/pull/54637">#54637</link>)
|
||||||
</para>
|
</para>
|
||||||
|
|
Loading…
Reference in New Issue