{# Argument: struct crate2nix::BuildInfo Rendered via https://tera.netlify.com #} # This file was @generated by crate2nix {{info.crate2nix_version | safe}} with the command: # {% for arg in info.crate2nix_arguments %} {{arg}}{% endfor %} # See https://github.com/kolloch/crate2nix for more info. { nixpkgs ? {{config.nixpkgs_path | safe}} , pkgs ? import nixpkgs { config = {}; } , lib ? pkgs.lib , stdenv ? pkgs.stdenv , buildRustCrateForPkgs ? pkgs: pkgs.buildRustCrate # This is used as the `crateOverrides` argument for `buildRustCrate`. , defaultCrateOverrides ? pkgs.defaultCrateOverrides # The features to enable for the root_crate or the workspace_members. , rootFeatures ? [ "default" ] # If true, throw errors instead of issueing deprecation warnings. , strictDeprecation ? false # Elements to add to the `-C target-feature=` argument passed to `rustc` # (separated by `,`, prefixed with `+`). # Used for conditional compilation based on CPU feature detection. , targetFeatures ? [] # Whether to perform release builds: longer compile times, faster binaries. , release ? true # Additional crate2nix configuration if it exists. , crateConfig ? if builtins.pathExists ./crate-config.nix then pkgs.callPackage ./crate-config.nix {} else {} }: rec { # # "public" attributes that we attempt to keep stable with new versions of crate2nix. # {% if root_package_id -%} rootCrate = rec { packageId = {{root_package_id}}; # Use this attribute to refer to the derivation building your root crate package. # You can override the features with rootCrate.build.override { features = [ "default" "feature1" ... ]; }. build = internal.buildRustCrateWithFeatures { inherit packageId; }; # Debug support which might change between releases. # File a bug if you depend on any for non-debug work! debug = internal.debugCrate { inherit packageId; }; }; {%- endif -%} {% if workspace_members %} # Refer your crate build derivation by name here. # You can override the features with # workspaceMembers."${crateName}".build.override { features = [ "default" "feature1" ... ]; }. workspaceMembers = { {%- for name, pkg_id in workspace_members %} {{name}} = rec { packageId = {{pkg_id}}; build = internal.buildRustCrateWithFeatures { packageId = {{pkg_id}}; }; # Debug support which might change between releases. # File a bug if you depend on any for non-debug work! debug = internal.debugCrate { inherit packageId; }; }; {%- endfor %} }; {%- endif %} # A derivation that joins the outputs of all workspace members together. allWorkspaceMembers = pkgs.symlinkJoin { name = "all-workspace-members"; paths = let members = builtins.attrValues workspaceMembers; in builtins.map (m: m.build) members; }; # # "internal" ("private") attributes that may change in every new version of crate2nix. # internal = rec { # Build and dependency information for crates. # Many of the fields are passed one-to-one to buildRustCrate. # # Noteworthy: # * `dependencies`/`buildDependencies`: similar to the corresponding fields for buildRustCrate. # but with additional information which is used during dependency/feature resolution. # * `resolvedDependencies`: the selected default features reported by cargo - only included for debugging. # * `devDependencies` as of now not used by `buildRustCrate` but used to # inject test dependencies into the build crates = { {%- for crate in crates %} {{crate.package_id}} = rec { crateName = {{crate.crate_name}}; version = {{crate.version}}; edition = {{crate.edition}}; {%- if crate.links %} links = {{crate.links}}; {%- endif %} {%- if crate.binaries|length > 0 and not crate.is_root_or_workspace_member %} crateBin = []; {%- elif crate.binaries|length > 0 and crate.is_root_or_workspace_member %} crateBin = [ {%- set bins_sorted = crate.binaries|sort(attribute="name") -%} {%- for bin in bins_sorted %} { name = {{ bin.name }}; path = {{ bin.src_path }}; requiredFeatures = [ {% for feature in bin.required_features %}{{feature}} {% endfor %}]; } {%- endfor %} ]; {%- endif -%} {%- if crate.source.CratesIo.sha256 %} sha256 = {{crate.source.CratesIo.sha256}}; {%- elif crate.source.Nix.file.import and crate.source.Nix.attr %} src = (import {{crate.source.Nix.file.import | safe}}).{{crate.source.Nix.attr | safe}}; {%- elif crate.source.Nix.file.package and crate.source.Nix.attr %} src = (pkgs.callPackage {{crate.source.Nix.file.package | safe}} {}).{{crate.source.Nix.attr | safe}}; {%- elif crate.source.Nix.file.import %} src = import {{crate.source.Nix.file.import | safe}}; {%- elif crate.source.Nix.file.package %} src = pkgs.callPackage {{crate.source.Nix.file.package | safe}} {}; {%- elif crate.source.LocalDirectory.path %} src = lib.cleanSourceWith { filter = sourceFilter; src = {{crate.source.LocalDirectory.path | safe}}; }; {%- elif crate.source.Git %} workspace_member = null; src = pkgs.fetchgit { url = {{crate.source.Git.url}}; rev = {{crate.source.Git.rev}}; {%- if crate.source.Git.sha256 %} sha256 = {{ crate.source.Git.sha256 }}; {%- endif %} }; {%- else %} src = builtins.throw ''ERROR: Could not resolve source: {{crate.source | json_encode() | safe}}''; {%- endif -%} {%- if crate.proc_macro %} procMacro = true; {%- endif -%} {%- if crate.build.src_path and crate.build.src_path != "build.rs" -%} {#- This defaults to "build.rs". #} build = {{crate.build.src_path}}; {%- endif -%} {%- if crate.lib and crate.lib.name and crate.lib.name != crate.crate_name -%} {#- This defaults to crateName. #} libName = {{crate.lib.name}}; {%- endif -%} {%- if crate.lib and crate.lib.src_path and crate.lib.src_path != "src/lib.rs" -%} {#- This defaults to empty which triggers some auto-probing. #} libPath = {{crate.lib.src_path}}; {%- endif -%} {%- if not crate.proc_macro -%} {#- Omitting []. -#} {%- if crate.lib_crate_types|length > 0 -%} {#- Omitting [ "lib" ]. -#} {%- if crate.lib_crate_types|length != 1 or crate.lib_crate_types[0] != "lib" -%} type = [{%- for crate_type in crate.lib_crate_types %} {{ crate_type }}{%- endfor %} ]; {%- endif -%} {%- endif -%} {%- endif -%} {%- if crate.authors|length > 0 %} authors = [ {%- for author in crate.authors %} {{author}} {%- endfor %} ]; {%- endif -%} {%- if crate.dependencies|length > 0 %} dependencies = [ {%- for dependency in crate.dependencies %} { name = {{dependency.name}}; packageId = {{dependency.package_id}}; {%- if dependency.rename %} rename = {{dependency.rename}}; {%- endif %} {%- if dependency.optional %} optional = true; {%- endif -%} {%- if not dependency.uses_default_features %} usesDefaultFeatures = false; {%- endif -%} {%- if dependency.target %} target = { target, features }: {{dependency.target | cfg_to_nix_expr | safe }}; {%- endif %} {%- if dependency.features %} features = [ {% for feature in dependency.features %}{{feature}} {% endfor %}]; {%- endif %} } {%- endfor %} ]; {%- endif -%} {%- if crate.build_dependencies|length > 0 %} buildDependencies = [ {%- for dependency in crate.build_dependencies %} { name = {{dependency.name}}; packageId = {{dependency.package_id}}; {%- if dependency.optional %} optional = true; {%- endif -%} {%- if dependency.rename %} rename = {{dependency.rename}}; {%- endif %} {%- if not dependency.uses_default_features %} usesDefaultFeatures = false; {%- endif -%} {%- if dependency.target %} target = {target, features}: {{dependency.target | cfg_to_nix_expr | safe }}; {%- endif %} {%- if dependency.features %} features = [ {% for feature in dependency.features %}{{feature}} {% endfor %}]; {%- endif %} } {%- endfor %} ]; {%- endif -%} {%- if crate.dev_dependencies|length > 0 %} devDependencies = [ {%- for dependency in crate.dev_dependencies %} { name = {{dependency.name}}; packageId = {{dependency.package_id}}; {%- if dependency.optional %} optional = true; {%- endif -%} {%- if dependency.rename %} rename = {{dependency.rename}}; {%- endif %} {%- if not dependency.uses_default_features %} usesDefaultFeatures = false; {%- endif -%} {%- if dependency.target %} target = {target, features}: {{dependency.target | cfg_to_nix_expr | safe }}; {%- endif %} {%- if dependency.features %} features = [ {% for feature in dependency.features %}{{feature}} {% endfor %}]; {%- endif %} } {%- endfor %} ]; {%- endif -%} {#- #} {% if crate.features|length > 0 -%} features = { {%- for feature, features in crate.features -%} {% if features|length > 0 %} {{feature}} = [ {% for feature in features %}{{feature}} {% endfor %}]; {%- endif %} {%- endfor %} }; {%- endif %} {%- if crate.resolved_default_features|length > 0 %} resolvedDefaultFeatures = [ {% for feature in crate.resolved_default_features %}{{feature}} {% endfor %}]; {%- endif %} }; {%- endfor %} }; {% include "nix/crate2nix/default.nix" %} }; }