diff options
Diffstat (limited to 'pkgs/build-support/dart/build-dart-application/default.nix')
-rw-r--r-- | pkgs/build-support/dart/build-dart-application/default.nix | 129 |
1 files changed, 62 insertions, 67 deletions
diff --git a/pkgs/build-support/dart/build-dart-application/default.nix b/pkgs/build-support/dart/build-dart-application/default.nix index 2cb193ac6f161..e8e6bd16b1689 100644 --- a/pkgs/build-support/dart/build-dart-application/default.nix +++ b/pkgs/build-support/dart/build-dart-application/default.nix @@ -1,7 +1,25 @@ -{ lib, stdenv, callPackage, fetchDartDeps, runCommand, symlinkJoin, writeText, dartHooks, makeWrapper, dart, cacert, nodejs, darwin, jq }: +{ lib +, stdenv +, callPackage +, writeText +, pub2nix +, dartHooks +, makeWrapper +, dart +, nodejs +, darwin +, jq +}: -{ sdkSetupScript ? "" -, pubGetScript ? "dart pub get" +{ src +, sourceRoot ? "source" +, packageRoot ? (lib.removePrefix "/" (lib.removePrefix "source" sourceRoot)) +, gitHashes ? { } +, sdkSourceBuilders ? { } +, customSourceBuilders ? { } + +, sdkSetupScript ? "" +, extraPackageConfigSetup ? "" # Output type to produce. Can be any kind supported by dart # https://dart.dev/tools/dart-compile#types-of-output @@ -26,47 +44,52 @@ , runtimeDependencies ? [ ] , extraWrapProgramArgs ? "" -, customPackageOverrides ? { } -, autoDepsList ? false -, depsListFile ? null -, pubspecLockFile ? null -, vendorHash ? "" +, pubspecLock , ... }@args: let - dartDeps = (fetchDartDeps.override { - dart = symlinkJoin { - name = "dart-sdk-fod"; - paths = [ - (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" - '') - dart - ]; + generators = callPackage ./generators.nix { inherit dart; } { buildDrvArgs = args; }; + + pubspecLockFile = builtins.toJSON pubspecLock; + pubspecLockData = pub2nix.readPubspecLock { inherit src packageRoot pubspecLock gitHashes sdkSourceBuilders customSourceBuilders; }; + packageConfig = generators.linkPackageConfig { + packageConfig = pub2nix.generatePackageConfig { + pname = if args.pname != null then "${args.pname}-${args.version}" else null; + + dependencies = + # Ideally, we'd only include the main dependencies and their transitive + # dependencies. + # + # The pubspec.lock file does not contain information about where + # transitive dependencies come from, though, and it would be weird to + # include the transitive dependencies of dev and override dependencies + # without including the dev and override dependencies themselves. + builtins.concatLists (builtins.attrValues pubspecLockData.dependencies); + + inherit (pubspecLockData) dependencySources; }; - }) { - buildDrvArgs = args; - inherit sdkSetupScript pubGetScript vendorHash pubspecLockFile; + extraSetupCommands = extraPackageConfigSetup; }; + inherit (dartHooks.override { inherit dart; }) dartConfigHook dartBuildHook dartInstallHook dartFixupHook; - baseDerivation = stdenv.mkDerivation (finalAttrs: args // { - inherit sdkSetupScript pubGetScript dartCompileCommand dartOutputType - dartRuntimeCommand dartCompileFlags dartJitFlags runtimeDependencies; + baseDerivation = stdenv.mkDerivation (finalAttrs: (builtins.removeAttrs args [ "gitHashes" "sdkSourceBuilders" "pubspecLock" "customSourceBuilders" ]) // { + inherit pubspecLockFile packageConfig sdkSetupScript + dartCompileCommand dartOutputType dartRuntimeCommand dartCompileFlags + dartJitFlags; + + outputs = args.outputs or [ ] ++ [ "out" "pubcache" ]; dartEntryPoints = if (dartEntryPoints != null) then writeText "entrypoints.json" (builtins.toJSON dartEntryPoints) else null; - runtimeDependencyLibraryPath = lib.makeLibraryPath finalAttrs.runtimeDependencies; + runtimeDependencies = map lib.getLib runtimeDependencies; nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ dart - dartDeps dartConfigHook dartBuildHook dartInstallHook @@ -75,55 +98,27 @@ let jq ] ++ 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 ""} + ] ++ + # Ensure that we inherit the propagated build inputs from the dependencies. + builtins.attrValues pubspecLockData.dependencySources; + + preConfigure = args.preConfigure or "" + '' + ln -sf "$pubspecLockFilePath" pubspec.lock ''; # 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 { }); + passAsFile = [ "pubspecLockFile" ]; + + passthru = { + pubspecLock = pubspecLockData; + } // (args.passthru or { }); 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 +baseDerivation |