feat(rust-crane): get rid of depsDrvOptions and use mkDerivation as a submodule instead

This commit is contained in:
DavHau 2023-08-29 00:19:08 +02:00
parent 42ac2de3a3
commit 9b721a5cd3
3 changed files with 21 additions and 15 deletions

View File

@ -27,7 +27,7 @@ in {
sha256 = "sha256-udEh+Re2PeO3DnX4fQThsaT1Y3MBHFfrX5Q5EN2XrF0=";
};
# note: any more options defined here will be applied to both
# `rust-crane.mainDrvOptions` and `rust-crane.depsDrvOptions`.
# `config.mkDerivation` and `config.depsDrv.mkDerivation`.
};
rust-crane = {

View File

@ -165,6 +165,7 @@
# we pass cargoLock path to buildDepsOnly
# so that crane's mkDummySrc adds it to the dummy source
inherit (utils) cargoLock;
pname = l.mkOverride 99 pname;
pnameSuffix = depsNameSuffix;
# Make sure cargo only checks the package we want
cargoCheckCommand = "cargo check \${cargoBuildFlags:-} --profile \${cargoBuildProfile} --package ${pname}";
@ -183,26 +184,30 @@
${common.preConfigure}
${utils.writeCargoLock}
'';
cargoArtifacts = packageDeps;
cargoArtifacts = cfg.depsDrv.public;
};
packageDeps = crane.buildDepsOnly cfg.depsDrvOptions;
in {
imports = [
./interface.nix
dream2nix.modules.drv-parts.mkDerivation
];
rust-crane.depsDrvOptions = l.mkMerge [
rust-crane.depsDrv = {
inherit version;
name = pname + depsNameSuffix;
mkDerivation = builtins.removeAttrs config.mkDerivation ["src"];
package-func.func = crane.buildDepsOnly;
package-func.args = l.mkMerge [
common
depsArgs
];
};
package-func.func = crane.buildPackage;
package-func.args = l.mkMerge [common buildArgs];
public = {
dependencies = packageDeps;
dependencies = cfg.depsDrv.public;
meta = utils.getMeta pname version;
};

View File

@ -1,6 +1,7 @@
{
config,
lib,
dream2nix,
specialArgs,
...
}: let
l = lib // builtins;
@ -53,12 +54,12 @@ in {
description = "Flags to add when running `cargo test`";
default = [];
};
# TODO: use mkDerivation module interface here
depsDrvOptions = {
type = t.submodule {
freeformType = t.attrsOf t.raw;
depsDrv = {
type = t.submoduleWith {
modules = [dream2nix.modules.drv-parts.mkDerivation];
inherit specialArgs;
};
description = "Attributes to pass to the buildDepsOnly function";
description = "A single derivation with all dependencies of the package";
default = {};
};
};