diff options
author | hacker1024 <hacker1024@users.sourceforge.net> | 2023-10-21 22:30:23 +1100 |
---|---|---|
committer | hacker1024 <hacker1024@users.sourceforge.net> | 2023-10-21 22:30:23 +1100 |
commit | 6298ac27745cbab2dd3895c2c25ad3a795310f78 (patch) | |
tree | 6a03d7c50993c52243eb0a35dd4a82bb58b4998e /pkgs/build-support | |
parent | 234b63b0f0668770f9136eb06c718787aed4d342 (diff) |
buildDartApplication: Use package override mechanism from buildFlutterApplication
This allows Dart applications to benefit from the package override system, which is useful for things like FFI dependencies.
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/dart/build-dart-application/default.nix | 102 |
1 files changed, 73 insertions, 29 deletions
diff --git a/pkgs/build-support/dart/build-dart-application/default.nix b/pkgs/build-support/dart/build-dart-application/default.nix index 2246c5634d27c..6992c79a37ed1 100644 --- a/pkgs/build-support/dart/build-dart-application/default.nix +++ b/pkgs/build-support/dart/build-dart-application/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchDartDeps, runCommand, writeText, dartHooks, makeWrapper, dart, cacert, nodejs, darwin }: +{ lib, stdenv, callPackage, fetchDartDeps, runCommand, writeText, dartHooks, makeWrapper, dart, cacert, nodejs, darwin, jq }: { pubGetScript ? "dart pub get" @@ -24,6 +24,9 @@ else null , runtimeDependencies ? [ ] +, customPackageOverrides ? { } +, autoDepsList ? false +, depsListFile ? null , pubspecLockFile ? null , vendorHash ? "" , ... @@ -41,37 +44,78 @@ let inherit pubGetScript vendorHash pubspecLockFile; }; inherit (dartHooks.override { inherit dart; }) dartConfigHook dartBuildHook dartInstallHook dartFixupHook; -in -assert !(builtins.isString dartOutputType && dartOutputType != "") -> -throw "dartOutputType must be a non-empty string"; -stdenv.mkDerivation (args // { - inherit pubGetScript dartCompileCommand dartOutputType dartRuntimeCommand - dartCompileFlags dartJitFlags runtimeDependencies; - dartEntryPoints = - if (dartEntryPoints != null) - then writeText "entrypoints.json" (builtins.toJSON dartEntryPoints) - else null; + baseDerivation = stdenv.mkDerivation (finalAttrs: args // { + inherit pubGetScript dartCompileCommand dartOutputType dartRuntimeCommand + dartCompileFlags dartJitFlags runtimeDependencies; + + dartEntryPoints = + if (dartEntryPoints != null) + then writeText "entrypoints.json" (builtins.toJSON dartEntryPoints) + else null; + + runtimeDependencyLibraryPath = lib.makeLibraryPath finalAttrs.runtimeDependencies; - runtimeDependencyLibraryPath = lib.makeLibraryPath runtimeDependencies; + nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ + dart + dartDeps + dartConfigHook + dartBuildHook + dartInstallHook + dartFixupHook + makeWrapper + jq + ] ++ lib.optionals stdenv.isDarwin [ + darwin.sigtool + ]; - nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ - dart - dartDeps - dartConfigHook - dartBuildHook - dartInstallHook - dartFixupHook - makeWrapper - ] ++ lib.optionals stdenv.isDarwin [ - darwin.sigtool - ]; + preUnpack = '' + ${lib.optionalString (!autoDepsList) '' + if ! { [ '${lib.boolToString (depsListFile != null)}' = 'true' ] ${lib.optionalString (depsListFile != null) "&& cmp -s <(jq -Sc . '${depsListFile}') <(jq -Sc . '${finalAttrs.passthru.dartDeps.depsListFile}')"}; }; then + echo 1>&2 -e '\nThe dependency list file was either not given or differs from the expected result.' \ + '\nPlease choose one of the following solutions:' \ + '\n - Duplicate the following file and pass it to the depsListFile argument.' \ + '\n ${finalAttrs.passthru.dartDeps.depsListFile}' \ + '\n - Set autoDepsList to true (not supported by Hydra or permitted in Nixpkgs)'. + exit 1 + fi + ''} + ${args.preUnpack or ""} + ''; + + # 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"); - # 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 { }); - passthru = { inherit dartDeps; } // (args.passthru or { }); + meta = (args.meta or { }) // { platforms = args.meta.platforms or dart.meta.platforms; }; + }); - meta = (args.meta or { }) // { platforms = args.meta.platforms or dart.meta.platforms; }; -}) + packageOverrideRepository = (callPackage ../../../development/compilers/dart/package-overrides { }) // customPackageOverrides; + productPackages = builtins.filter (package: package.kind != "dev") + (if autoDepsList + then lib.importJSON dartDeps.depsListFile + else + if depsListFile == null + then [ ] + else lib.importJSON depsListFile); +in +assert !(builtins.isString dartOutputType && dartOutputType != "") -> +throw "dartOutputType must be a non-empty string"; +builtins.foldl' + (prev: package: + if packageOverrideRepository ? ${package.name} + then + prev.overrideAttrs + (packageOverrideRepository.${package.name} { + inherit (package) + name + version + kind + source + dependencies; + }) + else prev) + baseDerivation + productPackages |