about summary refs log tree commit diff
path: root/lib/modules.nix
Commit message (Collapse)AuthorAge
* Revert "lib/modules: Throw better error when definitions assign to an option ↵Silvan Mosberger2020-03-19
| | | | | | | | set" This reverts commit 15c873b486347e7861c64fb0b5a7852be9fc82e4. This was causing infinite recursion when depending on nested options
* lib/modules: Fix type checks not being done before mergingSilvan Mosberger2020-03-18
| | | | Co-Authored-By: Robert Hensing <robert@roberthensing.nl>
* lib/modules: Throw better error when definitions assign to an option setSilvan Mosberger2020-03-18
|
* lib/modules: Remove internal _module attribute from configSilvan Mosberger2020-03-17
| | | | | | | | | | The _module option is added as an internal option set, and it messes up the results of module evaluations, requiring people to manually filter _modules out. If people depend on this, they can still use config._module from inside the modules, exposing _module as an explicitly declared user option. Or alternatively with the _module attribute now returned by evalModules.
* lib/modules.nix: Add file context to unmerged values in mergeDefinitionsRobert Hensing2020-02-24
| | | | | | | | | | | | | | | | | | | | | | | | This helps with troubleshooting exceptions in config values, which were hard to track down for options with many definitions. The trace will look like: error: while evaluating the attribute 'config.foo' at undefined position: [...] while evaluating the option `foo': [...] while evaluating definitions from `/home/user/mymod.nix': while evaluating 'dischargeProperties' at /home/user/nixpkgs/lib/modules.nix:464:25, called from /home/user/nixpkgs/lib/modules.nix:392:137: while evaluating the attribute 'value' at /home/user/nixpkgs/lib/modules.nix:277:44: Value error! where the `/home/user/mymod.nix` module is { lib, ... }: { options.foo = lib.mkOption { type = lib.types.lines; }; config.foo = builtins.throw "Value error!"; }
* nixos/lib: Inherit type for doRename optionsJanne Heß2020-01-20
| | | | Co-authored-by: Silvan Mosberger <contact@infinisil.com>
* lib/modules: Switch _module.args from attrsOf to lazyAttrsOfSilvan Mosberger2020-01-10
|
* lib/modules: Move the isDefined check into mergedValueSilvan Mosberger2020-01-10
| | | | | | | | | | | | | Without this change, accessing `mergedValue` from `mergeDefinitions` in case there are no definitions will throw an error like error: evaluation aborted with the following error message: 'This case should never happen.' This change makes it throw the appropriate error error: The option `foo' is used but not defined. This is fully backwards compatible.
* lib/modules: Fix store importsSilvan Mosberger2020-01-10
| | | | | | | | | This fixes imports from the store not being possible, which was caused by https://github.com/NixOS/nixpkgs/pull/76857 E.g. such a case: imports = [ "${home-manager}/nixos" ];
* Merge pull request #76857 from Infinisil/recursive-disableModulesSilvan Mosberger2020-01-09
|\ | | | | Apply `disabledModules` recursively
| * lib/modules: Recursive disabledModulesSilvan Mosberger2020-01-09
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With this change, disabledModules applies recursively, meaning if you have a module "foo.nix" with imports = [ ./bar.nix ]; then setting disabledModules = [ "foo.nix" ]; will disable both "foo.nix" and "bar.nix", whereas previously only "foo.nix" would be disabled. This change along with https://github.com/NixOS/nixpkgs/pull/61570 allows modules to be fully disabled even when they have some `mkRenamedOption` imports.
* | Clarify error message of 'assigning to top-level attribute' (#76702)Silvan Mosberger2020-01-08
|\ \ | |/ |/| Clarify error message of 'assigning to top-level attribute'
| * lib/modules: clarify error message of 'assigning to top-level attribute'Arnout Engelen2020-01-05
| | | | | | | | | | | | | | If I understand correctly, the problem isn't so much that you're assigning to that top-level attribute, but that the assignment to the attribute (or any child of the attribute) introduces the 'config' object and prevents 'lifting' all settings to a generated 'config' object.
* | lib/modules: Don't pack submodules speciallySilvan Mosberger2020-01-01
| | | | | | | | | | This has the beneficial side effect of allowing paths to be used as modules in types.{submodule,submoduleWith}
* | lib/modules: Make unifyModuleSyntax fully idempotentSilvan Mosberger2019-12-05
| | | | | | | | Because why not
* | lib/modules: file -> _file for a more idempotent unifyModuleSyntaxSilvan Mosberger2019-12-05
|/ | | | This will be useful for doing more complicated module evaluations
* Add note: Keep error message in sync with nixos-optionChuck2019-11-04
|
* Merge pull request #69746 from Infinisil/rem-opt-usage-messageSilvan Mosberger2019-10-02
|\ | | | | lib.mkRemovedOptionModule: Show replacement for option usage too
| * lib.mkRemovedOptionModule: Show replacement for option usage tooSilvan Mosberger2019-09-28
| | | | | | | | | | | | | | | | | | | | | | Previously mkRemovedOptionModule would only show the replacement instructions when the removed option was *defined*. With this change, it also does so when an option is *used*. This is essential for options that are only intended to be used such as `security.acme.directory`, whose replacement instructions would never trigger without this change because almost everybody only uses the option and isn't defining it.
* | mkRemovedOptionModule: assert on removed optionsRobin Gloster2019-09-30
|/ | | | | | | We don't want to ignore config that can mess up machines. In general this should always fail evaluation, as you think you are changing behaviour and don't, which can easily create run-time errors we can catch early.
* lib/modules: Use options `apply` function even if no values are definedSilvan Mosberger2019-08-10
| | | | | | This allows `apply` functions to return a valid value if they completely ignore their argument, which is the case for the option renaming functions like `mkAliasOptionModule`. Therefore this solves issue #63693
* module system: revert "remove types.optionSet", just deprecate (#56857)Danylo Hlynskyi2019-03-07
| | | | | | | | | | | | | | | | | | | | 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 <nixpkgs/lib>).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) ```
* Merge pull request #54528 from cdepillabout/module-alias-uses-prioritySilvan Mosberger2019-02-23
|\ | | | | lib/modules: Change mkAliasOptionModule to use the priority for the alias
| * lib/modules: Change mkAliasOptionModule to use the priority for the alias.(cdep)illabout2019-01-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit changes the `mkAliasOptionModule` function to make sure that the priority for the aliased option is propagated to the non-aliased option. This also affects the `mkRenamedOptionModule` function in a similar fashion. This also removes the `mkAliasOptionModuleWithPriority` function, since its functionality is now subsumed by `mkAliasOptionModule`. This change was recommended by @nbp: https://github.com/NixOS/nixpkgs/pull/53397#discussion_r245487432
* | types.optionSet: deprecate and remove last usagesdanbst2019-01-31
| |
* | lib/modules.nix: small eval optimization (foldl' + foldl' + attrNames -> ↵danbst2019-01-30
|/ | | | foldl' + mapAttrs)
* Pull out defaultPriority to a top-level definition.(cdep)illabout2019-01-06
|
* lib/modules: Add a function to create an option alias that respects the priority(cdep)illabout2019-01-04
| | | | | | | | | | | | | | | | | This commit adds a function `mkAliasOptionModuleWithPriority`. This function will make an alias to an existing option and copy over the priority. This functionality is needed for PRs like #53041. In that case `nixos-generate-config` added an option to `hardware-configuration.nix` with `mkDefault`. That option was then changed and an alias created for the old name. The end user should be able to set the non-alias option in their `configuration.nix` and have everything work correctly. Without this function, the priority for the option won't be copied over correctly and the end-user will get a message saying they have the same option set to two different values.
* module system: rework module mergingSymphorien Gibol2018-08-27
| | | | The asymptotic complexity is now much lower.
* [bot]: remove unreferenced codevolth2018-07-20
|
* Merge pull request #42138 from NixOS/yegortimoshenko-patch-6xeji2018-06-27
|\ | | | | lib/modules: decrease mkOptionDefault priority to 1500
| * lib/modules: bump mkOptionDefault priority to 1500Yegor Timoshenko2018-06-17
| |
* | lib: fix and simplify `doRename`Jan Malakhovski2018-06-11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this change `mkRenamedOptionModule` would override option defaults even when the old option name is left unused. For instance ```nix { optios = { services.name.new = mkOption { default = { one = {}; }; }; }; imports = [ (mkRenamedOptionModule [ "services" "name" "old" ] [ "services" "name" "new" "two" ]) ]; config = {}; } ``` would evaluate to `{ config.services.name.new = { two = {}; }; }` when you'd expect it to evaluate to `{ config.services.name.new = { one = {}; }; }`.
* | lib: simplify `mkAliasAndWrapDefinitions`Jan Malakhovski2018-06-11
|/
* Merge pull request #34805 from rycee/fix/dorenameMatthew Justin Bauer2018-05-14
|\ | | | | lib: make use of visible variable in doRename
| * lib: make use of visible variable in doRenameRobert Helgesson2018-02-10
| | | | | | | | | | | | The `visible` variable was not hooked up previously. It is used to determine whether the renamed option should be shown in the documentation.
* | lib: modules: propagate `highestPrio`Jan Malakhovski2018-05-12
| | | | | | | | | | Yeah, it's ugly. But it's the minimal change that doesn't break anything else.
* | lib/debug: deprecate `addErrorContextToAttrs`Profpatsch2018-04-27
| | | | | | | | | | | | The function isn’t used anywhere and `addErrorContext` is an undocumented builtin. The builtin is explicitely qualified at its two uses in the module system.
* | lib: make extensibleSilvan Mosberger2018-04-07
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This allows the lib fixed point to be extended with myLib = lib.extend (self: super: { foo = "foo"; }) With this it's possible to have the new modified lib attrset available to all modules when using evalModules myLib.evalModules { modules = [ ({ lib, ... }: { options.bar = lib.mkOption { default = lib.foo; }; }) ]; } => { config = { bar = "foo"; ... }; options = ...; }
* | lib/modules: fix typoFranz Pletz2018-03-28
|/
* Add setFunctionArgs lib function.Shea Levy2018-01-31
| | | | | | Among other things, this will allow *2nix tools to output plain data while still being composable with the traditional callPackage/.override interfaces.
* lib/modules: Change type error to be gramatically nicerProfpatsch2017-11-05
| | | | | | | | | | | Before: <x> is not a integer between 0 and 100 (inclusively). (notice that “a” is wrong, it should be “an”) Now: <x> is not of type `integer between 0 and 100 (inclusively)'. This sounds a bit more formal, but circumvents the grammatical problems. Multi-word type descriptions are also easier to see.
* Convert libs to a fixed-pointGraham Christensen2017-09-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This does break the API of being able to import any lib file and get its libs, however I'm not sure people did this. I made this while exploring being able to swap out docFn with a stub in #2305, to avoid functor performance problems. I don't know if that is going to move forward (or if it is a problem or not,) but after doing all this work figured I'd put it up anyway :) Two notable advantages to this approach: 1. when a lib inherits another lib's functions, it doesn't automatically get put in to the scope of lib 2. when a lib implements a new obscure functions, it doesn't automatically get put in to the scope of lib Using the test script (later in this commit) I got the following diff on the API: + diff master fixed-lib 11764a11765,11766 > .types.defaultFunctor > .types.defaultTypeMerge 11774a11777,11778 > .types.isOptionType > .types.isType 11781a11786 > .types.mkOptionType 11788a11794 > .types.setType 11795a11802 > .types.types This means that this commit _adds_ to the API, however I can't find a way to fix these last remaining discrepancies. At least none are _removed_. Test script (run with nix-repl in the PATH): #!/bin/sh set -eux repl() { suff=${1:-} echo "(import ./lib)$suff" \ | nix-repl 2>&1 } attrs_to_check() { repl "${1:-}" \ | tr ';' $'\n' \ | grep "\.\.\." \ | cut -d' ' -f2 \ | sed -e "s/^/${1:-}./" \ | sort } summ() { repl "${1:-}" \ | tr ' ' $'\n' \ | sort \ | uniq } deep_summ() { suff="${1:-}" depth="${2:-4}" depth=$((depth - 1)) summ "$suff" for attr in $(attrs_to_check "$suff" | grep -v "types.types"); do if [ $depth -eq 0 ]; then summ "$attr" | sed -e "s/^/$attr./" else deep_summ "$attr" "$depth" | sed -e "s/^/$attr./" fi done } ( cd nixpkgs #git add . #git commit -m "Auto-commit, sorry" || true git checkout fixed-lib deep_summ > ../fixed-lib git checkout master deep_summ > ../master ) if diff master fixed-lib; then echo "SHALLOW MATCH!" fi ( cd nixpkgs git checkout fixed-lib repl .types )
* lib: introduce imap0, imap1 (#25543)zimbatm2017-07-04
| | | | | | | | | | | | | | | | * lib: introduce imap0, imap1 For historical reasons, imap starts counting at 1 and it's not consistent with the rest of the lib. So for now we split imap into imap0 that starts counting at zero and imap1 that starts counting at 1. And imap is marked as deprecated. See https://github.com/NixOS/nixpkgs/commit/c71e2d42359f9900ea2c290d141c0d606471da16#commitcomment-21873221 * replace uses of lib.imap * lib: move imap to deprecated.nix
* lib: trivial spelling fixesTom Saeger2017-04-19
|
* lib: fix mixed tab/space indents, trailing whitespace, etcBenjamin Staffin2017-03-11
| | | | | | Nix style seems to have settled on not using spaces between bound variable names and the lambda : so I also tried to make those somewhat more consistent throughout.
* modules: add support for module replacement with disabledModulesDaiderd Jordan2017-03-03
| | | | | | | | This is based on a prototype Nicolas B. Pierron worked on during a discussion we had at FOSDEM. A new version with a workaround for problems of the reverted original. Discussion: https://github.com/NixOS/nixpkgs/commit/3f2566689
* Revert "modules: add support for module replacement with disabledModules"Vladimír Čunát2017-03-01
| | | | | This reverts commit 3f2566689d14f1d7778d55ca807d1dad2f4695d1 for now. Evaluation of the tested job got broken, blocking nixos-unstable.
* modules: add support for module replacement with disabledModulesDaiderd Jordan2017-02-28
| | | | | This is based on a prototype Nicolas B. Pierron worked on during a discussion we had at FOSDEM.
* modules lib: type description in type error messageNikolay Amiantov2017-02-03
|