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

conan-flake

Declarative Configuration for the Conan C/C++ Package Manager

The conan-flake module provides options used to generate a configuration for the Conan C/C++ Package Manager and defines a devShell (conan.outputs.devShell) that can be used directly, or passed in the inputsFrom option as a way to compose with other devShells.

For examples see the conan-flake README.

Installation

To use these options, add to your flake inputs:

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

and inside the mkFlake:

imports = [
  inputs.conan-flake.flakeModule
];

Run nix flake lock and you’re set.

Options

perSystem.conan

Project-level Conan configuration

A wrapper based on this configuration is exposed in conan.outputs.package.wrapper.

Type: submodule

Default:

{ }

Declared by:

perSystem.conan.package

The Conan package to use.

Type: package

Default:

conanPackage pkgs

Declared by:

perSystem.conan.autoWire

List of configuration output types to autowire.

Using an empty list will disable autowiring entirely, enabling you to manually refer to them with config.conan.outputs.

Type: list of (one of “devShells”, “checks”, “packages”)

Default:

[
  "devShells"
  "checks"
  "packages"
]

Declared by:

perSystem.conan.checks

Use this to define checks for the configuration.

Type: lazy attribute set of (submodule)

Default:

{ }

Declared by:

perSystem.conan.checks.<name>.enable

Whether to enable this check.

Type: boolean

Default:

false

Declared by:

perSystem.conan.checks.<name>.drv

The check derivation.

Type: package

Declared by:

perSystem.conan.conanHome

Conan home. Can be an absolute (non-store) path or one relative to the root of the developer environment. Defaults to "./.conan2".

This is where Conan will keep its local cache, profiles and other settings.

Type: relative path not in the Nix store or absolute path not in the Nix store

Default:

"./.conan2"

Declared by:

perSystem.conan.configLocal

Configuration directory to be created in the developer environment.

Used to keep links pointing to the generated configuration in the store.

Type: relative path not in the Nix store

Default:

"./config"

Declared by:

perSystem.conan.configRoot

Path to the root of the configuration.

Type: null or path in the Nix store

Default:

null

Declared by:

perSystem.conan.configRootFile

Can be used to discover the root of the configuration on a developer environment. It’s a parameter of the root finding algorithm defined in rootFinding.package.

This option is a string that represents a filename which is searched for in the root directory.

Type: string

Default:

"conanfile.py"

Declared by:

perSystem.conan.configRootFiles

Can be used to discover the root of the configuration on a developer environment. It’s a parameter of the root finding algorithm defined in rootFinding.package.

This is a list of files to locate in the root directory to be used only as fallbacks when configRootFile cannot be found.

Type: list of string

Default:

[
  "flake.nix"
  ".git/config"
]

Declared by:

perSystem.conan.debug

Enable debug mode for devShell.enterShell.

Type: boolean

Default:

false

Example:

true

Declared by:

perSystem.conan.defaults.enable

Whether to enable conan-flake’s default settings for this configuration.

Type: boolean

Default:

true

Declared by:

perSystem.conan.defaults.devShell.tools

Default build tools always included in devShell.

Type: lazy attribute set of (null or package)

Default:

lib.optionalAttrs defaults.enable {
  conan = package;
  cmake = pkgs.cmake;
  "${pnameFromStdenvCc stdenv}" = stdenv.cc;
  inherit (outputs.packages) infoWrapper;
  inherit (outputs.packages) configHomeWrapper;
  inherit (outputs.packages) runPreConfigInstallHookWrapper;
  inherit (outputs.packages) configInstallWrapper;
  inherit (outputs.packages) profileShowWrapper;
  inherit (outputs.packages) conanWrapper;
  inherit (outputs.packages) lockCreateWrapper;
  inherit (outputs.packages) lockExtendWrapper;
  inherit (outputs.packages) createLockInstallWrapper;
  inherit (outputs.packages) buildWrapper;
  inherit (outputs.packages) allWrapper;
}

Declared by:

perSystem.conan.defaults.profiles.buildEnv

Default profile [buildenv] entries, merged into every profile. A profile entry of the same name replaces the default entry; set its value to null to remove that default entry.

Type: list of (submodule)

Default:

lib.optionals defaults.enable [ ]

Declared by:

perSystem.conan.defaults.profiles.buildEnv.*.name

Name.

Type: string

Default:

""

Declared by:

perSystem.conan.defaults.profiles.buildEnv.*.op

Operation

Type: one of “=”, “+=”, “=+”, “=!”, “=(path)”, “=+(path)”, “+=(path)”

Default:

"="

Declared by:

perSystem.conan.defaults.profiles.buildEnv.*.value

Value.

Type: null or string

Default:

""

Declared by:

perSystem.conan.defaults.profiles.conf

Default profile conf section properties, merged into every profile.

Type: lazy attribute set of (null or string)

Default:

lib.optionalAttrs defaults.enable { }
  // lib.optionalAttrs (stdenv.cc.isClang && stdenv.cc.libcxx.isLLVM or false) {
  "tools.build:compiler_executables" = "{'c': '${getExe stdenv.cc}', 'cpp': '${dirOf (getExe stdenv.cc)}/clang++'}";
}
  // lib.optionalAttrs (contains "CMakeUserPresets" generators) {
  "tools.cmake.cmaketoolchain:user_presets" =
    "{{ os.path.join(os.getenv(\"CONAN_FLAKE_HOME\"), \"CMakeUserPresets.json\") }}";
}

Declared by:

perSystem.conan.defaults.profiles.options

Default profile options section properties, merged into every profile.

Type: lazy attribute set of (null or string)

Default:

lib.optionalAttrs defaults.enable { }

Declared by:

perSystem.conan.defaults.profiles.platformRequires

Default profile platform requires, merged into every profile.

Type: lazy attribute set of (null or string)

Default:

lib.optionalAttrs defaults.enable { }

Declared by:

perSystem.conan.defaults.profiles.platformToolRequires

Default profile platform tool requires, merged into every profile.

Type: lazy attribute set of (null or string)

Default:

lib.optionalAttrs defaults.enable { }
  // lib.optionalAttrs ((final.devShell.tools.cmake or null) != null) {
  cmake = final.devShell.tools.cmake.version;
}

Declared by:

perSystem.conan.defaults.profiles.replaceRequires

Default profile requirement replacements, merged into every profile.

Type: lazy attribute set of (null or string)

Default:

lib.optionalAttrs defaults.enable { }

Declared by:

perSystem.conan.defaults.profiles.replaceToolRequires

Default profile tool requirement replacements, merged into every profile.

Type: lazy attribute set of (null or string)

Default:

lib.optionalAttrs defaults.enable { }

Declared by:

perSystem.conan.defaults.profiles.runEnv

Default profile [runenv] entries, merged into every profile. A profile entry of the same name replaces the default entry; set its value to null to remove that default entry.

Type: list of (submodule)

Default:

lib.optionals defaults.enable [ ]

Declared by:

perSystem.conan.defaults.profiles.runEnv.*.name

Name.

Type: string

Default:

""

Declared by:

perSystem.conan.defaults.profiles.runEnv.*.op

Operation

Type: one of “=”, “+=”, “=+”, “=!”, “=(path)”, “=+(path)”, “+=(path)”

Default:

"="

Declared by:

perSystem.conan.defaults.profiles.runEnv.*.value

Value.

Type: null or string

Default:

""

Declared by:

perSystem.conan.defaults.profiles.settings

Default profile settings section properties, merged into every profile.

Type: lazy attribute set of (null or string)

Default:

lib.optionalAttrs defaults.enable {
  arch = parseSystemArch { throwImpl = (_: null); } stdenv.system;
  build_type = "Release";
  "compiler" = pnameFromStdenvCc stdenv;
  "compiler.cppstd" = "20";
  "compiler.libcxx" =
    if (stdenv.cc.isClang && stdenv.cc.libcxx.isLLVM or false)
    then "libc++"
    else "libstdc++11";
  "compiler.version" = versionFromStdenvCc stdenv;
  os = parseSystemOs { throwImpl = (_: null); } stdenv.system;
}

Declared by:

