about summary refs log tree commit diff
path: root/lib/modules.nix
AgeCommit message (Collapse)AuthorFilesLines
2022-01-27lib/modules: introduce setDefaultModuleLocationNaïm Favier1-5/+7
Wraps a module with a default location for reporting errors.
2021-12-28lib/modules: extract multiply-used value in byNamepennae1-4/+4
module.${attr} is used at least twice, so it must be evaluated at least twice (and since it's a function argument, be turned into a thunk twice).
2021-12-25lib/modules: optimize byNamepennae1-6/+5
the foldl is equivalent to a zip with concat. list concatenation in nix is an O(n) operation, which makes this operation extremely inefficient when large numbers of modules are involved. this change reduces the number of list elements by 7 million on the system used to write this, total memory spent on lists by 58MB, and total memory allocated on the GC heap by almost 100MB (with a similar reduction in GC heap size). it's also slightly faster.
2021-12-17Merge pull request #148785 from pennae/more-option-doc-staticizingGraham Christensen1-0/+2
treewide: more defaultText for options
2021-12-08nixos/modules: Allow options to be coerced to a string for convenienceSilvan Mosberger1-0/+2
2021-12-07Merge pull request #144022 from hercules-ci/lib-modules-optimize-unmatchedDefnsSilvan Mosberger1-13/+18
lib/modules: Short-circuit unmatchedDefns when configs is empty
2021-12-02lib/modules: Deprecate args and checkRobert Hensing1-1/+6
2021-12-02lib/modules: Pass legacy args argument along through extendModulesRobert Hensing1-4/+21
2021-11-22modules: Add moduleType to module argumentsRobert Hensing1-0/+3
2021-11-22modules: Document that extendModules is also a module argumentRobert Hensing1-0/+2
2021-11-15lib.modules: add mkDerivedConfigTaeer Bar-Yam1-0/+20
mkDerivedConfig : Option a -> (a -> Definition b) -> Definition b Create config definitions with the same priority as the definition of another option. This should be used for option definitions where one option sets the value of another as a convenience. For instance a config file could be set with a `text` or `source` option, where text translates to a `source` value using `mkDerivedConfig options.text (pkgs.writeText "filename.conf")`. It takes care of setting the right priority using `mkOverride`.
2021-11-03lib/modules: Use strict fold' as recursiveUpdate is also strictRobert Hensing1-2/+1
recursiveUpdate does not produce an attrset until it has evaluated both its arguments to weak head normal form. nix-repl> lib.recursiveUpdate (throw "a") (throw "b") error: b nix-repl> lib.recursiveUpdate (throw "a") {} error: a
2021-11-03lib/modules: Fix import* commentsRobert Hensing1-2/+2
Very confusing otherwise.
2021-11-03lib/modules: Remove a lib.flipRobert Hensing1-3/+2
In hot code, the overhead (envs, applies) can matter.
2021-11-03lib/modules: Short-circuit unmatchedDefns earlierRobert Hensing1-15/+16
2021-11-01modules: Update evalModules docRobert Hensing1-3/+26
2021-11-01modules: Add extendModules to module argsRobert Hensing1-15/+19
2021-11-01lib.evalModules: Add extendModules and type to resultRobert Hensing1-5/+22
Allows the simultaneous construction of top-level invocations and submodule types. This helps structure configuration systems integration code.
2021-10-31lib/modules: Short-circuit unmatchedDefns when configs is emptyRobert Hensing1-4/+10
2021-08-26lib/modules: grammar fix in error msgMaximilian Bosch1-1/+1
2021-08-25lib/modules: fix error-message when declaring an option inside `config'Maximilian Bosch1-7/+18
The message I originally implemented here was to catch a mixup of `config' and `options' in a `types.submodule'[1]. However it looks rather weird for a wrongly declared top-level option. So I decided to throw error: The option `foo' does not exist. Definition values: - In `<unknown-file>': { bar = { _type = "option"; type = { _type = "option-type"; ... It seems as you're trying to declare an option by placing it into `config' rather than `options'! for an expression like with import ./lib; evalModules { modules = [ { foo.bar = mkOption { type = types.str; }; } ]; } [1] fa30c9abed61f30218a211842204705986d486f9
2021-08-03lib/modules: add mkImageMediaOverrideDavid Arnold1-0/+1
so the underlaying use case of the preceding commit is so generic, that we gain a lot in reasoning to give it an appropriate name. As the comment states: image media needs to override host config short of mkForce
2021-07-12lib.mkFixStrictness: DeprecateRobert Hensing1-3/+1
2021-07-12Partially revert "lib/modules: Drop mkStrict and mkFixStrictness"Robert Hensing1-0/+4
mkFixStrictness was never properly deprecated and should only be removed after warning for some time. This partially reverts commit 8fb9984690c878fcd768e967190957441de05d11.
2021-06-06lib/modules: Drop mkStrict and mkFixStrictnessJanne Heß1-4/+0
This was deprecated in 2014 and is not used anywhere in the tree.
2021-05-07Merge pull request #121870 from Pacman99/pass-specialargsRobert Hensing1-1/+1
lib/modules: pass specialArgs to modules
2021-05-06lib/modules: pass specialArgs as a module argumentPacman991-1/+1
2021-05-06lib/modules: Small optimizationSilvan Mosberger1-6/+4
2021-05-05Merge pull request #114955 from berbiche/fix/modules-imports-listSilvan Mosberger1-0/+4
lib/modules: provide a better error message when "imports" contains a list
2021-05-05lib/modules: provide error message when imports contains a listNicolas Berbiche1-0/+4
2021-05-05Revert "lib/modules: Issue type deprecation warnings recursively"Robert Hensing1-13/+4
This reverts commit 4b54aedee5e05aaf2838f6d951508b83e33d2baa.
2021-05-03lib/modules: Issue type deprecation warnings recursivelySilvan Mosberger1-4/+13
Previously, an option of type attrsOf string wouldn't throw a deprecation warning, even though the string type is deprecated. This was because the deprecation warning trigger only looked at the type of the option itself, not any of its subtypes. This commit fixes this, causing each of the types deprecationMessages to trigger for the option. This relies on the subtypes mkOptionType attribute introduced in 26607a5a2e06653fec453c83d063cdfc4b59185f
2021-04-28treewide: use lib.warnIf where appropriateAlyssa Ross1-3/+3
2021-03-11lib/modules: better error message if an attr-set of options is expectedMaximilian Bosch1-0/+11
I recently wrote some Nix code where I wrongly set a value to an option which wasn't an actual option, but an attr-set of options. The mistake I made can be demonstrated with an expression like this: { foo = { lib, pkgs, config, ... }: with lib; { options.foo.bar.baz = mkOption { type = types.str; }; config.foo.bar = 23; }; } While it wasn't too hard to find the cause of the mistake for me, it was necessary to have some practice in reading stack traces from the module system since the eval-error I got was not very helpful: error: --- TypeError --------------------------------------------------------- nix-build at: (323:25) in file: /nix/store/3nm31brdz95pj8gch5gms6xwqh0xx55c-source/lib/modules.nix 322| foldl' (acc: module: 323| acc // (mapAttrs (n: v: | ^ 324| (acc.${n} or []) ++ f module v value is an integer while a set was expected (use '--show-trace' to show detailed location information) I figured that such an error can be fairly confusing for someone who's new to NixOS, so I decided to catch this case in th `byName` function in `lib/modules.nix` by checking if the value to map through is an actual attr-set. If not, a different error will be thrown.
2021-01-21lib/modules: Set submodule type for renamed option setsSilvan Mosberger1-1/+1
For renames like mkAliasOptionModule [ "services" "compton" ] [ "services" "picom" ] where the target is an option set (like services.picom) instead of a single option (like services.picom.enable), previously the renamed option type was unset, leading to it being `types.unspecified`. This changes it to be `types.submodule {}` instead, which makes more sense.
2020-12-18Revert "Module-builtin assertions, disabling assertions and submodule ↵Silvan Mosberger1-142/+22
assertions"
2020-12-18lib/modules: Prefix mkRemovedOptionModule & co. check namesSilvan Mosberger1-3/+3
To avoid name clashes Co-authored-by: Robert Hensing <robert@roberthensing.nl>
2020-12-17lib/modules: Introduce _module.checks.*.checkSilvan Mosberger1-18/+18
Previously the .enable option was used to encode the condition as well, which lead to some oddness: - In order to encode an assertion, one had to invert it - To disable a check, one had to mkForce it By introducing a separate .check option this is solved because: - It can be used to encode assertions - Disabling is done separately with .enable option, whose default can be overridden without a mkForce
2020-11-30lib/modules: _module.check should always be internalSilvan Mosberger1-8/+9
Honestly this option should probably just be removed
2020-11-30lib/modules: Remove _module.checks.*.triggerPath as it's not necessarySilvan Mosberger1-82/+27
Previously this option was thought to be necessary to avoid infinite recursion, but it actually isn't, since the check evaluation isn't fed back into the module fixed-point.
2020-11-30lib/modules: Rename _module.assertions to _module.checksSilvan Mosberger1-30/+36
2020-11-30nixos/modules: Expose the internal module in the top-level documentationSilvan Mosberger1-5/+10
2020-11-30nixos/modules: Allow options to be coerced to a string for convenienceSilvan Mosberger1-0/+2
2020-11-30lib/modules: Use module-builtin assertions for mkRemovedOptionModule and co.Silvan Mosberger1-14/+24
2020-11-30nixos/assertions: Use module-builtin assertion implementationSilvan Mosberger1-6/+6
2020-11-30lib/modules: Implement module-builtin assertionsSilvan Mosberger1-1/+152
This implements assertions/warnings supported by the module system directly, instead of just being a NixOS option (see nixos/modules/misc/assertions.nix). This has the following benefits: - It allows cleanly redoing the user interface. The new implementation specifically allows disabling assertions or converting them to warnings instead. - Assertions/warnings can now be thrown easily from within submodules, which previously wasn't possible and needed workarounds.
2020-11-30Merge pull request #99115 from Infinisil/toString-module-filesSilvan Mosberger1-2/+2
lib/modules: Make sure to not import module _file's into the store
2020-10-26Merge pull request #101139 from roberth/lib-use-static-scope-checkingRobert Hensing1-8/+49
lib: Use Nix's static scope checking, fix error message, optimize
2020-10-24docs: update documentation of `mkRemovedOptionModule`Robert Helgesson1-1/+1
Since b08b0bcbbec77046e5a7082177cedc12fbf1dc6c, the function actually causes an assertion error, not a warning.
2020-10-22lib/modules: Simplify inheritsRobert Hensing1-34/+32