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

devenv

There are two ways of using conan-flake with devenv: the languages.cplusplus.conan option, which devenv itself provides and which carries conan-flake’s own options under languages.cplusplus.conan.config, and a devenv shell that takes conan-flake’s computed devShell directly.

The languages.cplusplus.conan option

Configure Conan in any devenv shell with the supported integration:

# file: examples/devenv-module-recipe/devenv.nix
languages.cplusplus = {
  enable = true;

  conan = {
    enable = true;
    install.enable = true;

    config = {
      profiles.default = {
        settings.build_type = "Release";
        settings."compiler.cppstd" = "17";
      };

      # It's possible to specify Conan remotes explicitly, including
      # local-recipe-index remotes, in which case the `url` is taken as a
      # relative path to the root of the configuration:
      remotes.local = {
        url = "./repo";
        local = true;
        allowedPackages = [
          "hello-world/0.0.1.cci.20260428"
        ];
      };

      # Enable only local remotes (i.e., only of local-recipe-index type):
      offline = true;
    };
  };
}; # languages.cplusplus

Note

See how to setup Conan in devenv for further details. As can be seen from the above example, the devenv integration automatically takes care of the CMake part by default, and the profiles.<name>.platformToolRequires and devShell.tools options are not required to be set explicitly in the languages.cplusplus.conan.config namespace.

Warning

Depending when this page is being accessed, the devenv integration may still be pending approval upstream and the above links to the devenv docs may be missing. The devenv samples here can still be tested nonetheless, by overriding devenv itself with the version from our upstream PR. See examples/devenv-module-recipe and devenv.yaml therein for more details.

The example above is on the examples/devenv-module-recipe directory, and the Getting started chapter walks through it. A variant without the local-recipe-index remote is on examples/devenv-module; its profile settings, and the Conan profile they produce, are the pair shown on the front page.

A devenv shell taking conan-flake’s devShell

Where devenv shells are declared through flake-parts, conan-flake can be used without the languages.cplusplus option at all: importing inputs.conan-flake.flakeModule next to inputs.devenv.flakeModule makes config.conan.outputs.devShell available, which composes into a devenv shell the same way it composes into a pkgs.mkShell:

devenv = {
  shells.default = {
    name = "conan-flake-dev";

    inputsFrom = [
      # conan-flake exposes a `configuration` devShell by default that
      # can be used directly, or passed in the inputsFrom option as a
      # means to compose with other devShell modules.
      config.conan.outputs.devShell
    ];

    packages = [ pkgs.just ];

    treefmt = {
      enable = true;
      config = {
        programs = {
          nixpkgs-fmt.enable = true;
          cmake-format.enable = true;
        };
      };
    };
  };
}; # devenv

That example is on the examples/devenv directory, whose Conan configuration is written with the same perSystem.conan options the flake-parts chapter describes:

cd examples/devenv
direnv allow .

Either way, the options being set are conan-flake’s own, and the complete list of them is in the option reference — under perSystem.conan for the flake-parts spelling, and under languages.cplusplus.conan.config for the devenv one.