perSystem.conan.defaults.profiles.toolRequires

Default profile tool requires, merged into every profile.

Type: lazy attribute set of (null or string)

Default:

lib.optionalAttrs defaults.enable { }

Declared by:

perSystem.conan.defaults.settings.compiler

Default Conan user settings compiler properties (compiler section in settings_user.yml).

Type: attribute set

Default:

lib.optionalAttrs defaults.enable infuse
  (infuse
    {
      "${pnameFromStdenvCc stdenv}".version = [
        (versionFromStdenvCc stdenv)
      ];
    }
    {
      "${pnameFromStdenvCc pkgs.gccStdenv}".version.__append = [
        (versionFromStdenvCc pkgs.gccStdenv)
      ];
      "${pnameFromStdenvCc pkgs.llvmPackages.libcxxStdenv}".version.__append = [
        (versionFromStdenvCc pkgs.llvmPackages.libcxxStdenv)
      ];
    })
  {
    "${pnameFromStdenvCc pkgs.cudaPackages.backendStdenv}".version.__append = [
      (versionFromStdenvCc pkgs.cudaPackages.backendStdenv)
    ];
  }

Declared by:

perSystem.conan.defaults.settings.core

Default Conan global.conf core properties (configuration variables matching the “core.*” pattern).

Type: attribute set

Default:

{
  "graph:compatibility_mode" = "optimized";
}

Declared by:

perSystem.conan.defaults.settings.tools

Default Conan global.conf tools properties (configuration variables matching the “tools.*” pattern).

Type: attribute set

Default:

{ }

Declared by:

perSystem.conan.defaults.settings.user

Default Conan global.conf user properties (configuration variables matching the “user.*” pattern).

Type: attribute set

Default:

{ }

Declared by:

perSystem.conan.devShell

Development shell configuration.

Type: submodule

Default:

{ }

Declared by:

perSystem.conan.devShell.enterShell

Bash code to execute when entering the shell.

Type: strings concatenated with “\n”

Default:

""

Declared by:

perSystem.conan.devShell.env

Environment variables to be exposed inside the developer environment.

Type: open submodule of lazy attribute set of anything

Default:

{ }

Declared by:

perSystem.conan.devShell.inputsFrom

A list of derivations whose build inputs will be merged into the shell environment.

Type: list of package

Default:

[ ]

Example:

[
  pkgs.hello
  (pkgs.python3.withPackages (ps: [ ps.numpy ps.pandas ]))
]

Declared by:

perSystem.conan.devShell.name

Name of the project.

Type: null or string

Default:

"conan-shell"

Declared by:

perSystem.conan.devShell.stdenv

The stdenv to use for the developer environment.

Type: package

Default:

stdenv

Declared by:

perSystem.conan.devShell.tools

Build tools to expose inside the developer environment.

These tools are merged with the conan-flake defaults defined in the defaults.devShell.tools option. Set the value to null to remove that default tool.

Type: lazy attribute set of (null or package)

Default:

{ }

Declared by:

perSystem.conan.final.devShell.tools

Final configuration of the build tools to expose inside the developer environment.

Type: lazy attribute set of package (read only)

Default:

{ }

Declared by:

perSystem.conan.final.profiles

Final configuration of each Conan profile, that is, the profile properties merged with the conan-flake defaults.

Type: lazy attribute set of (submodule) (read only)

Declared by:

perSystem.conan.final.profiles.<name>.buildEnv

Final configuration of profile [buildenv] section entries.

Type: list of (submodule) (read only)

Declared by:

perSystem.conan.final.profiles.<name>.buildEnv.*.name

Name.

Type: string

Default:

""

Declared by:

perSystem.conan.final.profiles.<name>.buildEnv.*.op

Operation

Type: one of “=”, “+=”, “=+”, “=!”, “=(path)”, “=+(path)”, “+=(path)”

Default:

"="

Declared by:

perSystem.conan.final.profiles.<name>.buildEnv.*.value

Value.

Type: string

Default:

""

Declared by:

perSystem.conan.final.profiles.<name>.conf

Final configuration of profile [conf] section properties.

Type: lazy attribute set of string (read only)

Default:

{ }

Declared by:

perSystem.conan.final.profiles.<name>.options

Final configuration of profile [options] section properties.

Type: lazy attribute set of string (read only)

Default:

{ }

Declared by:

perSystem.conan.final.profiles.<name>.platformRequires

Final configuration of profile [platform_requires] section properties.

Type: lazy attribute set of string (read only)

Default:

{ }

Declared by:

perSystem.conan.final.profiles.<name>.platformToolRequires

Final configuration of profile [platform_tool_requires] section properties.

Type: lazy attribute set of string (read only)

Default:

{ }

Declared by:

perSystem.conan.final.profiles.<name>.replaceRequires

Final configuration of profile [replace_requires] section properties.

Type: lazy attribute set of string (read only)

Default:

{ }

Declared by:

perSystem.conan.final.profiles.<name>.replaceToolRequires

Final configuration of profile [replace_tool_requires] section properties.

Type: lazy attribute set of string (read only)

Default:

{ }

Declared by:

perSystem.conan.final.profiles.<name>.runEnv

Final configuration of profile [runenv] section entries.

Type: list of (submodule) (read only)

Declared by:

perSystem.conan.final.profiles.<name>.runEnv.*.name

Name.

Type: string

Default:

""

Declared by:

perSystem.conan.final.profiles.<name>.runEnv.*.op

Operation

Type: one of “=”, “+=”, “=+”, “=!”, “=(path)”, “=+(path)”, “+=(path)”

Default:

"="

Declared by:

perSystem.conan.final.profiles.<name>.runEnv.*.value

Value.

Type: string

Default:

""

Declared by:

perSystem.conan.final.profiles.<name>.settings

Final configuration of profile [settings] section properties.

Type: lazy attribute set of string (read only)

Default:

{ }

Declared by:

perSystem.conan.final.profiles.<name>.toolRequires

Final configuration of profile [tool_requires] section properties.

Type: lazy attribute set of string (read only)

Default:

{ }

Declared by:

perSystem.conan.final.settings.compiler

Final state of Conan user settings compiler properties (compiler section in settings_user.yml).

Type: attribute set (read only)

Default:

{ }

Declared by:

perSystem.conan.final.settings.core

Final state of Conan global.conf core properties (configuration variables matching the “core.*” pattern).

Type: attribute set (read only)

Default:

{ }

Declared by:

perSystem.conan.final.settings.tools

Final state of Conan global.conf tools properties (configuration variables matching the “tools.*” pattern).

Type: attribute set (read only)

Default:

{ }

Declared by:

perSystem.conan.final.settings.user

Final state of Conan global.conf user properties (configuration variables matching the “user.*” pattern).

Type: attribute set (read only)

Default:

{ }

Declared by:

perSystem.conan.generators

List of generators observed by the conan-flake configuration.

Type: list of (one of “CMakeDeps”, “CMakeToolchain”)

Default:

[
  "CMakeDeps"
]

Declared by:

perSystem.conan.hasImplicitConancenterRemote

