2023-10-09 19:29:22 +00:00
|
|
|
{ lib, stdenv, fetchDartDeps, runCommand, writeText, dartHooks, makeWrapper, dart, cacert, nodejs, darwin }:
|
2023-05-24 13:37:59 +00:00
|
|
|
|
|
|
|
{ pubGetScript ? "dart pub get"
|
|
|
|
|
|
|
|
# Output type to produce. Can be any kind supported by dart
|
|
|
|
# https://dart.dev/tools/dart-compile#types-of-output
|
|
|
|
# If using jit, you might want to pass some arguments to `dartJitFlags`
|
|
|
|
, dartOutputType ? "exe"
|
|
|
|
, dartCompileCommand ? "dart compile"
|
|
|
|
, dartCompileFlags ? [ ]
|
|
|
|
# These come at the end of the command, useful to pass flags to the jit run
|
|
|
|
, dartJitFlags ? [ ]
|
|
|
|
|
|
|
|
# Attrset of entry point files to build and install.
|
|
|
|
# Where key is the final binary path and value is the source file path
|
|
|
|
# e.g. { "bin/foo" = "bin/main.dart"; }
|
|
|
|
# Set to null to read executables from pubspec.yaml
|
|
|
|
, dartEntryPoints ? null
|
|
|
|
# Used when wrapping aot, jit, kernel, and js builds.
|
|
|
|
# Set to null to disable wrapping.
|
|
|
|
, dartRuntimeCommand ?
|
|
|
|
if dartOutputType == "aot-snapshot" then "${dart}/bin/dartaotruntime"
|
|
|
|
else if (dartOutputType == "jit-snapshot" || dartOutputType == "kernel") then "${dart}/bin/dart"
|
|
|
|
else if dartOutputType == "js" then "${nodejs}/bin/node"
|
|
|
|
else null
|
|
|
|
|
|
|
|
, pubspecLockFile ? null
|
|
|
|
, vendorHash ? ""
|
|
|
|
, ...
|
|
|
|
}@args:
|
|
|
|
|
|
|
|
let
|
2023-10-09 19:29:22 +00:00
|
|
|
dartDeps = (fetchDartDeps.override {
|
|
|
|
dart = runCommand "dart-fod" { nativeBuildInputs = [ makeWrapper ]; } ''
|
|
|
|
mkdir -p "$out/bin"
|
|
|
|
makeWrapper "${dart}/bin/dart" "$out/bin/dart" \
|
|
|
|
--add-flags "--root-certs-file=${cacert}/etc/ssl/certs/ca-bundle.crt"
|
|
|
|
'';
|
|
|
|
}) {
|
2023-05-24 13:37:59 +00:00
|
|
|
buildDrvArgs = args;
|
|
|
|
inherit pubGetScript vendorHash pubspecLockFile;
|
|
|
|
};
|
|
|
|
inherit (dartHooks.override { inherit dart; }) dartConfigHook dartBuildHook dartInstallHook;
|
|
|
|
in
|
|
|
|
assert !(builtins.isString dartOutputType && dartOutputType != "") ->
|
|
|
|
throw "dartOutputType must be a non-empty string";
|
|
|
|
stdenv.mkDerivation (args // {
|
|
|
|
inherit pubGetScript dartCompileCommand dartOutputType dartRuntimeCommand
|
|
|
|
dartCompileFlags dartJitFlags;
|
|
|
|
|
|
|
|
dartEntryPoints =
|
|
|
|
if (dartEntryPoints != null)
|
|
|
|
then writeText "entrypoints.json" (builtins.toJSON dartEntryPoints)
|
|
|
|
else null;
|
|
|
|
|
|
|
|
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [
|
|
|
|
dart
|
|
|
|
dartDeps
|
|
|
|
dartConfigHook
|
|
|
|
dartBuildHook
|
|
|
|
dartInstallHook
|
|
|
|
makeWrapper
|
2023-07-15 17:15:38 +00:00
|
|
|
] ++ lib.optionals stdenv.isDarwin [
|
|
|
|
darwin.sigtool
|
2023-05-24 13:37:59 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
# When stripping, it seems some ELF information is lost and the dart VM cli
|
|
|
|
# runs instead of the expected program. Don't strip if it's an exe output.
|
|
|
|
dontStrip = args.dontStrip or (dartOutputType == "exe");
|
|
|
|
|
|
|
|
passthru = { inherit dartDeps; } // (args.passthru or { });
|
|
|
|
|
|
|
|
meta = (args.meta or { }) // { platforms = args.meta.platforms or dart.meta.platforms; };
|
|
|
|
})
|