diff options
| author | Valentin Gagarin <valentin@gagarin.work> | 2026-01-19 18:39:21 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-19 18:39:21 +0000 |
| commit | 638ff75ea27171eb11d03ee5de3ff060da9dc250 (patch) | |
| tree | 8567a5faf92dcda4335f47d51b6d9a784fef02e2 /lib | |
| parent | xrizer: 0.3 -> 0.4 (#475044) (diff) | |
| parent | lib.literalCode: init (diff) | |
| download | nixpkgs-638ff75ea27171eb11d03ee5de3ff060da9dc250.tar.gz | |
lib.literalExpression: tag generated code blocks with `nix`, add usage example and describe function arg; lib.literalCode: init (#467878)
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/options.nix | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/lib/options.nix b/lib/options.nix index 164bd6248534..195ba79765e9 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -672,11 +672,30 @@ rec { is necessary for complex values, e.g. functions, or values that depend on other values or packages. + # Examples + :::{.example} + ## `literalExpression` usage example + + ```nix + llvmPackages = mkOption { + type = types.str; + description = '' + Version of llvm packages to use for + this module + ''; + example = literalExpression '' + llvmPackages = pkgs.llvmPackages_20; + ''; + }; + ``` + + ::: + # Inputs `text` - : 1\. Function argument + : The text to render as a Nix expression */ literalExpression = text: @@ -690,6 +709,49 @@ rec { /** For use in the `defaultText` and `example` option attributes. Causes the + given string to be rendered verbatim in the documentation as a code + block with the language bassed on the provided input tag. + + If you wish to render Nix code, please see `literalExpression`. + + # Examples + :::{.example} + ## `literalCode` usage example + + ```nix + myPythonScript = mkOption { + type = types.str; + description = '' + Example python script used by a module + ''; + example = literalCode "python" '' + print("Hello world!") + ''; + }; + ``` + + ::: + + # Inputs + + `languageTag` + + : The language tag to use when producing the code block (i.e. `js`, `rs`, etc). + + `text` + + : The text to render as a Nix expression + */ + literalCode = + languageTag: text: + lib.literalMD '' + ```${languageTag} + ${text} + ``` + ''; + + /** + For use in the `defaultText` and `example` option attributes. Causes the given MD text to be inserted verbatim in the documentation, for when a `literalExpression` would be too hard to read. |