Whether to consider the implicit conancenter remote (https://center2.conan.io) during the initial Conan setup or not.

Type: boolean

Default:

true

Declared by:

perSystem.conan.homeDirectory

Path to the developer environment relative to the initial working directory. Defaults to ".".

Type: relative path not in the Nix store

Default:

"."

Example:

"./dev"

Declared by:

perSystem.conan.homeRoot

Path to the developer environment initial working directory. Can be used to bypass any other finding logic defined in homeFinding.package to set the CONAN_FLAKE_HOME environment variable (unless it’s a non existent path). Defaults to null.

Type: null or absolute path not in the Nix store

Default:

null

Declared by:

perSystem.conan.info

Overall information on the configuration.

Type: submodule

Declared by:

perSystem.conan.info.configRoot

Information on the path to the root of the configuration directory.

Type: null or absolute path (read only)

Default:

null

Declared by:

perSystem.conan.offline

Whether to enable only local remotes.

Type: boolean

Default:

false

Declared by:

perSystem.conan.outputs

The outputs generated for this configuration.

This is an internal option, not meant to be set by the user.

Type: submodule

Declared by:

perSystem.conan.outputs.packages

Package set containing the generated Conan configuration.

Type: lazy attribute set of package

Default:

{ }

Declared by:

perSystem.conan.outputs.checks

The collected (enabled) checks for this configuration.

Type: lazy attribute set of package (read only)

Default:

{ }

Declared by:

perSystem.conan.outputs.configuration

The generated Conan configuration.

Type: lazy attribute set of (submodule)

Declared by:

perSystem.conan.outputs.configuration.<name>.package

The configuration-outputing derivation generated.

Type: package

Declared by:

perSystem.conan.outputs.configuration.<name>.kind

The kind of package, used to determine how to group packages together.

Type: one of “configuration”, “package”, “info”

Declared by:

perSystem.conan.outputs.configuration.<name>.manifest

For configuration packages, the intended relative path for the configuration file, in the case package is a file. Otherwise, a list of relative paths to the package’s output configuration files.

Type: null or relative path not in the Nix store or list of relative path not in the Nix store

Default:

null

Declared by:

perSystem.conan.outputs.devShell

The development shell derivation generated for this project.

Type: package (read only)

Declared by:

Paths to link after the configuration is generated.

Type: lazy attribute set of (submodule)

Declared by:

perSystem.conan.outputs.links.<name>.kind

The kind of links, used to determine how to group them together.

Type: one of “configuration”, “package”, “info”

Declared by:

perSystem.conan.outputs.links.<name>.relativePaths

List of relative paths to link.

Type: list of relative path not in the Nix store

Default:

[ ]

Declared by:

perSystem.conan.pkgs

Nixpkgs to use in conan-flake.

Type: lazy attribute set of raw value

Default: pkgs (module argument of perSystem)

Declared by:

perSystem.conan.profiles

Conan profiles.

Each attribute of this set defines one Conan profile, named after its attribute name. A profile named default is always present.

Each profile accepts settings, options, toolRequires, buildEnv, runEnv, conf, replaceRequires, replaceToolRequires, platformRequires and platformToolRequires (see profile.nix, whose own option declarations describe each section’s shape and rendering in detail). profiles is a deferredModule, which has no discoverable sub-options of its own, so every section is demonstrated below rather than left to be found on a per-option reference page.

Type: lazy attribute set of module

Default:

{ }

Example:

{
  default.settings.build_type = "Release";

  debug.settings.build_type = "Debug";

  settingsEx.settings = {
    arch = "x86_64";
    build_type = "Release";
    compiler = "apple-clang";
    "compiler.cppstd" = "gnu17";
    "compiler.libcxx" = "libc++";
    "compiler.version" = "14";
    os = "Macos";
  };

  buildEnvEx.buildEnv = [
    # Rendered as `CFLAGS=-O2`.
    {
      name = "CFLAGS";
      value = "-O2";
    }
    # Rendered as `PATH+=(path)/opt/bin`.
    {
      name = "PATH";
      op = "+=(path)";
      value = "/opt/bin";
    }
  ];

  # `options` is a reserved top-level attribute name for a Nix
  # module: nest it under `config` (see `profile.PROFILE.1-1`).
  optionsEx.config.options = {
    # Rendered as `mylib/*:shared=True`.
    "mylib/*:shared" = "True";
  };

  runEnvEx.runEnv = [
    # Rendered as `LD_LIBRARY_PATH+=(path)/opt/lib`.
    {
      name = "LD_LIBRARY_PATH";
      op = "+=(path)";
      value = "/opt/lib";
    }
  ];

  confEx.conf = {
    # Rendered as `tools.build:jobs=4`.
    "tools.build:jobs" = "4";
  };

  toolRequiresEx.toolRequires = {
    # Rendered as `tool1/0.1@user/channel`.
    tool1 = "0.1@user/channel";
  };

  replaceRequiresEx.replaceRequires = {
    # Rendered as `zlib/1.2.12: zlib/[*]`.
    "zlib/1.2.12" = "zlib/[*]";
    # Rendered as `dep/*: dep/*@system`.
    "dep/*" = "dep/*@system";
  };

  replaceToolRequiresEx.replaceToolRequires = {
    # Rendered as `7zip/*: 7zip/system`.
    "7zip/*" = "7zip/system";
    # Rendered as `cmake/*: cmake/3.25.2`.
    "cmake/*" = "cmake/3.25.2";
  };

  platformRequiresEx.platformRequires = {
    # Rendered as `dlib/1.3.22`.
    dlib = "1.3.22";
  };

  platformToolRequiresEx.platformToolRequires = {
    # Rendered as `cmake/3.24.2`.
    cmake = "3.24.2";
  };
}

Declared by:

perSystem.conan.remotes

Conan remote repositories.

Type: lazy attribute set of (submodule)

Default:

{ }

Declared by:

perSystem.conan.remotes.<name>.enable

Enable this remote.

Type: boolean

Default:

true

Declared by:

perSystem.conan.remotes.<name>.allowedPackages

Allowed packages.

Type: null or (list of string)

Default:

null

Declared by:

perSystem.conan.remotes.<name>.local

Whether this remote is of local-recipes-index type.

Type: boolean

Default:

false

Declared by:

perSystem.conan.remotes.<name>.name

Name of the remote.

Type: string

Default: remote’s name

Declared by:

perSystem.conan.remotes.<name>.url

Remote’s URL.

Type: relative path not in the Nix store or string

Declared by:

perSystem.conan.remotes.<name>.verifySsl

Whether to verify SSL.

Type: boolean

Default:

true

Declared by:

perSystem.conan.settings

Conan user settings (settings_user.yml).

Type: submodule

Declared by:

perSystem.conan.settings.compiler

Conan user settings compiler properties (compiler section in settings_user.yml).

Type: attribute set

Default:

{ }

Declared by:

perSystem.conan.settings.core

Conan global.conf core properties (configuration variables matching the “core.*” pattern).

Type: attribute set

Default:

{ }

Declared by:

perSystem.conan.settings.globalConfData

The conf-outputing derivation generated for the global configuration.

Type: package (read only)

Default:

pkgs.writeText "profile" ''
  ${lib.strings.concatMapAttrsStringSep "\n" (
    name: value: "core.${name}=${value}"
  ) final.settings.core}
  ${lib.strings.concatMapAttrsStringSep "\n" (
    name: value: "tools.${name}=${value}"
  ) final.settings.tools}
  ${lib.strings.concatMapAttrsStringSep "\n" (
    name: value: "user.${name}=${value}"
  ) final.settings.user}

Declared by:

perSystem.conan.settings.settingsUserYamlData

The YAML-outputing derivation generated for the user configuration.

Type: package (read only)

Default:

(pkgs.formats.yaml { }).generate "settings_user.yml" final.settings.compiler

Declared by:

perSystem.conan.settings.tools

Conan global.conf tools properties (configuration variables matching the “tools.*” pattern).

Type: attribute set

Default:

{ }

Declared by:

perSystem.conan.settings.user

Conan global.conf user properties (configuration variables matching the “user.*” pattern).

Type: attribute set

Default:

{ }

Declared by:

perSystem.conan.stdenv

The stdenv derivation to use for the Conan environment.

Type: package

Default:

pkgs.stdenv

Example:

pkgs.llvmPackages.libcxxStdenv
pkgs.cudaPackages.backendStdenv

Declared by:

perSystem.conan.wrappers.conanFlakeLockFile

The path to the lock file to output or null to disable lock file generation. Defaults to null.

Type: null or string

Default:

null

Example:

"conan-flake.lock"

Declared by:

perSystem.conan.wrappers.conanInstall

Whether to run conan install automatically during shell activation. Defaults to false.

Type: boolean

Default:

false

Declared by:

perSystem.conan.wrappers.conanLockFile

The conan lock file to generate, or null to disable lock file generation. Defaults to null.

Type: null or string

Default:

null

Example:

"conan.lock"

Declared by:

perSystem.conan.wrappers.infoWrapperStdoutOutput

Whether to output the lock file to stdout. Defaults to true.

Type: boolean

Default:

true

Declared by: