mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-27 16:33:05 +03:00
fix(rust): correct overrideAttrs behaviour
This commit is contained in:
parent
59de99b3be
commit
6460f3f0ee
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user