diff --git a/README.md b/README.md index bfcd841eb1..f42d4e5b5b 100644 --- a/README.md +++ b/README.md @@ -1383,6 +1383,7 @@ Use your favorite [**package manager**](https://json.nlohmann.me/integration/pac - [**build2**](https://json.nlohmann.me/integration/package_managers/#build2) `nlohmann-json` -  [**cpm.cmake**](https://json.nlohmann.me/integration/package_managers/#cpmcmake) `gh:nlohmann/json` -  [**xmake**](https://json.nlohmann.me/integration/package_managers/#xmake) `nlohmann_json` +-  [**Nix**](https://json.nlohmann.me/integration/package_managers/#nix) `nlohmann_json` The library is part of many package managers. See the [**documentation**](https://json.nlohmann.me/integration/package_managers/) for detailed descriptions and examples. diff --git a/docs/mkdocs/docs/images/package_managers/nix.svg b/docs/mkdocs/docs/images/package_managers/nix.svg new file mode 100644 index 0000000000..2a065bc9db --- /dev/null +++ b/docs/mkdocs/docs/images/package_managers/nix.svg @@ -0,0 +1,187 @@ + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/docs/mkdocs/docs/integration/nix/CMakeLists.txt b/docs/mkdocs/docs/integration/nix/CMakeLists.txt new file mode 100644 index 0000000000..12f4ae1f2b --- /dev/null +++ b/docs/mkdocs/docs/integration/nix/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.15) +project(json_example) + +find_package(nlohmann_json CONFIG REQUIRED) + +add_executable(json_example example.cpp) +target_link_libraries(json_example PRIVATE nlohmann_json::nlohmann_json) diff --git a/docs/mkdocs/docs/integration/nix/example.cpp b/docs/mkdocs/docs/integration/nix/example.cpp new file mode 100644 index 0000000000..c51a502aa2 --- /dev/null +++ b/docs/mkdocs/docs/integration/nix/example.cpp @@ -0,0 +1,10 @@ +#include +#include +#include + +using nlohmann::json; + +int main() +{ + std::cout << std::setw(4) << json::meta() << std::endl; +} diff --git a/docs/mkdocs/docs/integration/package_managers.md b/docs/mkdocs/docs/integration/package_managers.md index 84fceae7aa..b5bcef2788 100644 --- a/docs/mkdocs/docs/integration/package_managers.md +++ b/docs/mkdocs/docs/integration/package_managers.md @@ -14,7 +14,8 @@ ![Conda](../images/package_managers/conda.svg){: style="height:1em"} [**Conda**](#conda) `nlohmann_json`   ![MacPorts](../images/package_managers/macports.svg){: style="height:1em"} [**MacPorts**](#macports) `nlohmann-json`
![cpm.cmake](../images/package_managers/CPM.png){: style="height:1em"} [**CPM.cmake**](#cpmcmake) `gh:nlohmann/json`   -![xmake](../images/package_managers/xmake.svg){: style="height:1em"} [**xmake**](#xmake) `nlohmann_json` +![xmake](../images/package_managers/xmake.svg){: style="height:1em"} [**xmake**](#xmake) `nlohmann_json`   +![Nix](../images/package_managers/nix.svg){: style="height:1em"} [**Nix**](#nix) `nlohmann_json`

## Running example @@ -906,6 +907,56 @@ CPMAddPackage("gh:nlohmann/json@3.12.0") * * * +## Nix + +!!! abstract "Summary" + + package: [**`nlohmann_json`**](https://search.nixos.org/packages?channel=unstable&show=nlohmann_json&query=nlohmann_json) + + - :octicons-tag-24: Available versions: current version of each Nixpkgs channel (may lag behind the latest release) + - :octicons-rocket-24: The package is maintained by the Nixpkgs community and updated after releases. + - :octicons-file-24: File issues at the [Nixpkgs issue tracker](https://github.com/NixOS/nixpkgs/issues) + - :octicons-question-24: [Nix website](https://nixos.org) + +If you are using [Nix](https://nixos.org) or [NixOS](https://nixos.org/manual/nixos/stable/), the library is available +as the [nlohmann_json](https://search.nixos.org/packages?channel=unstable&show=nlohmann_json&query=nlohmann_json) +package in [Nixpkgs](https://github.com/NixOS/nixpkgs). To try it in a temporary shell, execute + +```shell +nix-shell -p nlohmann_json +``` + +On NixOS, the package can be installed system-wide by adding it to `configuration.nix`: + +```nix +environment.systemPackages = [ pkgs.nlohmann_json ]; +``` + +??? example "Example: CMake" + + 1. Create the following files: + + ```cpp title="example.cpp" + --8<-- "integration/nix/example.cpp" + ``` + + ```cmake title="CMakeLists.txt" + --8<-- "integration/nix/CMakeLists.txt" + ``` + + 2. Enter a shell that provides the package, CMake, and a C++ compiler: + + ```sh + nix-shell -p nlohmann_json cmake + ``` + + 3. Compile the code: + + ```sh + cmake -S . -B build + cmake --build build + ``` + ## Other package managers The library is also contained in many other package repositories; [Repology](https://repology.org/project/nlohmann-json/versions) tracks the packaged