Skip to content

evalConanConfig

This example can be found in the standalone-eval-conan-config directory:

Terminal window
cd examples/standalone-eval-conan-config

Where the actual perSystem function — the one left out of the schema of the previous chapter — is used to configure a Release, C++17 profile:

examples/standalone-eval-conan-config/flake.nix
{
# ...
perSystem = system:
let
pkgs = nixpkgs.legacyPackages.${system};
configuration = conan-flake.lib.evalConanConfig pkgs (
{ pkgs, config, ... }: {
configRoot = self;
profiles.default = {
settings.build_type = "Release";
settings."compiler.cppstd" = "17";
};
remotes.local = {
url = "./repo";
local = true;
allowedPackages = [ "hello-world/0.0.1.cci.20260428" ];
};
offline = true;
checks.example = {
enable = true;
drv =
conan-flake.lib.runCommandWithInSimulatedShell pkgs config.stdenv config.outputs.devShell
config.info.configRoot "./config"
"standalone-eval-conan-config-example-conan-create"
{ }
''
(
set -x
conan create . --build=missing 2>&1 | grep -F "example/0.0.1"
touch $out
)
''; # checks.example
};
}
);
in
{
devShells.default = configuration.config.outputs.devShell;
checks = configuration.config.outputs.checks;
};
# ...
}

This configuration now can be used to set a developer environment with direnv:

Terminal window
direnv allow .

But even a plain nix develop would suffice:

Terminal window
nix develop .

From within this shell, the following command can be used to obtain the resulting profile:

Terminal window
conan profile show

To the profiles.default.settings.build_type and profiles.default.settings."compiler.cppstd" attributes correspond, respectively, the build_type and compiler.cppstd entries in its output:

Host profile:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=17
compiler.libcxx=libstdc++11
compiler.version=15.3.0
os=Linux
[platform_tool_requires]
cmake/4.3.4
[conf]
Build profile:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=17
compiler.libcxx=libstdc++11
compiler.version=15.3.0
os=Linux
[platform_tool_requires]
cmake/4.3.4
[conf]

In the standalone-eval-conan-config directory, the conanfile.py recipe file defines a C++ package — example/0.0.1 — it’s possible to call conan create on it, and export this package into the local Conan cache:

Terminal window
conan create . --build=missing

The above command is going to install the dependencies and then build the example/0.0.1 package. Then export it to the local Conan cache and test it afterwards against standalone-eval-conan-config/test_package. If everything goes well, the last lines from the previous command would be the test package’s output:

hello-world: Hello World Release!
hello-world: __x86_64__ defined
hello-world: _GLIBCXX_USE_CXX11_ABI 1
hello-world: __cplusplus201703
hello-world: __GNUC__15
hello-world: __GNUC_MINOR__2
example/0.0.1 test_package

There’s also a check example function defined along with each default devShell:

checks.example = {
enable = true;
drv =
conan-flake.lib.runCommandWithInSimulatedShell pkgs config.stdenv config.outputs.devShell
config.info.configRoot "./config"
"standalone-eval-conan-config-example-conan-create"
{ }
''
(
set -x
conan create . --build=missing 2>&1 | grep -F "example/0.0.1"
touch $out
)
''; # checks.example

Run the check via nix flake check:

Terminal window
nix flake check .