134 Commits

Author SHA1 Message Date
Michael Daniels
18e82c4591 lib: remove unused let bindings and args@{} uses 2026-04-30 18:43:56 -04:00
Robert Hensing
77b5864637 lib.modules: submodule emptyValue must evaluate sub-option defaults
`emptyValue` for `types.submodule` was `{ value = { }; }`, i.e. none
of the type-declared options or their defaults.

Previously submodules without defs would simply fail for lack of a default,
but since PR #500104 repurposed `emptyValue` as the fallback when no
definitions exist, submodule options without an explicit `default = { }`
(new additions) silently lost their sub-option defaults
(e.g. `requiredFeatures.devnet` in the nixos-test-driver, #511413).

Main change: `emptyValue`: `{ }` -> `{ value = base.config; }`

Additionally, skip `emptyValue`-based default rendering in docs for
types with submodules, because their sub-options are already documented
individually, and forcing evaluation here can break on modules with
invalid or incomplete definitions.
2026-04-19 20:52:33 +01:00
cinereal
4c7577dd94 lib.options: reflect emptyValue-based option defaults in documentation
Signed-off-by: cinereal <cinereal@riseup.net>
2026-03-24 14:02:55 +01:00
İlkecan Bozdoğan
e394a579b0 lib: update type signatures
- concrete types start with uppercase: Int, String, Bool, Derivation,
  etc.
- type variables start with lowercase: a, b, etc.
- list:
  - use `[x]` for homogeneous lists instead of `List x` or `[ x ]`
  - use `List` for heterogeneous lists (not that common in `lib`)
- attr:
  - use `AttrSet` for a generic attribute set type
  - use `{ key1 :: Type1; key2 :: Type2; ... }` for adding signatures
    for known attribute names and types
  - use `{ key1 = value1; key2 = value2; ... }` for adding attributes
    with known literals
  - end with an ellipsis (`...`) if the set can contain unknown
    attributes
  - use `{ [String] :: x }` if all the attributes has the same type `x`
- prefer `Any` over `a` if the latter is not reused
2026-03-04 00:10:00 +03:00
Valentin Gagarin
638ff75ea2 lib.literalExpression: tag generated code blocks with nix, add usage example and describe function arg; lib.literalCode: init (#467878) 2026-01-19 18:39:21 +00:00
Johannes Kirschbauer
c80a1dea36 docs/mkOption: improve mkOption documentation 2026-01-09 09:47:50 +01:00
Justin !
511bf56650 treewide: fix or-as-identifier
Lix will soon warn, and in the future, error when `or` is used as an
identifier. This commit fix those cases.
2025-12-31 17:02:13 -05:00
Luke Bailey
56cee4ffd3 lib.literalCode: init 2025-12-21 15:18:17 +00:00
Luke Bailey
4d2e351d55 lib.literalExpression: add example and properly describe function arg 2025-12-16 19:15:07 +00:00
Anton Mosich
4fc8af31c0 docs/lib: use note/warning markup more consistently 2025-11-29 22:03:10 +01:00
Anton Mosich
367d102c09 docs/lib: use backticks for nix names 2025-11-29 21:46:54 +01:00
Aliaksandr
dc7095a86e treewide: remove deprecated lib functions that had warning for more than 2 years 2025-10-24 06:30:16 +03:00
dish
92aa5dc190 lib: remove lib.options.mkPackageOptionMD
Removed this, as it was deprecated in 24.11 and was intended to be
removed in 25.05. Better late than never.
2025-10-07 15:53:30 -04:00
Johannes Kirschbauer
bb9da33c62 lib/*: fix docs to use "returns" instead of "return" (#442388) 2025-10-06 08:09:54 +00:00
Felix Buehler
06ac3fbebd lib/*: fix docs to use "returns" instead of "return" 2025-09-12 16:16:41 +02:00
Matt Sturgeon
6c20442479 lib.options.optionAttrSetToDocList: add visible = "transparent"
Allows marking an option as invisible, without excluding its sub-options.

In practice, this is similar to `visible = true; internal = true;`,
however it is more explicit and less reliant on implementation details.
2025-09-11 17:00:17 +01:00
Robert Hensing
48ddbb29a1 lib.options.mkOption: clean up visible docs 2025-09-11 17:00:17 +01:00
Matt Sturgeon
ba961de6fb lib.options.mkOption: use one-sentence-per-line for visible docs 2025-09-10 14:41:12 +01:00
Emily
3b7e7e362b haskell.compiler.ghc928: drop 2025-09-07 18:45:52 +01:00
Wolfgang Walther
5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
Florent Charpentier
b6bb27bc38 lib.mkEnableOption: fix syntax error in example comment 2025-06-10 00:11:31 +02:00
Peder Bergebakken Sundt
c77ac9dfc3 treewide: fix typos 2025-06-02 16:07:07 +02:00
Matt Sturgeon
6107d48bcb lib.options.mkPackageOption: use lib.showAttrPath
Make use of `lib.showAttrPath` instead of manually doing `concatStringsSep "."`.

This means edge-cases such as the attr-path including names that are not
valid nix identifiers will be handled better.

See:
- https://nix.dev/manual/nix/2.26/language/identifiers
- https://nixos.org/manual/nixpkgs/unstable/#function-library-lib.attrsets.showAttrPath
2025-04-13 20:54:13 +01:00
Silvan Mosberger
374e6bcc40 treewide: Format all Nix files
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](8616af08d9/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
2025-04-01 20:10:43 +02:00
Johannes Kirschbauer
88f912da48 Docs: migrate format of comments to doc-comments 2025-02-12 15:01:43 +07:00
Johannes Kirschbauer
77156bcc8f doc: improve lib.options reference documentation (#316862)
* Doc: lib/options fixup wording and references

Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Silvan Mosberger <github@infinisil.com>
2025-01-13 22:02:34 +01:00
piegames
603733851b treewide: Fix incorrect string escapes 2025-01-07 19:49:28 +01:00
Johannes Kirschbauer
d504a1e680 lib.types.attrsWith: add placeholder parameter 2024-12-09 15:25:18 +01:00
Wolfgang Walther
73df63f8ef lib/options: remove mdDoc
Following through on message itself.
2024-11-22 18:30:11 +01:00
éclairevoyant
77f6192786 lib: deprecate mkPackageOptionMD 2024-06-26 23:14:45 -04:00
éclairevoyant
a2a0316319 lib: clarify warning about mdDoc 2024-04-15 14:16:33 -04:00
stuebinm
c0c2f2903f lib.mdDoc: remove and replace with warning 2024-04-13 10:07:35 -07:00
Silvan Mosberger
f37ba19765 Merge pull request #284512 from hercules-ci/lib-types-unique-merge
lib.types.unique: Check inner type deeply
2024-02-10 02:52:45 +01:00
Robert Hensing
542f5d4f4d lib.option.mergeUniqueOption: Simplify and add warning about merge function
The previous code was optimized for the old uniq behavior, which did not
call merge. That's changed, so the legacy path is not a hot path anymore,
and is not worth any tech debt.
2024-02-04 16:02:13 +01:00
Alois Wohlschlager
d33127863e lib: make deprecation warnings consistent
The deprecation warnings in lib were wildly inconsistent. Different
formulations were used in different places for the same meaning. Some warnings
used builtins.trace instead of lib.warn, which prevents silencing; one even
only had a comment instead. Make everything more uniform.
2024-02-03 19:01:39 +01:00
Robert Hensing
b78ba9bc68 lib.types.unique: Check inner type deeply
This doesn't change uniq. Why not?

- In NixOS it seems that uniq is only used with
  simple types that are fully checked by t.check.

- It exists for much longer and is used more widely.

- I believe we should deprecate it, because unique was
  already better.

- unique can be a proving ground.
2024-01-28 14:09:27 +01:00
Silvan Mosberger
055ba65fed lib: Take advantage of section descriptions
See https://github.com/nix-community/nixdoc/releases/tag/v2.6.0
2023-11-20 03:02:11 +01:00
Anselm Schüler
7e24b3619f lib/options: refactor mkPackageOption 2023-10-10 13:14:17 +02:00
Anselm Schüler
f07537da75 lib/options: add pkgsText parameter to mkPackageOption 2023-10-06 14:08:50 +02:00
Anselm Schüler
19241f5618 lib/options: correct and improve documentation of mkPackageOption 2023-10-06 14:07:06 +02:00
pennae
d36f950d40 lib: turn *MD functions into aliases
with docbook gone and MD the default these aren't needed any more. we
can't remove them yet because there's thousands of uses, but maybe some
day we can.
2023-06-13 16:56:32 +02:00
pennae
7542a1aa8f lib/options: remove literalDocBook
no longer supported. warning when used would not be appropriate, and
docbook has been on the way out for long enough that throwing an error
should not be necessary either.
2023-06-13 16:56:30 +02:00
Naïm Favier
4a56b2655e lib/options: nullable mkPackageOption
It is sometimes useful to allow setting a package option to `null` to
skip installing the package. See
https://github.com/nix-community/home-manager/pull/3668#issuecomment-1554044171
for example.
2023-05-19 12:22:21 +02:00
Naïm Favier
7cd5b9a6e8 lib/options: fix rendering of options with only a defaultText
Some options have their default value set in the `config` instead of
`default`, for example to push `mkDefault`s down an attribute set.
In those cases, it's useful to provide a `defaultText` for informational
purposes.
2023-05-06 17:09:10 +02:00
pennae
f0e8db002b lib/options: fix mkPackageOption docs
nixdoc takes everything from Type: to Example: as the type, which
misrendered a large part of the docs. it also drops sorely needed spaces
where the type had line breaks, so all has to be on one line (or use
non-standard literal spaces, which is probably worse).

also clarify what the `?` for arguments mean while we're here.
2023-03-05 01:21:46 +01:00
Anselm Schüler
9769e90233 lib/options: Add more options to mkPackageOption 2023-02-26 03:00:22 +01:00
Naïm Favier
6c7d4d4f9d lib/options: update showOption comment 2023-02-18 18:13:11 +01:00
Domen Kožar
fe734efc9c types: suggest how to resolve the conflict 2023-02-09 08:24:12 +00:00
Domen Kožar
b3cc29c288 types: explicitly state unique options are expected to be unique 2023-02-09 07:25:50 +00:00
Colin Arnott
6ff66fcbd7 lib: standardise attrset type syntax
There are a number of different syntaxes used for attrset type
signatures in our doc strings, this change standardises upon one that
uses :: for specifying attribute type, and ; terminators to be
consistent with nix syntax. There are no bugs in the functions
themselves, just that different syntaxes may confuse new users.
2023-01-30 23:53:44 +00:00