mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-28 08:59:04 +03:00
fix(rust): correct overrideAttrs behaviour
This commit is contained in:
parent
59de99b3be
commit
6460f3f0ee
@ -143,7 +143,7 @@
|
|||||||
l.mapAttrs
|
l.mapAttrs
|
||||||
(funcName: func: getOverrideFunctionArgs func)
|
(funcName: func: getOverrideFunctionArgs func)
|
||||||
(l.filterAttrs
|
(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);
|
base_derivation);
|
||||||
|
|
||||||
getOverrideFuncNameForAttrName = attrName: let
|
getOverrideFuncNameForAttrName = attrName: let
|
||||||
|
@ -39,8 +39,7 @@
|
|||||||
writeGitVendorEntries = vendoring.writeGitVendorEntries "vendored-sources";
|
writeGitVendorEntries = vendoring.writeGitVendorEntries "vendored-sources";
|
||||||
|
|
||||||
cargoBuildFlags = "--package ${pname}";
|
cargoBuildFlags = "--package ${pname}";
|
||||||
in
|
buildArgs = {
|
||||||
produceDerivation pname (buildWithToolchain defaultToolchain {
|
|
||||||
inherit pname version src;
|
inherit pname version src;
|
||||||
|
|
||||||
meta = utils.getMeta pname version;
|
meta = utils.getMeta pname version;
|
||||||
@ -65,6 +64,11 @@
|
|||||||
${replacePaths}
|
${replacePaths}
|
||||||
${utils.writeCargoLock}
|
${utils.writeCargoLock}
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
|
in
|
||||||
|
produceDerivation pname (buildWithToolchain {
|
||||||
|
toolchain = defaultToolchain;
|
||||||
|
args = buildArgs;
|
||||||
});
|
});
|
||||||
|
|
||||||
mkShellForPkg = pkg:
|
mkShellForPkg = pkg:
|
||||||
|
@ -85,7 +85,7 @@
|
|||||||
inherit (utils) cargoLock;
|
inherit (utils) cargoLock;
|
||||||
pnameSuffix = depsNameSuffix;
|
pnameSuffix = depsNameSuffix;
|
||||||
# Make sure cargo only checks the package we want
|
# 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;
|
dream2nixVendorDir = vendoring.vendoredDependencies;
|
||||||
preUnpack = ''
|
preUnpack = ''
|
||||||
${vendoring.copyVendorDir "$dream2nixVendorDir" common.cargoVendorDir}
|
${vendoring.copyVendorDir "$dream2nixVendorDir" common.cargoVendorDir}
|
||||||
@ -98,7 +98,10 @@
|
|||||||
deps =
|
deps =
|
||||||
produceDerivation
|
produceDerivation
|
||||||
"${pname}${depsNameSuffix}"
|
"${pname}${depsNameSuffix}"
|
||||||
(buildDepsWithToolchain defaultToolchain depsArgs);
|
(buildDepsWithToolchain {
|
||||||
|
toolchain = defaultToolchain;
|
||||||
|
args = depsArgs;
|
||||||
|
});
|
||||||
|
|
||||||
buildArgs =
|
buildArgs =
|
||||||
common
|
common
|
||||||
@ -118,10 +121,15 @@
|
|||||||
'';
|
'';
|
||||||
passthru = {dependencies = deps;};
|
passthru = {dependencies = deps;};
|
||||||
};
|
};
|
||||||
|
build =
|
||||||
|
produceDerivation
|
||||||
|
pname
|
||||||
|
(buildPackageWithToolchain {
|
||||||
|
toolchain = defaultToolchain;
|
||||||
|
args = buildArgs;
|
||||||
|
});
|
||||||
in
|
in
|
||||||
produceDerivation
|
build;
|
||||||
pname
|
|
||||||
(buildPackageWithToolchain defaultToolchain buildArgs);
|
|
||||||
|
|
||||||
mkShellForPkg = pkg: let
|
mkShellForPkg = pkg: let
|
||||||
pkgDeps = pkg.passthru.dependencies;
|
pkgDeps = pkg.passthru.dependencies;
|
||||||
|
@ -14,6 +14,41 @@
|
|||||||
}: let
|
}: let
|
||||||
l = lib // builtins;
|
l = lib // builtins;
|
||||||
isInPackages = name: version: (packages.${name} or null) == version;
|
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 {
|
in rec {
|
||||||
getMeta = pname: version: let
|
getMeta = pname: version: let
|
||||||
meta = subsystemAttrs.meta.${pname}.${version};
|
meta = subsystemAttrs.meta.${pname}.${version};
|
||||||
@ -53,32 +88,10 @@ in rec {
|
|||||||
'';
|
'';
|
||||||
|
|
||||||
mkBuildWithToolchain = mkBuildFunc: let
|
mkBuildWithToolchain = mkBuildFunc: let
|
||||||
buildWithToolchain = toolchain: args: let
|
buildWithToolchain = args:
|
||||||
_drv = (mkBuildFunc toolchain) args;
|
makeOverridable
|
||||||
drv =
|
(args: {derivation = (mkBuildFunc args.toolchain) args.args;})
|
||||||
_drv
|
args;
|
||||||
// {
|
|
||||||
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)
|
|
||||||
);
|
|
||||||
};
|
|
||||||
in
|
in
|
||||||
buildWithToolchain;
|
buildWithToolchain;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user