flake-parts
The flake-parts integration requires conan-flake and
infuse to be added to the flake
inputs:
# file: examples/flake-parts/flake.nix
{
inputs = {
nixpkgs.url = "github:cachix/devenv-nixpkgs/rolling";
flake-parts.url = "github:hercules-ci/flake-parts";
treefmt-nix.url = "github:numtide/treefmt-nix";
# Add these two:
conan-flake.url = "git+https://codeberg.org/tarcisio/conan-flake";
infuse = {
url = "git+https://codeberg.org/amjoseph/infuse.nix?rev=364ea18b5611b5fd6a6acd7151411b430a70e194";
flake = false;
};
};
# ...
}
After importing inputs.conan-flake.flakeModule, it’s possible to use the
options from
perSystem.conan
to configure a suitable Conan profile:
# file: examples/flake-parts/flake.nix
{
# ...
outputs = inputs@{ self, nixpkgs, flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = nixpkgs.lib.systems.flakeExposed;
imports = [
inputs.conan-flake.flakeModule # Import this module
inputs.treefmt-nix.flakeModule
];
perSystem = { pkgs, config, ... }: {
# A suitable Conan profile:
conan = {
profiles.default = {
settings.build_type = "Release";
settings."compiler.cppstd" = "23";
};
};
devShells.default = pkgs.mkShell {
inputsFrom = [
# conan-flake computes a devShell that can be used directly or
# appended to the `inputsFrom` option of another devShell as a
# means to compose with other devShell modules:
config.conan.outputs.devShell
config.treefmt.build.devShell
];
packages = [ pkgs.just ];
}; # devShells
treefmt.config = {
projectRoot = self;
projectRootFile = "README.md";
programs = {
cmake-format.enable = true;
};
};
};
};
}
The example above can be found in the examples/flake-parts directory:
cd examples/flake-parts
direnv allow .
It can take a while before completing. After that, the conan command should be
available in the path, and the required profile and other Conan settings already
in place:
conan profile show
A Release, C++23 profile is expected:
Host profile:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=23
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=23
compiler.libcxx=libstdc++11
compiler.version=15.3.0
os=Linux
[platform_tool_requires]
cmake/4.3.4
[conf]
Note
By default, conan-flake sets both CMake and the configured
stdenv.cccompiler asdevShell.tools. Also, whatever CMake version, if any, ends up being in thedevShell.toolsis also set, by default, as aprofiles.<name>.platformToolRequiresof every profile.
The resulting default devShell defined above is a composition — it
merges config.conan.outputs.devShell and config.treefmt.build.devShell, and
appends pkgs.just to the resulting devShell’s package list for its own
sake:
devShells.default = pkgs.mkShell {
inputsFrom = [
# conan-flake computes a devShell that can be used directly or
# appended to the `inputsFrom` option of another devShell as a
# means to compose with other devShell modules:
config.conan.outputs.devShell
config.treefmt.build.devShell
];
packages = [ pkgs.just ];
}; # devShells
A possible sanity check could be to find the corresponding commands available in the path:
cmake --version
conan --version
treefmt --version
echo
just --version
Also, CMake’s version should match the one listed in the
[platform_tool_requires] section of the conan profile show command’s output
above:
cmake version 4.3.4
CMake suite maintained and supported by Kitware (kitware.com/cmake).
Conan version 2.32.0-dev
treefmt v2.5.0
just 1.57.0
The complete list of the options available under perSystem.conan, along with
the initial setup instructions for flake-parts scenarios, is in the
option reference.