diff --git a/src/modules/utils.override/implementation.nix b/src/modules/utils.override/implementation.nix index 3bd937fb..b1b33d59 100644 --- a/src/modules/utils.override/implementation.nix +++ b/src/modules/utils.override/implementation.nix @@ -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 diff --git a/src/subsystems/rust/builders/build-rust-package/default.nix b/src/subsystems/rust/builders/build-rust-package/default.nix index 2b45a767..95d61a52 100644 --- a/src/subsystems/rust/builders/build-rust-package/default.nix +++ b/src/subsystems/rust/builders/build-rust-package/default.nix @@ -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: diff --git a/src/subsystems/rust/builders/crane/default.nix b/src/subsystems/rust/builders/crane/default.nix index 85524e47..f02463db 100644 --- a/src/subsystems/rust/builders/crane/default.nix +++ b/src/subsystems/rust/builders/crane/default.nix @@ -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; diff --git a/src/subsystems/rust/builders/utils.nix b/src/subsystems/rust/builders/utils.nix index d66e2379..2d30667f 100644 --- a/src/subsystems/rust/builders/utils.nix +++ b/src/subsystems/rust/builders/utils.nix @@ -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;