Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib.trivial: add examples for importJSON and importTOML #318102

Conversation

TheCodedProf
Copy link
Contributor

Description of changes

Added examples for both lib.trivial.importJSON and lib.trivial.importTOML

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 馃憤 reaction to pull requests you find important.

@infinisil
Copy link
Member

infinisil commented Jun 7, 2024

Check out e.g.

nixpkgs/lib/trivial.nix

Lines 95 to 126 in a1bed62

# Examples
:::{.example}
## `lib.trivial.pipe` usage example
```nix
pipe 2 [
(x: x + 2) # 2 + 2 = 4
(x: x * 2) # 4 * 2 = 8
]
=> 8
# ideal to do text transformations
pipe [ "a/b" "a/c" ] [
# create the cp command
(map (file: ''cp "${src}/${file}" $out\n''))
# concatenate all commands into one string
lib.concatStrings
# make that string into a nix derivation
(pkgs.runCommand "copy-to-out" {})
]
=> <drv which copies all files to $out>
The output type of each function has to be the input type
of the next function, and the last function returns the
final value.
```
:::
for the conventional example syntax :)

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/4082

Friend came to me with misunderstanding of how this function works.
After discussion we came to the conclusion having an example would have
prevented this.
Add parity with importTOML.
@infinisil infinisil force-pushed the private/thecodedprof/documentation-examples branch from 474d1b0 to cfc6c9b Compare June 13, 2024 01:12
Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed a very minor change, looking good now, thanks!

@infinisil infinisil merged commit a1bae89 into NixOS:master Jun 13, 2024
7 of 8 checks passed
@TheCodedProf TheCodedProf deleted the private/thecodedprof/documentation-examples branch June 13, 2024 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants