2023-10-25 13:29:28 +02:00
|
|
|
{ lib
|
|
|
|
, stdenvNoCC
|
|
|
|
, dart
|
|
|
|
, dartHooks
|
2023-10-26 06:28:17 +02:00
|
|
|
, jq
|
2023-10-25 13:29:28 +02:00
|
|
|
, yq
|
|
|
|
, cacert
|
|
|
|
}:
|
|
|
|
|
|
|
|
{
|
|
|
|
# Arguments used in the derivation that builds the Dart package.
|
|
|
|
# Passing these is recommended to ensure that the same steps are made to
|
|
|
|
# prepare the sources in both this derivation and the one that builds the Dart
|
|
|
|
# package.
|
2023-10-26 06:28:17 +02:00
|
|
|
buildDrvArgs ? { }
|
2023-10-25 13:29:28 +02:00
|
|
|
, ...
|
|
|
|
}@args:
|
|
|
|
|
2023-12-26 20:50:50 +01:00
|
|
|
# This is a derivation and setup hook that can be used to fetch dependencies for Dart projects.
|
2023-10-25 13:29:28 +02:00
|
|
|
# It is designed to be placed in the nativeBuildInputs of a derivation that builds a Dart package.
|
|
|
|
# Providing the buildDrvArgs argument is highly recommended.
|
|
|
|
let
|
|
|
|
buildDrvInheritArgNames = [
|
|
|
|
"name"
|
|
|
|
"pname"
|
|
|
|
"version"
|
|
|
|
"src"
|
|
|
|
"sourceRoot"
|
|
|
|
"setSourceRoot"
|
|
|
|
"preUnpack"
|
|
|
|
"unpackPhase"
|
|
|
|
"unpackCmd"
|
|
|
|
"postUnpack"
|
|
|
|
"prePatch"
|
|
|
|
"patchPhase"
|
|
|
|
"patches"
|
|
|
|
"patchFlags"
|
|
|
|
"postPatch"
|
|
|
|
];
|
|
|
|
|
|
|
|
buildDrvInheritArgs = builtins.foldl'
|
|
|
|
(attrs: arg:
|
|
|
|
if buildDrvArgs ? ${arg}
|
|
|
|
then attrs // { ${arg} = buildDrvArgs.${arg}; }
|
|
|
|
else attrs)
|
|
|
|
{ }
|
|
|
|
buildDrvInheritArgNames;
|
|
|
|
|
|
|
|
drvArgs = buildDrvInheritArgs // (removeAttrs args [ "buildDrvArgs" ]);
|
|
|
|
name = (if drvArgs ? name then drvArgs.name else "${drvArgs.pname}-${drvArgs.version}");
|
|
|
|
|
2023-10-26 06:28:17 +02:00
|
|
|
# Adds the root package to a dependency package_config.json file from pub2nix.
|
2023-10-26 06:40:37 +02:00
|
|
|
linkPackageConfig = { packageConfig, extraSetupCommands ? "" }: stdenvNoCC.mkDerivation (drvArgs // {
|
2023-10-26 06:28:17 +02:00
|
|
|
name = "${name}-package-config-with-root.json";
|
|
|
|
|
|
|
|
nativeBuildInputs = drvArgs.nativeBuildInputs or [ ] ++ args.nativeBuildInputs or [ ] ++ [ jq yq ];
|
|
|
|
|
|
|
|
dontBuild = true;
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
packageName="$(yq --raw-output .name pubspec.yaml)"
|
|
|
|
jq --arg name "$packageName" '.packages |= . + [{ name: $name, rootUri: "../", packageUri: "lib/" }]' '${packageConfig}' > "$out"
|
2023-10-26 06:40:37 +02:00
|
|
|
${extraSetupCommands}
|
2023-10-26 06:28:17 +02:00
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
});
|
2023-10-25 13:29:28 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
inherit
|
2023-10-28 16:23:47 +02:00
|
|
|
linkPackageConfig;
|
2023-10-25 13:29:28 +02:00
|
|
|
}
|