diff options
author | Alyssa Ross <hi@alyssa.is> | 2019-03-16 17:16:21 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2019-03-16 22:36:36 +0000 |
commit | cb6d0ec12187e0c2c11b203f3d8fa62790628141 (patch) | |
tree | 0ca0fedc67d5676e89438cffa3e0865eee0962e4 /nixpkgs/lib | |
parent | 4d83b8e578d3a0b78d2694921c944172b009036a (diff) | |
parent | da1a2b1eeafa66b4419b4f275396d8a731eccb61 (diff) | |
download | nixlib-cb6d0ec12187e0c2c11b203f3d8fa62790628141.tar nixlib-cb6d0ec12187e0c2c11b203f3d8fa62790628141.tar.gz nixlib-cb6d0ec12187e0c2c11b203f3d8fa62790628141.tar.bz2 nixlib-cb6d0ec12187e0c2c11b203f3d8fa62790628141.tar.lz nixlib-cb6d0ec12187e0c2c11b203f3d8fa62790628141.tar.xz nixlib-cb6d0ec12187e0c2c11b203f3d8fa62790628141.tar.zst nixlib-cb6d0ec12187e0c2c11b203f3d8fa62790628141.zip |
Merge commit 'da1a2b1eeafa66b4419b4f275396d8a731eccb61'
Diffstat (limited to 'nixpkgs/lib')
-rw-r--r-- | nixpkgs/lib/default.nix | 2 | ||||
-rw-r--r-- | nixpkgs/lib/modules.nix | 18 | ||||
-rw-r--r-- | nixpkgs/lib/options.nix | 2 | ||||
-rw-r--r-- | nixpkgs/lib/trivial.nix | 3 | ||||
-rw-r--r-- | nixpkgs/lib/types.nix | 6 |
5 files changed, 25 insertions, 6 deletions
diff --git a/nixpkgs/lib/default.nix b/nixpkgs/lib/default.nix index dbb90081b2c3..688c117d52b4 100644 --- a/nixpkgs/lib/default.nix +++ b/nixpkgs/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/nixpkgs/lib/modules.nix b/nixpkgs/lib/modules.nix index a41c9da610ac..0869eae1982b 100644 --- a/nixpkgs/lib/modules.nix +++ b/nixpkgs/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/nixpkgs/lib/options.nix b/nixpkgs/lib/options.nix index d46dec6e41ca..a16a980398d6 100644 --- a/nixpkgs/lib/options.nix +++ b/nixpkgs/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/nixpkgs/lib/trivial.nix b/nixpkgs/lib/trivial.nix index 3f0816b55405..2d682961035f 100644 --- a/nixpkgs/lib/trivial.nix +++ b/nixpkgs/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 "[1;31mwarning: ${msg}[0m"; info = msg: builtins.trace "INFO: ${msg}"; + showWarnings = warnings: res: lib.fold (w: x: warn w x) res warnings; ## Function annotations diff --git a/nixpkgs/lib/types.nix b/nixpkgs/lib/types.nix index 7a88e1b9e36b..b225119299da 100644 --- a/nixpkgs/lib/types.nix +++ b/nixpkgs/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; }; |