summary refs log tree commit diff
path: root/lib/options.nix
Commit message (Collapse)AuthorAge
* lib/options: Throw error for options without a typeJanne Heß2022-02-28
| | | | | | | | | Makes all options rendered in the manual throw an error if they don't have a type specified. This is a follow-up to #76184 Co-Authored-By: Silvan Mosberger <contact@infinisil.com>
* Merge pull request #156503 from hercules-ci/nixos-add-system.build-optionsRobert Hensing2022-01-25
|\ | | | | nixos: Add `system.build.`{`toplevel`,`installBootLoader`}, improve error message
| * lib.modules: Define mergeOneOption in terms of mergeUniqueOptionRobert Hensing2022-01-24
| |
| * lib.types: Add unique like uniq, but custom errorsRobert Hensing2022-01-24
| | | | | | | | | | Couldn't extend types.uniq and it had a silly name anyway. Now we can have better error messages.
* | nixos/docs/option-declarations: Document mkEnableOption and mkPackageOptionAnselm Schüler2022-01-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a squashed commit. These are the original commit messages: lib/option: Improve comment better comment Update documentation Updated nixos/doc/manual/development/options-declarations.md with info on mkEnableOption and mkPackageOption. Updated the comment on mkEnableOption in lib/options.nix remove trailing whitespace nixos/doc/option-declarations: Update IDs & formatting nixos/docs/option-declarations: Escape angle brackets Build DB from MD (Amended) Fix typo Co-authored-by: pennae <82953136+pennae@users.noreply.github.com> (Amended) Build DB from MD (again)
* | lib/options: Add mkPackageOptionAnselm Schüler2022-01-23
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a squashed commit. These are the original commit messages: lib/options: Add mkPackageOption lib/options: Add missing semicolon lib/options.nix: Make mkPackageOption more complicated lib/options: Fix indent. & spacing lib/options.nix: Remove example and align comment lib/options: ravenous overuse of arguments lib/options: Format better lib/options: Add default examplePath decl lib/options: Make better mkPackageOption function lib/options: Remove trailing whitespace lib/options: Improve mkPackageOptions lib/options: Remove pkgs prefixing Co-authored-by: pennae <82953136+pennae@users.noreply.github.com> lib/options: Slim down mkPackageOption further lib/options: mkPackageOption: Add "pkgs." to example lib/options: mkPackageOption: Make name & pkgs single arguments lib/options: mkPackageOption: Swap name & pkgs lib/options: Remove unnecessary import Co-authored-by: pennae <82953136+pennae@users.noreply.github.com>
* nixos/documentation: split options doc buildpennae2022-01-02
| | | | | | | | | | | | | | | | most modules can be evaluated for their documentation in a very restricted environment that doesn't include all of nixpkgs. this evaluation can then be cached and reused for subsequent builds, merging only documentation that has changed into the cached set. since nixos ships with a large number of modules of which only a few are used in any given config this can save evaluation a huge percentage of nixos options available in any given config. in tests of this caching, despite having to copy most of nixos/, saves about 80% of the time needed to build the system manual, or about two second on the machine used for testing. build time for a full system config shrank from 9.4s to 7.4s, while turning documentation off entirely shortened the build to 7.1s.
* modules: Add visible = "shallow" to hide only sub-optionsRobert Hensing2021-11-01
|
* lib/options: add literalExpression and literalDocBook, deprecate literalExampleNaïm Favier2021-10-03
|
* lib/generators: move limit detection into `withRecursion`Maximilian Bosch2021-08-26
| | | | | | | | | | | | | As suggested in #131205. Now it's possible to pretty-print a value with `lib.generators` like this: with lib.generators; toPretty { } (withRecursion { depthLimit = 10; } /* arbitrarily complex value */) Also, this can be used for any other pretty-printer now if needed.
* lib/options: use `depthLimit` for `toPretty` when showing a definitionMaximilian Bosch2021-08-25
| | | | | | | | | | | | | | | | | | | When having a bogus declaration such as { lib, ... }: { foo.bar = mkOption { type = types.str; }; } the evaluation will terminate with a not-so helpful error: stack overflow (possible infinite recursion) To make sure a useful error is still provided, I added a `depthLimit` of `10` which should be perfectly sufficient to `toPretty` when it's used in an error-case for `showDefs`.
* lib/options: Better mergeEqualOption error for uncomparable typesSilvan Mosberger2021-08-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For an option definition that uses `lib.options.mergeEqualOption` underneath, like `types.anything`, an error is thrown when multiple functions are assigned, indicating that functions can't be compared for equivalence: error: The option `test' has conflicting definition values: - In `xxx': <function> - In `xxx': <function> (use '--show-trace' to show detailed location information) However, the error message didn't use the correct files. While above error indicates that both definitions are in the xxx file, that's in fact not true. Above error was generated with options.test = lib.mkOption { type = lib.types.anything; }; imports = [ { _file = "yyy"; test = y: y; } { _file = "xxx"; test = x: x; } ]; With this change, the error uses the correct file locations: error: The option `test' has conflicting definition values: - In `xxx': <function> - In `yyy': <function> (use '--show-trace' to show detailed location information)
* Revert "Module-builtin assertions, disabling assertions and submodule ↵Silvan Mosberger2020-12-18
| | | | assertions"
* lib/options: Don't show internal suboption in the manualSilvan Mosberger2020-11-30
| | | | | | | | Initially https://github.com/NixOS/nixpkgs/pull/82897 prevented non-visible options from being rendered in the manual, but visible-but-internal options were still being recursed into. This fixes this, aligning the recurse condition here with the one in make-options-doc/default.nix
* lib/options.nix: Use merge-friendly inherit syntaxRobert Hensing2020-10-22
|
* lib: Use Nix's static scope checking, fix error message, optimizeRobert Hensing2020-10-22
| | | | | | | | | | | | | | | | | | | 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.
* lib/options.nix: Use head instead of elemAt _ 0Robert Hensing2020-10-22
|
* lib/modules: Improve error messages using showDefsSilvan Mosberger2020-09-21
|
* lib/options: Introduce showDefsSilvan Mosberger2020-09-21
| | | | For pretty-printing definitions, including file and values
* lib/options: Fix mergeEqualOption for singular functionsSilvan Mosberger2020-09-15
| | | | Previously it would error out for a single function definition
* lib/options: fix showOption exampleDaiderd Jordan2020-04-14
|
* Revert "lib/options: Use escapeNixIdentifier for showOption"Daiderd Jordan2020-04-14
| | | | | | | | This is used in in the manual generation for option identifiers that can be linked. This, unike what the example describes, doesn't preserve quotes which is needed for these identifiers to be valid. This reverts commit 124cccbe3b63122733e02e41e45a383ec48752fd.
* lib/options: Relax showOption quotingJan Tojnar2020-04-14
| | | | | | | | | | https://github.com/NixOS/nixpkgs/commit/124cccbe3b63122733e02e41e45a383ec48752fd broke the build of NixOS manual. It does not make sense to be as strict as with attributes since we are not limited by the CLI's inability to handle numbers. Placeholders should not be quoted either as they are not part of Nix syntax but a meta-level construct.
* lib/options: Use escapeNixIdentifier for showOptionSilvan Mosberger2020-04-13
|
* lib/options: Only recurse into visible sub optionsSilvan Mosberger2020-03-19
|
* lib/options: fix path in commentJan Tojnar2019-08-26
|
* module system: prettify a bit error when unique option defined twicedanbst2019-06-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | The error can be reproduced like: ``` $ nix-instantiate ./nixos -A system --arg configuration ' { fileSystems."/".device = "nodev"; boot.loader.grub.devices = [ "nodev" ]; containers.t.config.imports = [ <nixpkgs/nixos/modules/virtualisation/amazon-image.nix> ]; }' ``` Previously error was: ``` error: The unique option `containers.t.networking.hostName' is defined multiple times, in `/nix/var/nix/profiles/per-user/root/channels/nixpkgs/nixos/modules/virtualisation/amazon-image.nix' and `module at /home/danbst/dev/nixpkgs/nixos/modules/virtualisation/containers.nix:470'. (use '--show-trace' to show detailed location information) ``` Now it is: ``` error: The unique option `containers.t.networking.hostName' is defined multiple times, in: - /nix/var/nix/profiles/per-user/root/channels/nixpkgs/nixos/modules/virtualisation/amazon-image.nix - module at /home/danbst/dev/nixpkgs/nixos/modules/virtualisation/containers.nix:470. (use '--show-trace' to show detailed location information) ``` Related: https://github.com/NixOS/nixpkgs/issues/15747
* 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) ```
* lib: optionAttrSetToDocList: warn instead of throwing on options without ↵Jan Malakhovski2019-03-05
| | | | | | descriptions For convenience, it's not like not having a description is deadly or something.
* types.optionSet: deprecate and remove last usagesdanbst2019-01-31
|
* lib/options: Update documentation comments for docs generationVincent Ambo2018-10-29
| | | | | | | | Documents functions in `lib.options` for docs generation with nixdoc. The formatting change in the `mkOption` arguments is due to the way `nixdoc` parses documentation comments on pattern arguments. It's not ideal, but it works.
* docs: lib/options.nix function documentationTobias Pflug2018-10-02
|
* lib/options: teach showOptions about funny option namesGraham Christensen2018-03-05
| | | | | | | | | | | | | | | | | | | | | | Handle the case where options have funny symbols inside of them. Example: If I reference the following attribute without it being defined: security.acme.certs."example.com".webroot I now get the error: The option `security.acme.certs."example.com".webroot' is used but not defined. where before I got: The option `security.acme.certs.example.com.webroot' is used but not defined. which is not true.
* lib: export option location in `optionAttrSetToDocList`Jan Malakhovski2018-02-11
|
* nixos, lib: implement relatedPackages optionJan Malakhovski2018-02-09
| | | | | | | | This allows one to specify "related packages" in NixOS that get rendered into the configuration.nix(5) man page. The interface philosophy is pretty much stolen from TeX bibliography. See the next several commits for examples.
* Revert "nixos: doc: implement related packages in the manual"Graham Christensen2017-12-23
|
* nixos, lib: implement relatedPackages optionJan Malakhovski2017-12-07
| | | | | | This allows one to specify "related packages" in NixOS that get rendered into the configuration.nix(5) man page. The interface philosophy is pretty much stolen from TeX bibliography.
* 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 )
* module system: extensible option typesEric Sagnes2016-11-06
|
* Add read-only optionsEelco Dolstra2015-07-30
| | | | | These are options that can have only one definition, regardless of priority.
* Rename misc.nix -> deprecated.nixEelco Dolstra2015-07-23
|
* Use foldl' instead of fold in some placesEelco Dolstra2015-07-23
|
* optionAttrSetToDocList: O(n^2) -> O(n)Eelco Dolstra2015-07-23
| | | | This shaves about 10% off memory consumption of NixOS evaluation.
* Make types.bool complain on conflicting definitionsEelco Dolstra2015-06-15
| | | | | | | Previously, conflicting definitions would merge to "true". Now they give an error, e.g. error: The option `hardware.enableAllFirmware' has conflicting definitions, in `/etc/nixos/configurations/misc/eelco/stuff.nix' and `/etc/nixos/configurations/misc/eelco/mandark.nix'.
* Remove obsolete stuffEelco Dolstra2015-06-15
|
* Add Type information into manual and manpages, fixes #4600Domen Kožar2015-01-04
|
* modules: Add mkSinkUndeclaredOptions.Nicolas B. Pierron2014-12-21
|
* Eliminate some optionals/optionalAttrs calls on the hot pathEelco Dolstra2014-10-05
|
* Add some primops to libEelco Dolstra2013-11-12
|
* Clean up some option examplesEelco Dolstra2013-10-30
|