Commit graph

143 commits

Author SHA1 Message Date
Robert Hensing 98352288bd
Merge pull request #128032 from Artturin/add-swap-options
nixos/swap: add options option
2021-07-23 10:45:53 +02:00
Artturin a3c5f0cba8 lib/types.nix: add nonEmptyStr 2021-07-20 20:51:27 +03:00
Robert Hensing 285632320d lib.types.enum: Improve description for lengths 0 and 1 2021-05-25 10:53:04 +02:00
Silvan Mosberger fb1969806f
Merge pull request #117888 from kvtb/patch-3
types.nix: fix outdated comment
2021-05-08 05:46:10 +02:00
Silvan Mosberger 68955fe612 lib/types: Introduce mkOptionType occurringTypes argument
This will be used to issue deprecation warnings recursively in the next
commit

In addition, this allows easily getting nested types of other options, which
is useful when you want to create an option that aliases a part of
another one.
2021-05-03 22:15:30 +02:00
sternenseemann 8a83d611f5 lib/types: only accept derivations for shellPackage
Since shellPackage actually requires the value to be an attribute set
(i. e. an derivation in this case), we cannot re-use the package.check
type checker since it also allows strings or things that are coercible
to strings as long as they look like store paths.
2021-04-26 20:43:43 +02:00
kvtb 1c0d31d042
types.nix: types.ints.s32 and types.ints.u32 do work 2021-03-30 15:03:53 +00:00
kvtb 3131cdf05b
types.nix: fix outdated comment
Nix's `int` is always 64-bit
2021-03-28 14:04:39 +00:00
Fritz Otlinghaus e0215b3175
lib/types: add description for functionTo 2021-01-31 15:59:13 +01:00
Silvan Mosberger e9101d4a3b
lib/types: Improved functionTo merging
Now type checks the resulting function values and allows mkMerge and co.
Also indicates that the type check is done in the function body

Co-Authored-By: Robert Hensing <robert@roberthensing.nl>
2021-01-27 00:16:23 +01:00
Bas van Dijk b454af298d
Revert "Remove types.functionTo."
This reverts commit 4ff1ab5a56.

We need this to type options like:
services.xserver.windowManager.xmonad.extraPackages that specify functions that
take an attribute set containing packages / plugins and return a list containing
a selection of the values in this set.

The reason we need a dedicated type for this is to have the correct merge
behaviour. Without the functionTo type merging multiple function option
definitions results in an evaluation error. The functionTo type merges
definitions by returning a new function that applies the functions of all the
definitions to the given input and merges the result.

(cherry picked from commit 7ed41ff5e7e633dd64866398ee497ac02736a3a5)
2021-01-24 16:56:33 +01:00
Keshav Kini a456ccb0c8 lib/types.nix: fix missing inherit
I think there was a silent (i.e. semantic) merge conflict between PR #101139 and
PR #100456.  This commit should fix the error, which manifests as follows:

  error: undefined variable 'boolToString' at /home/kkini/src/nixpkgs/lib/types.nix:552:42
2020-10-26 00:50:06 -07:00
Robert Hensing 7102388834
Merge pull request #101139 from roberth/lib-use-static-scope-checking
lib: Use Nix's static scope checking, fix error message, optimize
2020-10-26 06:59:17 +01:00
Robert Hensing afa6c51f27 lib: Use Nix's static scope checking, fix error message, optimize
Nix can perform static scope checking, but whenever code is inside
a `with` expression, the analysis breaks down, because it can't
know statically what's in the attribute set whose attributes were
brought into scope. In those cases, Nix has to assume that
everything works out.

Except it doesnt. Removing `with` from lib/ revealed an undefined
variable in an error message.

If that doesn't convince you that we're better off without `with`,
I can tell you that this PR results in a 3% evaluation performance
improvement because Nix can look up local variables by index.
This adds up with applications like the module system.

