about summary refs log tree commit diff
path: root/lib/types.nix
AgeCommit message (Collapse)AuthorFilesLines
2022-06-14lib.types.deferredModule: Improve reported locationRobert Hensing1-1/+1
2022-06-14lib.types: Add deferredModuleRobert Hensing1-0/+8
2022-06-14lib/types, lib/modules: Remove unused extensionOffsetRobert Hensing1-6/+0
2022-06-14lib/types: Use map instead of imap1 in submoduleWithRobert Hensing1-1/+1
2022-06-14lib/types: Simplify submoduleWith shorthandOnlyDefinesConfig handlingSilvan Mosberger1-12/+3
The module system already uses the parent module's _file as a fallback, so we don't need to inject the file in a weird way
2022-06-10Merge pull request #173621 from ncfavier/submodule-descriptionRobert Hensing1-6/+17
lib/types: allow custom `submoduleWith` descriptions
2022-05-19lib/types: allow custom `submoduleWith` descriptionsNaïm Favier1-6/+17
Currently the only way to set the description for a submodule type is to use `freeformType`. This is not ideal as it requires setting a freeform type, and evaluates the submodule config unnecessarily. Instead, add a `description` argument to `submoduleWith`.
2022-05-17Merge pull request #172813 from hercules-ci/functionTo-properlyRobert Hensing1-1/+3
`lib.types.functionTo` type merging and docs
2022-05-13lib.types.functionTo: Add pseudo-attr to generated docsRobert Hensing1-1/+1
2022-05-13lib.types.functionTo: Support type mergingRobert Hensing1-0/+2
2022-04-27 lib/types: Drop misleading plural from type descriptions #170561Klemens Nanni1-3/+3
Probably being the most prominent document demonstrating the problem, configuration.nix(5) describes various types in plural, e.g. - ` Type: list of strings` - ` Type: list of systemd options` However, there are other cases where appending "s" to the inner type effectively changes the type, e.g. - ``` Type: list of string matching the pattern [a-zA-Z0-9@%:_.\-]+[.](service|socket|device|mount|automount|swap|target|path|timer|scope|slice)s ``` This should've read "list of string[s]..." but instead changes the regular expression. Simply drop the best-effort plural in favour of correctness and simplicity rather than adding more grammar related logic/trying to fix this.
2022-04-24lib.types.submoduleWith: Avoid _key collisions after extendModulesRobert Hensing1-2/+8
2022-03-18lib/modules: Finally remove deprecated types.optionSetSilvan Mosberger1-8/+0
types.optionSet has been deprecated for almost 10 years now (0e333688cea468a28516bf6935648c03ed62a7bb)! A removal was already attempted in 2019 (27982b408e465554b8831f492362bc87ed0ec02a), but it was promptly reinstantiated since some third-party uses were discovered (f531ce75e4178c6867cc1d0f7fec96b2d5c3f1cb). It's finally time to remove it for good :)
2022-03-16Merge pull request #156533 from ↵Silvan Mosberger1-7/+15
hercules-ci/issue-146882-transparent-submodule-options lib.modules: Let module declare options directly in bare submodule
2022-03-11Merge pull request #163443 from ncfavier/fix-types-packageRobert Hensing1-2/+10
lib.types.package: only call toDerivation when necessary
2022-03-11lib.types.package: only call toDerivation when necessaryNaïm Favier1-2/+10
The current logic assumes that everything that isn't a derivation is a store path, but it can also be something that's *coercible* to a store path, like a flake input. Unnecessary uses of `lib.toDerivation` result in errors in pure evaluation mode when `builtins.storePath` is disabled. Also document what a `package` is.
2022-03-10lib.types.optionType: Only merge when necessaryRobert Hensing1-1/+3
2022-03-03lib.modules: Inline a private functionRobert Hensing1-7/+7
This should save about four calls per module.
2022-03-03lib.modules: Default shorthandOnlyDefinesConfig to true when nullRobert Hensing1-1/+5
2022-03-03lib.modules: Make option injection work when shorthandOnlyDefinesConfigRobert Hensing1-1/+5
2022-03-03lib.types.submodule: Remove redundant isSubmodule attrRobert Hensing1-5/+0
2022-03-03lib.modules: Let module declare options directly in bare submoduleRobert Hensing1-0/+5
... where a bare submodule is an option that has a type like `submoduleWith x`, as opposed to `attrsOf (submoduleWith x)`. This makes migration unnecessary when introducing a freeform type in an existing option tree. Closes #146882
2022-03-02Merge pull request #162283 from Infinisil/functionTo.descriptionSilvan Mosberger1-1/+1
lib/types: Fix functionTo description
2022-03-01lib.types: Introduce `types.optionType`Silvan Mosberger1-1/+30
This type correctly merges multiple option types together while also annotating them with file information. In a future commit this will be used for `_module.freeformType`
2022-03-01lib/types: Fix functionTo descriptionSilvan Mosberger1-1/+1
2022-02-22lib/types: Introduce types.raw for unprocessed valuesSilvan Mosberger1-0/+7
2022-02-17lib/types: Fix emptyValue of listOf and nonEmptyListOfSilvan Mosberger1-2/+2
An empty list is [], not {}! Also, non-empty lists shouldn't have a default of an empty list!
2022-01-24lib.types: Add unique like uniq, but custom errorsRobert Hensing1-1/+14
Couldn't extend types.uniq and it had a silly name anyway. Now we can have better error messages.
2022-01-21types.singleLineStr: Improve descriptionJules Aguillon1-1/+1
Co-authored-by: pennae <82953136+pennae@users.noreply.github.com>
2022-01-20types.singleLineStr: Allow and trim trailing \nJules Aguillon1-5/+12
Allow a \n character at the end of the string and remove it during the merge function. An option of this type will resolve to the value "foo" whether it is set to "foo" or "foo\n". This is useful when using 'builtins.readFile' or ''-strings, which might add an unintended newline (for example, bash trim the final newline from a subshell).
2022-01-18types.singleLineStr: Disallow \rJules Aguillon1-3/+2
2022-01-18types.singleLineStr: strings that don't contain '\n'Jules Aguillon1-0/+7
Add a new type, inheriting 'types.str' but checking whether the value doesn't contain any newline characters. The motivation comes from a problem with the 'users.users.${u}.openssh.authorizedKeys' option. It is easy to unintentionally insert a newline character at the end of a string, or even in the middle, for example: restricted_ssh_keys = command: keys: let prefix = '' command="${command}",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding ''; in map (key: "${prefix} ${key}") keys; The 'prefix' string ends with a newline, which ends up in the middle of a key entry after a few manipulations. This is problematic because the key file is built by concatenating all the keys with 'concatStringsSep "\n"', with result in two entries for the faulty key: '' command="...",options... MY_KEY '' This is hard to debug and might be dangerous. This is now caught at build time.
2021-11-01lib.evalModules: Add extendModules and type to resultRobert Hensing1-28/+28
Allows the simultaneous construction of top-level invocations and submodule types. This helps structure configuration systems integration code.
2021-10-02lib/types: Make types.anything merge functionsSilvan Mosberger1-0/+6
Previously it would give an error if there were multiple function definitions.
2021-07-23Merge pull request #128032 from Artturin/add-swap-optionsRobert Hensing1-0/+7
nixos/swap: add options option
2021-07-20lib/types.nix: add nonEmptyStrArtturin1-0/+7
2021-05-25lib.types.enum: Improve description for lengths 0 and 1Robert Hensing1-1/+11
2021-05-08Merge pull request #117888 from kvtb/patch-3Silvan Mosberger1-4/+4
types.nix: fix outdated comment
2021-05-03lib/types: Introduce mkOptionType occurringTypes argumentSilvan Mosberger1-1/+18
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-04-26lib/types: only accept derivations for shellPackagesternenseemann1-1/+1
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-03-30types.nix: types.ints.s32 and types.ints.u32 do workkvtb1-2/+2
2021-03-28types.nix: fix outdated commentkvtb1-2/+2
Nix's `int` is always 64-bit
2021-01-31lib/types: add description for functionToFritz Otlinghaus1-1/+2
2021-01-27lib/types: Improved functionTo mergingSilvan Mosberger1-1/+1
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-24Revert "Remove types.functionTo."Bas van Dijk1-0/+10
This reverts commit 4ff1ab5a56f1280d2de319ad4eb4b2796e07ed35. 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)
2020-10-26lib/types.nix: fix missing inheritKeshav Kini1-0/+3
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-26Merge pull request #101139 from roberth/lib-use-static-scope-checkingRobert Hensing1-6/+56
lib: Use Nix's static scope checking, fix error message, optimize
2020-10-22lib: Use Nix's static scope checking, fix error message, optimizeRobert Hensing1-5/+55
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-22lib/types.nix: Use // instead of mergeAttrsRobert Hensing1-1/+1
2020-10-14treewide: De-inline uses of lib.boolToStringMalte Brandy1-1/+1
This commit should not change eval results