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

Standalone

Although conan-flake is presented as a flake-parts module, there is a subset of its options that can be imported independently, directly into any Nix code. This use case is supported by two helper functions, exposed in the lib namespace of the flake defined by this repository: evalConanConfig and submoduleWith.

To use these functions, add conan-flake to your flake inputs:

{
  inputs = {
    nixpkgs.url = "github:cachix/devenv-nixpkgs/rolling";

    # Add this:
    conan-flake.url = "git+https://codeberg.org/tarcisio/conan-flake";
  };
  # ...
}

Now conan-flake.lib.evalConanConfig can be used to configure, for each system supported, a Conan configuration and output a devShell and a check command. With this schema in place:

{
  # ...
  outputs = { self, nixpkgs, conan-flake, ... }:
    let
      eachSystem = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;

      # See below for the actual `perSystem` function definition:
      perSystem = system:
        let
          # ...
          configuration = conan-flake.lib.evalConanConfig pkgs (
            # ...
          );
        in
        {
          devShells = {
            # ...
          };
          checks = {
            # ...
          };
        };
      systemOutputs = eachSystem perSystem;
    in
    {
      devShells = nixpkgs.lib.mapAttrs (_: s: s.devShells) systemOutputs;
      checks = nixpkgs.lib.mapAttrs (_: s: s.checks) systemOutputs;
    };
}

The two chapters that follow fill in the perSystem function, one with each helper:

Warning

There’s still no support for the automatic nixification of conanfile.py package definitions;1 the conan-flake module is about the Conan configuration side of things, that is: profiles, settings, remotes…

The options accepted by both helpers are the ones documented in the option reference (the perSystem.conan.* entries, minus their perSystem.conan prefix).


  1. Or even of conanfile.txt, for that matter.