Furthermore, removing `with` makes the binding site of each
variable obvious, which helps with comprehension.
2020-10-22 13:46:47 +02:00
Robert Hensing 5aa2a98dfa lib/types.nix: Use // instead of mergeAttrs 2020-10-22 13:46:47 +02:00
Malte Brandy cebf9198f3
treewide: De-inline uses of lib.boolToString
This commit should not change eval results
2020-10-14 01:46:17 +02:00
Silvan Mosberger de71ca2ebc
lib/types: Fix type description of bool enum values
Previously bool values would show as <bool>
2020-10-03 15:15:04 +02:00
Silvan Mosberger 2ff7c3e2e1
lib/types: Remove unreachable if branch
The type's check function already ensured that it can't be passed
non-lists
2020-09-21 17:13:06 +02:00
Robert Hensing f3893d8b53
Merge pull request #97119 from Infinisil/types.anything
Introduce `types.anything`
2020-09-21 08:49:24 +02:00
Silvan Mosberger 67551f46fb
lib/types: Introduce types.anything
This new type has unsurprising merge behavior: Only attribute sets are
merged together (recursively), and only if they don't conflict.

This is in contrast to the existing types:
- types.attrs is problematic because later definitions completely
  override attributes of earlier definitions, and it doesn't support
  mkIf and co.
- types.unspecified is very similar to types.attrs, but it has smart
  merging behavior that often doesn't make sense, and it doesn't support
  all types
2020-09-15 21:01:07 +02:00
Silvan Mosberger ed5a07c0ef
Merge pull request #97114 from Infinisil/type-deprecation
Better type deprecation messages
2020-09-07 19:33:19 +02:00
Silvan Mosberger f73b762aac
Merge pull request #97042 from Infinisil/freeform-option-docs
Show sub options of freeform types
2020-09-07 19:31:01 +02:00
Silvan Mosberger a582f6adde
lib/types: Set deprecationMessage for types.optionSet 2020-09-07 13:17:19 +02:00
Silvan Mosberger 3b7aca47e0
lib/types: Set deprecationMessage for types.loaOf 2020-09-07 13:17:19 +02:00
Silvan Mosberger 2bed3b2ad7
lib/types: Set deprecationMessage for types.string 2020-09-07 13:17:19 +02:00
Silvan Mosberger 14095f8f48
lib/types: Remove types.list, it's been deprecated long enough
Has been deprecated since fd803fce60
(2013-08-22)
2020-09-07 13:17:18 +02:00
Silvan Mosberger 1d4656225d
lib/types: Allow types to emit a deprecation warning
Previously the only way to deprecate a type was using

  theType = lib.warn "deprecated" (mkOptionType ...)

This caused the warning to be emitted when the type was evaluated, but
the error didn't include which option actually used that type.

With this commit, types can specify a deprecationMessage, which when
non-null, is printed along with the option that uses the type
2020-09-07 13:17:14 +02:00
Silvan Mosberger ea5ba6e13d
lib/types: Show sub options of freeform types
Previously if you set the freeform type to e.g. attrsOf (submodule ..),
those submodule options wouldn't be shown in the manual.
2020-09-03 21:16:29 +02:00
rnhmjoj 20d491a317
treewide: completely remove types.loaOf 2020-09-02 00:42:50 +02:00
Silvan Mosberger 2d45a62899
lib/types: Make submodules use the freeform type description
Submodules that have a freeform type set behave as if that was the type
of the option itself (for values that don't have an option). Since the
submodules options are shown as separate entries in the manual, it makes
sense to show the freeform type as the submodule type.
2020-08-03 22:37:01 +02:00
Drew Hess 370efefd8c
Replace short URL from #63103 with full URL.
The error message is already helpfully verbose, so there's little
reason to shorten the informational URL.
2020-01-15 13:47:49 +00:00
arcnmx 92b464d57d lib/types: prioritise coercedType in coercedTo
This more intuitively matches `types.either` and allows paths to be
coerced to submodules again, which was inhibited by #76861
2020-01-14 09:30:53 -08:00
worldofpeace 265da70e58 lib/types: dont warn loaOf for home-manager namespace
This option namespace is not a part of NixOS
so we shouldn't provide this warning for it.
2020-01-12 15:14:08 -05:00
Jan Tojnar 61cf52bc17
Merge pull request #77501 from jtojnar/more-loaof-fxes
tree-wide: fix more warning related to loaOf deprecation
2020-01-12 18:47:34 +01:00
Robert Hensing 9884cb3ed0
Merge pull request #76861 from Infinisil/paths-as-submodules
lib/types: Allow paths as submodule values
2020-01-12 14:19:04 +01:00
Jan Tojnar 13633bd21a
lib/types: improve loaOf message even more
Now we suggest correct names for all options in Nixpkgs and also home-manager at the time of writing.
2020-01-11 15:02:57 +01:00
Jan Tojnar 6fc46fbb17
lib/types: only show ... in loaOf warning when necessary 2020-01-11 13:32:30 +01:00
Jan Tojnar b0c2c96cbe
lib/types: improve loaOf warning
Not all modules use name attribute as the name of the submodule, for example,
environment.etc uses target. We will need to maintain a list of exceptions.
2020-01-11 08:56:29 +01:00
Silvan Mosberger b48717d1eb
lib/types: Introduce lazyAttrsOf
The standard attrsOf is strict in its *values*, meaning it's impossible to
access only one attribute value without evaluating all others as well.
lazyAttrsOf is a version that doesn't have that problem, at the expense
of conditional definitions not properly working anymore.
2020-01-10 16:19:55 +01:00
Silvan Mosberger 4268b4f9cf
lib/types: Add emptyValue attribute to types
Co-Authored-By: Robert Hensing <roberth@users.noreply.github.com>
2020-01-10 16:19:54 +01:00
Silvan Mosberger 6525da6321
lib/types: Allow paths as submodule values 2020-01-08 23:54:45 +01:00
Silvan Mosberger 65872f407e
Merge pull request #77133 from Infinisil/fix-path-check
lib/types: Fix path type check
2020-01-07 16:43:50 +01:00
Silvan Mosberger d7a109b59f
lib/types: Fix path type check
Previously when this function was called without a value coercible to a
string it would throw an error instead of returning false. Now it does.

As a result this now allows the use of a type like `either path attrs`
without it erroring out when a definition is an attribute set.

The warning about there not being a isPath primop was removed because
this is not the case anymore, there is builtins.isPath. But also there
always was `builtins.typeOf x == "path"` that could've been used
instead. However the path type now stands for more than just path types,
but absolute paths in general.
2020-01-06 22:09:56 +01:00
rnhmjoj 03309899eb lib/types: warn loaOf is deprecated 2020-01-06 10:39:19 -05:00
Silvan Mosberger c7ade6844f
Revert "lib/types: Allow paths as submodule values"
This reverts commit eec83d41e3.

This broke hydra evaluation because with this commit submodule values
are allowed to be paths, however the certmgr module uses `either
(submodule ...) path` in its type, meaning it already used paths for
something else which would now be interpreted as a submodule.
2020-01-03 05:21:01 +01:00
Silvan Mosberger eec83d41e3
lib/types: Allow paths as submodule values 2020-01-02 09:59:35 +01:00
Silvan Mosberger 5002e6afbc
lib/types: Add types.submoduleWith for more flexibility than types.submodule 2020-01-01 01:13:01 +01:00
Vladimír Čunát f21211ebfe
Merge branch 'master' into staging 2019-09-02 23:25:24 +02:00
Silvan Mosberger 03391cd336
lib/types: Make usage of types.string emit a warning 2019-08-31 18:19:15 +02:00
volth 08f68313a4 treewide: remove redundant rec 2019-08-28 11:07:32 +00:00