Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

evalConanConfig

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

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:

# file: 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:

direnv allow .

But even a plain nix develop would suffice:

nix develop .

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

conan profile show

To the profiles.default.settings.build_type and profiles.default.settings."compiler.cppstd" conan-flake options 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:

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:

nix flake check .