From a53b3ba091153de98b76e42d4a90607179bf64bf Mon Sep 17 00:00:00 2001 From: Jan Malakhovski Date: Fri, 22 Feb 2019 00:05:58 +0000 Subject: lib: optionAttrSetToDocList: warn instead of throwing on options without descriptions For convenience, it's not like not having a description is deadly or something. --- lib/options.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/options.nix b/lib/options.nix index 5cea99067aab..d46dec6e41ca 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -141,7 +141,7 @@ rec { docOption = rec { loc = opt.loc; name = showOption opt.loc; - description = opt.description or (throw "Option `${name}' has no description."); + description = opt.description or (lib.warn "Option `${name}' has no description." "This option has no description."); declarations = filter (x: x != unknownModule) opt.declarations; internal = opt.internal or false; visible = opt.visible or true; -- cgit v1.2.3 From 60e8fcf0e56ce881294b06bd1f40069016308162 Mon Sep 17 00:00:00 2001 From: Danylo Hlynskyi Date: Thu, 7 Mar 2019 21:28:09 +0200 Subject: 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 ).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) ``` --- lib/modules.nix | 18 ++++++++++++++++-- lib/options.nix | 2 ++ lib/types.nix | 6 ++++-- 3 files changed, 22 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/modules.nix b/lib/modules.nix index a41c9da610ac..0869eae1982b 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -476,8 +476,22 @@ rec { optionSet to options of type submodule. FIXME: remove eventually. */ fixupOptionType = loc: opt: - if opt.type.getSubModules or null == null - then opt // { type = opt.type or types.unspecified; } + 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 + then opt // { type = f (opt.type or types.unspecified); } else opt // { type = opt.type.substSubModules opt.options; options = []; }; diff --git a/lib/options.nix b/lib/options.nix index d46dec6e41ca..a16a980398d6 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -48,6 +48,8 @@ rec { visible ? null, # Whether the option can be set only once readOnly ? null, + # Deprecated, used by types.optionSet. + options ? null } @ attrs: attrs // { _type = "option"; }; diff --git a/lib/types.nix b/lib/types.nix index 7a88e1b9e36b..b225119299da 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -469,8 +469,10 @@ rec { # Obsolete alternative to configOf. It takes its option # declarations from the ‘options’ attribute of containing option # 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. addCheck = elemType: check: elemType // { check = x: elemType.check x && check x; }; -- cgit v1.2.3 From 570aed4b46916551da969c4daeef0322461ac2fe Mon Sep 17 00:00:00 2001 From: Jan Malakhovski Date: Sat, 23 Feb 2019 18:06:51 +0000 Subject: lib: add `showWarnings` --- lib/default.nix | 2 +- lib/trivial.nix | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/default.nix b/lib/default.nix index dbb90081b2c3..688c117d52b4 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -59,7 +59,7 @@ let stringLength sub substring tail; inherit (trivial) id const concat or and bitAnd bitOr bitXor bitNot boolToString mergeAttrs flip mapNullable inNixShell min max - importJSON warn info nixpkgsVersion version mod compare + importJSON warn info showWarnings nixpkgsVersion version mod compare splitByAndCompare functionArgs setFunctionArgs isFunction; inherit (fixedPoints) fix fix' converge extends composeExtensions makeExtensible makeExtensibleWithCustomName; diff --git a/lib/trivial.nix b/lib/trivial.nix index 3f0816b55405..2d682961035f 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -259,9 +259,10 @@ rec { # TODO: figure out a clever way to integrate location information from # something like __unsafeGetAttrPos. - warn = msg: builtins.trace "WARNING: ${msg}"; + warn = msg: builtins.trace "warning: ${msg}"; info = msg: builtins.trace "INFO: ${msg}"; + showWarnings = warnings: res: lib.fold (w: x: warn w x) res warnings; ## Function annotations -- cgit v1.2.3