To detect nativeDir, the currently generated deps.nix contains this logic:
nativeDir = "${old.src}/native/${with builtins; head (attrNames (readDir "${old.src}/native"))}";
fenix =
if toolchain == null then
extendedPkgs.fenix.stable
else
extendedPkgs.fenix.fromToolchainName toolchain;
native =
(extendedPkgs.makeRustPlatform {
inherit (fenix) cargo rustc;
}).buildRustPackage
{
pname = "${old.packageName}-native";
version = old.version;
src = nativeDir;
cargoLock = {
lockFile = "${nativeDir}/Cargo.lock";
};
nativeBuildInputs = [
extendedPkgs.cmake
];
doCheck = false;
};
causing src = nativeDir and lockFile = "${nativeDir}/Cargo.lock" to trigger an Import from Derivation.
Even though allow-import-from-derivation is true by default, it is forbidden in Nixpkgs.
AFAICS, there is no easy way to avoid that IfD by provisioning nativeDir and Cargo.lock through an override.
I had to override preConfigure entirely, as in this overrideAttrsRust:
overrideAttrsRust = nativeDir: finalRust: previousRust: {
preConfigure = ''
mkdir -p priv/native
for lib in ${finalRust.passthru.native}/lib/*
do
dest="$(basename "$lib")"
if [[ "''${dest##*.}" = "dylib" ]]
then
dest="''${dest%.dylib}.so"
fi
ln -s "$lib" "priv/native/$dest"
done
'';
passthru = previousRust.passthru // {
inherit nativeDir;
native = rustPlatform.buildRustPackage {
pname = "${previousRust.passthru.packageName}-native";
version = previousRust.version;
src = "${previousRust.src}/native/${finalRust.passthru.nativeDir}";
cargoLock = {
lockFile = ./deps + "/${previousRust.passthru.packageName}/Cargo.lock";
};
nativeBuildInputs = [
cmake
];
doCheck = false;
};
updateScript = writeShellScriptBin "${previousRust.passthru.packageName}-update" ''
set -eux
install -Dm660 "${finalRust.src}/native/${finalRust.passthru.nativeDir}/Cargo.lock" \
'pkgs/by-name/bonfire/deps/${previousRust.passthru.packageName}/Cargo.lock'
'';
};
};
Usage example of overrideAttrsRust:
mixNixDeps = import ./deps.nix {
inherit lib pkgs beamPackages;
overrides =
finalMixPkgs: previousMixPkgs:
{
autumn = previousMixPkgs.autumn.overrideAttrs (overrideAttrsRust "autumnus_nif");
mdex = previousMixPkgs.mdex.overrideAttrs (overrideAttrsRust "comrak_nif");
mjml = previousMixPkgs.mjml.overrideAttrs (overrideAttrsRust "mjml_nif");
}
};
To detect
nativeDir, the currently generateddeps.nixcontains this logic:causing
src = nativeDirandlockFile = "${nativeDir}/Cargo.lock"to trigger an Import from Derivation.Even though
allow-import-from-derivationis true by default, it is forbidden in Nixpkgs.AFAICS, there is no easy way to avoid that IfD by provisioning
nativeDirandCargo.lockthrough an override.I had to override
preConfigureentirely, as in thisoverrideAttrsRust:Usage example of
overrideAttrsRust: