fix(rust): correct overrideAttrs behaviour

This commit is contained in:
Yusuf Bera Ertan 2022-12-18 02:13:24 +03:00
parent 59de99b3be
commit 6460f3f0ee
No known key found for this signature in database
GPG Key ID: 1D8F8FAF2294D6EA
4 changed files with 59 additions and 34 deletions

View File

@ -143,7 +143,7 @@
l.mapAttrs
(funcName: func: getOverrideFunctionArgs func)
(l.filterAttrs
(funcName: func: l.hasPrefix "override" funcName && funcName != "overrideDerivation" && funcName != "overridePythonAttrs")
(funcName: func: l.hasPrefix "override" funcName && (! b.elem funcName ["overrideDerivation" "overridePythonAttrs" "overrideRustToolchain"]))
base_derivation);
getOverrideFuncNameForAttrName = attrName: let

View File

@ -39,8 +39,7 @@
writeGitVendorEntries = vendoring.writeGitVendorEntries "vendored-sources";
cargoBuildFlags = "--package ${pname}";
in
produceDerivation pname (buildWithToolchain defaultToolchain {
buildArgs = {
inherit pname version src;
meta = utils.getMeta pname version;
@ -65,6 +64,11 @@
${replacePaths}
${utils.writeCargoLock}
'';
};
in
produceDerivation pname (buildWithToolchain {
toolchain = defaultToolchain;
args = buildArgs;
});
mkShellForPkg = pkg:

View File

@ -85,7 +85,7 @@
inherit (utils) cargoLock;
pnameSuffix = depsNameSuffix;
# Make sure cargo only checks the package we want
cargoCheckCommand = "cargo check --release --package ${pname}";
cargoCheckCommand = "cargo check \${cargoBuildFlags:-} --profile \${cargoBuildProfile} --package ${pname}";
dream2nixVendorDir = vendoring.vendoredDependencies;
preUnpack = ''
${vendoring.copyVendorDir "$dream2nixVendorDir" common.cargoVendorDir}
@ -98,7 +98,10 @@
deps =
produceDerivation
"${pname}${depsNameSuffix}"
(buildDepsWithToolchain defaultToolchain depsArgs);
(buildDepsWithToolchain {
toolchain = defaultToolchain;
args = depsArgs;
});
buildArgs =
common
@ -118,10 +121,15 @@
'';
passthru = {dependencies = deps;};
};
build =
produceDerivation
pname
(buildPackageWithToolchain {
toolchain = defaultToolchain;
args = buildArgs;
});
in
produceDerivation
pname
(buildPackageWithToolchain defaultToolchain buildArgs);
build;
mkShellForPkg = pkg: let
pkgDeps = pkg.passthru.dependencies;

View File

@ -14,6 +14,41 @@
}: let
l = lib // builtins;
isInPackages = name: version: (packages.${name} or null) == version;
# a make overridable for rust derivations specifically
makeOverridable = f: origArgs: let
result = f origArgs;
# Creates a functor with the same arguments as f
copyArgs = g: l.setFunctionArgs g (l.functionArgs f);
# Changes the original arguments with (potentially a function that returns) a set of new attributes
overrideWith = newArgs:
origArgs
// (
if l.isFunction newArgs
then newArgs origArgs
else newArgs
);
# Re-call the function but with different arguments
overrideArgs = copyArgs (newArgs: makeOverridable f (overrideWith newArgs));
# Change the result of the function call by applying g to it
overrideResult = g: makeOverridable (copyArgs (args: g (f args))) origArgs;
in
result.derivation
// {
override = args:
overrideArgs {
args =
origArgs.args
// (
if l.isFunction args
then args origArgs.args
else args
);
};
overrideRustToolchain = f: overrideArgs {toolchain = f origArgs.toolchain;};
overrideAttrs = fdrv: overrideResult (x: {derivation = x.derivation.overrideAttrs fdrv;});
};
in rec {
getMeta = pname: version: let
meta = subsystemAttrs.meta.${pname}.${version};
@ -53,32 +88,10 @@ in rec {
'';
mkBuildWithToolchain = mkBuildFunc: let
buildWithToolchain = toolchain: args: let
_drv = (mkBuildFunc toolchain) args;
drv =
_drv
// {
passthru = (_drv.passthru or {}) // {rustToolchain = toolchain;};
};
mergedPassthru = attrs: oattrs: {
passthru = (attrs.passthru or {}) // (oattrs.passthru or {});
};
in
drv
// {
overrideRustToolchain = f: let
newToolchain = toolchain // (f toolchain);
in
buildWithToolchain newToolchain (
args // (mergedPassthru args newToolchain)
);
overrideAttrs = f: let
changes = f drv;
in
buildWithToolchain toolchain (
args // changes // (mergedPassthru args changes)
);
};
buildWithToolchain = args:
makeOverridable
(args: {derivation = (mkBuildFunc args.toolchain) args.args;})
args;
in
buildWithToolchain;