Merge pull request #164651 from Infinisil/remove-optionSet

lib/modules: Finally remove deprecated types.optionSet
This commit is contained in:
Silvan Mosberger 2022-03-25 17:41:57 +01:00 committed by GitHub
commit 99d9d45630
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 8 additions and 205 deletions

View File

@ -122,7 +122,7 @@ Reviewing process:
- [CODEOWNERS](https://help.github.com/articles/about-codeowners/) will make GitHub notify users based on the submitted changes, but it can happen that it misses some of the package maintainers.
- Ensure that the module tests, if any, are succeeding.
- Ensure that the introduced options are correct.
- Type should be appropriate (string related types differs in their merging capabilities, `optionSet` and `string` types are deprecated).
- Type should be appropriate (string related types differs in their merging capabilities, `loaOf` and `string` types are deprecated).
- Description, default and example should be provided.
- Ensure that option changes are backward compatible.
- `mkRenamedOptionModuleWith` provides a way to make option changes backward compatible.
@ -157,7 +157,7 @@ Reviewing process:
- Ensure that the module tests, if any, are succeeding.
- Ensure that the introduced options are correct.
- Type should be appropriate (string related types differs in their merging capabilities, `optionSet` and `string` types are deprecated).
- Type should be appropriate (string related types differs in their merging capabilities, `loaOf` and `string` types are deprecated).
- Description, default and example should be provided.
- Ensure that module `meta` field is present
- Maintainers should be declared in `meta.maintainers`.

View File

@ -609,17 +609,9 @@ rec {
throw "The option `${showOption loc}' in `${opt._file}' is already declared in ${showFiles res.declarations}."
else
let
/* Add the modules of the current option to the list of modules
already collected. The options attribute except either a list of
submodules or a submodule. For each submodule, we add the file of the
current option declaration as the file use for the submodule. If the
submodule defines any filename, then we ignore the enclosing option file. */
options' = toList opt.options.options;
getSubModules = opt.options.type.getSubModules or null;
submodules =
if getSubModules != null then map (setDefaultModuleLocation opt._file) getSubModules ++ res.options
else if opt.options ? options then map (coerceOption opt._file) options' ++ res.options
else res.options;
in opt.options // res //
{ declarations = res.declarations ++ [opt._file];
@ -802,27 +794,13 @@ rec {
compare = a: b: (a.priority or 1000) < (b.priority or 1000);
in sort compare defs';
# This calls substSubModules, whose entire purpose is only to ensure that
# option declarations in submodules have accurate position information.
# TODO: Merge this into mergeOptionDecls
fixupOptionType = loc: opt:
let
options = opt.options or
(throw "Option `${showOption loc}' has type optionSet but has no option attribute, in ${showFiles opt.declarations}.");
# Hack for backward compatibility: convert options of type
# optionSet to options of type submodule. FIXME: remove
# eventually.
f = tp:
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 (tp.functor.wrapped.name or null) == "optionSet" then
if tp.name == "attrsOf" then types.attrsOf (types.submodule options)
else if tp.name == "listOf" then types.listOf (types.submodule options)
else if tp.name == "nullOr" then types.nullOr (types.submodule options)
else tp
else tp;
in
if opt.type.getSubModules or null == null
then opt // { type = f (opt.type or types.unspecified); }
else opt // { type = opt.type.substSubModules opt.options; options = []; };
if opt.type.getSubModules or null == null
then opt // { type = opt.type or types.unspecified; }
else opt // { type = opt.type.substSubModules opt.options; options = []; };
/* Properties. */

View File

@ -79,8 +79,6 @@ rec {
visible ? null,
# Whether the option can be set only once
readOnly ? null,
# Deprecated, used by types.optionSet.
options ? null
} @ attrs:
attrs // { _type = "option"; };

View File

@ -749,14 +749,6 @@ rec {
nestedTypes.finalType = finalType;
};
# Obsolete alternative to configOf. It takes its option
# declarations from the options attribute of containing option
# declaration.
optionSet = mkOptionType {
name = "optionSet";
description = "option set";
deprecationMessage = "Use `types.submodule' instead";
};
# Augment the given type with an additional type check function.
addCheck = elemType: check: elemType // { check = x: elemType.check x && check x; };

View File

@ -1,53 +0,0 @@
# sets of small configurations:
# Each configuration
rec {
# has 2 arguments pkgs and this.
configA = pkgs: this: {
# Can depends on other configuration
require = configB;
# Defines new options
optionA = pkgs.lib.mkOption {
# With default values
default = false;
# And merging functions.
merge = pkgs.lib.mergeEnableOption;
};
# Add a new definition to other options.
optionB = this.optionA;
};
# Can be used for option header.
configB = pkgs: this: {
# Can depends on more than one configuration.
require = [ configC configD ];
optionB = pkgs.lib.mkOption {
default = false;
};
# Is not obliged to define other options.
};
configC = pkgs: this: {
require = [ configA ];
optionC = pkgs.lib.mkOption {
default = false;
};
# Use the default value if it is not overwritten.
optionA = this.optionC;
};
# Can also be used as option configuration only.
# without any arguments (backward compatibility)
configD = {
# Is not forced to specify the require attribute.
# Is not force to make new options.
optionA = true;
optionD = false;
};
}

View File

@ -1,11 +0,0 @@
let
pkgs = import ../../.. {};
config = import ./declare.nix;
in
with (pkgs.lib);
finalReferenceOptionSets
filterOptionSets
pkgs
# List of main configurations.
[ config.configB config.configC ]

View File

@ -1,57 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<expr>
<attrs>
<attr name="optionA">
<list>
<attrs>
<attr name="_type">
<string value="option" />
</attr>
<attr name="default">
<bool value="false" />
</attr>
<attr name="merge">
<unevaluated />
</attr>
<attr name="name">
<string value="optionA" />
</attr>
</attrs>
</list>
</attr>
<attr name="optionB">
<list>
<attrs>
<attr name="_type">
<string value="option" />
</attr>
<attr name="default">
<bool value="false" />
</attr>
<attr name="name">
<string value="optionB" />
</attr>
</attrs>
</list>
</attr>
<attr name="optionC">
<list>
<attrs>
<attr name="_type">
<string value="option" />
</attr>
<attr name="default">
<bool value="false" />
</attr>
<attr name="name">
<string value="optionC" />
</attr>
</attrs>
</list>
</attr>
<attr name="optionD">
<attrs>
</attrs>
</attr>
</attrs>
</expr>

View File

@ -1,15 +0,0 @@
let
pkgs = import ../../.. {};
config = import ./declare.nix;
# Define the handler of unbound options.
noOption = name: values:
builtins.trace "Attribute named '${name}' does not match any option declaration." values;
in
with (pkgs.lib);
finalReferenceOptionSets
(mergeOptionSets noOption)
pkgs
# List of main configurations.
[ config.configB config.configC ]

View File

@ -1,20 +0,0 @@
trace: Str("Attribute named 'optionD' does not match any option declaration.",[])
<?xml version='1.0' encoding='utf-8'?>
<expr>
<attrs>
<attr name="optionA">
<bool value="true" />
</attr>
<attr name="optionB">
<bool value="true" />
</attr>
<attr name="optionC">
<bool value="false" />
</attr>
<attr name="optionD">
<list>
<bool value="false" />
</list>
</attr>
</attrs>
</expr>

View File

@ -1,9 +0,0 @@
#! /bin/sh -e
echo 1>&2 "Test: Merge of option bindings."
nix-instantiate merge.nix --eval-only --strict --xml >& merge.out
diff merge.ref merge.out
echo 1>&2 "Test: Filter of option declarations."
nix-instantiate keep.nix --eval-only --strict --xml >& keep.out
diff keep.ref keep.out