summaryrefslogtreecommitdiffstats
path: root/lib/modules.nix
AgeCommit message (Collapse)Author
2020-01-10lib/modules: Switch _module.args from attrsOf to lazyAttrsOfSilvan Mosberger
2020-01-10lib/modules: Move the isDefined check into mergedValueSilvan Mosberger
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.
2020-01-10lib/modules: Fix store importsSilvan Mosberger
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" ];
2020-01-09Merge pull request #76857 from Infinisil/recursive-disableModulesSilvan Mosberger
Apply `disabledModules` recursively
2020-01-09lib/modules: Recursive disabledModulesSilvan Mosberger
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.
2020-01-08Clarify error message of 'assigning to top-level attribute' (#76702)Silvan Mosberger
Clarify error message of 'assigning to top-level attribute'
2020-01-05lib/modules: clarify error message of 'assigning to top-level attribute'Arnout Engelen
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.
2020-01-01lib/modules: Don't pack submodules speciallySilvan Mosberger
This has the beneficial side effect of allowing paths to be used as modules in types.{submodule,submoduleWith}
2019-12-05lib/modules: Make unifyModuleSyntax fully idempotentSilvan Mosberger
Because why not
2019-12-05lib/modules: file -> _file for a more idempotent unifyModuleSyntaxSilvan Mosberger
This will be useful for doing more complicated module evaluations
2019-11-04Add note: Keep error message in sync with nixos-optionChuck
2019-10-02Merge pull request #69746 from Infinisil/rem-opt-usage-messageSilvan Mosberger
lib.mkRemovedOptionModule: Show replacement for option usage too
2019-09-30mkRemovedOptionModule: assert on removed optionsRobin Gloster
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.
2019-09-28lib.mkRemovedOptionModule: Show replacement for option usage tooSilvan Mosberger
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.
2019-08-10lib/modules: Use options `apply` function even if no values are definedSilvan Mosberger
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
2019-03-07module system: revert "remove types.optionSet", just deprecate (#56857)Danylo Hlynskyi
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) ```
2019-02-23Merge pull request #54528 from cdepillabout/module-alias-uses-prioritySilvan Mosberger
lib/modules: Change mkAliasOptionModule to use the priority for the alias
2019-01-31types.optionSet: deprecate and remove last usagesdanbst
2019-01-30lib/modules.nix: small eval optimization (foldl' + foldl' + attrNames -> ↵danbst
foldl' + mapAttrs)
2019-01-24lib/modules: Change mkAliasOptionModule to use the priority for the alias.(cdep)illabout
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
2019-01-06Pull out defaultPriority to a top-level definition.(cdep)illabout
2019-01-04lib/modules: Add a function to create an option alias that respects the priority(cdep)illabout
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.
2018-08-27module system: rework module mergingSymphorien Gibol
The asymptotic complexity is now much lower.
2018-07-20[bot]: remove unreferenced codevolth
2018-06-27Merge pull request #42138 from NixOS/yegortimoshenko-patch-6xeji
lib/modules: decrease mkOptionDefault priority to 1500
2018-06-17lib/modules: bump mkOptionDefault priority to 1500Yegor Timoshenko
2018-06-11lib: fix and simplify `doRename`Jan Malakhovski
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 = {}; }; }`.
2018-06-11lib: simplify `mkAliasAndWrapDefinitions`Jan Malakhovski
2018-05-14Merge pull request #34805 from rycee/fix/dorenameMatthew Justin Bauer
lib: make use of visible variable in doRename
2018-05-12lib: modules: propagate `highestPrio`Jan Malakhovski
Yeah, it's ugly. But it's the minimal change that doesn't break anything else.
2018-04-27lib/debug: deprecate `addErrorContextToAttrs`Profpatsch
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.
2018-04-07lib: make extensibleSilvan Mosberger
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 = ...; }
2018-03-28lib/modules: fix typoFranz Pletz
2018-02-10lib: make use of visible variable in doRenameRobert Helgesson
The `visible` variable was not hooked up previously. It is used to determine whether the renamed option should be shown in the documentation.
2018-01-31Add setFunctionArgs lib function.Shea Levy
Among other things, this will allow *2nix tools to output plain data while still being composable with the traditional callPackage/.override interfaces.
2017-11-05lib/modules: Change type error to be gramatically nicerProfpatsch
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.
2017-09-16Convert libs to a fixed-pointGraham Christensen
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 )
2017-07-04lib: introduce imap0, imap1 (#25543)zimbatm
* 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
2017-04-19lib: trivial spelling fixesTom Saeger
2017-03-11lib: fix mixed tab/space indents, trailing whitespace, etcBenjamin Staffin
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.
2017-03-03modules: add support for module replacement with disabledModulesDaiderd Jordan
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
2017-03-01Revert "modules: add support for module replacement with disabledModules"Vladimír Čunát
This reverts commit 3f2566689d14f1d7778d55ca807d1dad2f4695d1 for now. Evaluation of the tested job got broken, blocking nixos-unstable.
2017-02-28modules: add support for module replacement with disabledModulesDaiderd Jordan
This is based on a prototype Nicolas B. Pierron worked on during a discussion we had at FOSDEM.
2017-02-03modules lib: type description in type error messageNikolay Amiantov
2016-11-21mkIf: Check whether the condition is a BooleanEelco Dolstra
This gives a nicer error message than (say) while evaluating the option `fileSystems': while evaluating the attribute ‘isDefined’ at /nix/store/r8z4vvl2qzg31zm4ra6awlx5b22k7gf9-nixos-16.09.tar.gz/lib/modules.nix:323:5: while evaluating ‘filterOverrides’ at /nix/store/r8z4vvl2qzg31zm4ra6awlx5b22k7gf9-nixos-16.09.tar.gz/lib/modules.nix:395:21, called from /nix/store/r8z4vvl2qzg31zm4ra6awlx5b22k7gf9-nixos-16.09.tar.gz/lib/modules.nix:307:18: while evaluating ‘concatMap’ at /nix/store/r8z4vvl2qzg31zm4ra6awlx5b22k7gf9-nixos-16.09.tar.gz/lib/lists.nix:79:18, called from /nix/store/r8z4vvl2qzg31zm4ra6awlx5b22k7gf9-nixos-16.09.tar.gz/lib/modules.nix:401:8: while evaluating ‘concatMap’ at /nix/store/r8z4vvl2qzg31zm4ra6awlx5b22k7gf9-nixos-16.09.tar.gz/lib/lists.nix:79:18, called from /nix/store/r8z4vvl2qzg31zm4ra6awlx5b22k7gf9-nixos-16.09.tar.gz/lib/modules.nix:302:17: while evaluating anonymous function at /nix/store/r8z4vvl2qzg31zm4ra6awlx5b22k7gf9-nixos-16.09.tar.gz/lib/modules.nix:302:28, called from undefined position: while evaluating ‘dischargeProperties’ at /nix/store/r8z4vvl2qzg31zm4ra6awlx5b22k7gf9-nixos-16.09.tar.gz/lib/modules.nix:365:25, called from /nix/store/r8z4vvl2qzg31zm4ra6awlx5b22k7gf9-nixos-16.09.tar.gz/lib/modules.nix:303:62: value is a list while a Boolean was expected
2016-11-06module system: extensible option typesEric Sagnes
2016-09-24lib/module: add mkChangedOptionModule functionEric Sagnes
2016-09-24lib/module: add mkMergedOptionModule functionEric Sagnes
2016-08-28Merge pull request #15025 from ericsagnes/modules/manualDomen Kožar
manual: automatically generate modules documentation
2016-08-28Merge pull request #14311 from Profpatsch/mkRemovedOptionModule-replacementDomen Kožar
mkRemovedOptionModule: add replacement argument