diff --git a/pkgs/build-support/dart/build-dart-application/default.nix b/pkgs/build-support/dart/build-dart-application/default.nix index 0f736beb1ef3..2f38a17d2442 100644 --- a/pkgs/build-support/dart/build-dart-application/default.nix +++ b/pkgs/build-support/dart/build-dart-application/default.nix @@ -51,7 +51,7 @@ }@args: let - generators = callPackage ./generators.nix { inherit dart; } { inherit sdkSetupScript; buildDrvArgs = args; }; + generators = callPackage ./generators.nix { inherit dart; } { buildDrvArgs = args; }; generatedDepsList = generators.mkDepsList { inherit pubspecLockFile pubspecLockData packageConfig; }; @@ -64,7 +64,7 @@ let pubspecLockFile = builtins.toJSON pubspecLock; pubspecLockData = pub2nix.readPubspecLock { inherit src packageRoot pubspecLock gitHashes sdkSourceBuilders; }; - packageConfig = pub2nix.generatePackageConfig { + packageConfig = generators.linkPackageConfig (pub2nix.generatePackageConfig { pname = if args.pname != null then "${args.pname}-${args.version}" else null; dependencies = @@ -78,7 +78,7 @@ let builtins.concatLists (builtins.attrValues pubspecLockData.dependencies); inherit (pubspecLockData) dependencySources; - }; + }); inherit (dartHooks.override { inherit dart; }) dartConfigHook dartBuildHook dartInstallHook dartFixupHook; diff --git a/pkgs/build-support/dart/build-dart-application/generators.nix b/pkgs/build-support/dart/build-dart-application/generators.nix index 622ba7fc8fa7..67b5fd81b4cd 100644 --- a/pkgs/build-support/dart/build-dart-application/generators.nix +++ b/pkgs/build-support/dart/build-dart-application/generators.nix @@ -2,18 +2,17 @@ , stdenvNoCC , dart , dartHooks +, jq , yq , cacert }: { - # Commands to run once before using Dart or pub. - sdkSetupScript ? "" # 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. -, buildDrvArgs ? { } + buildDrvArgs ? { } , ... }@args: @@ -50,6 +49,24 @@ let drvArgs = buildDrvInheritArgs // (removeAttrs args [ "buildDrvArgs" ]); name = (if drvArgs ? name then drvArgs.name else "${drvArgs.pname}-${drvArgs.version}"); + # Adds the root package to a dependency package_config.json file from pub2nix. + linkPackageConfig = packageConfig: stdenvNoCC.mkDerivation (drvArgs // { + 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" + + runHook postInstall + ''; + }); + mkDepsDrv = { pubspecLockFile, pubspecLockData, packageConfig }: args: stdenvNoCC.mkDerivation (drvArgs // args // { inherit pubspecLockFile packageConfig; @@ -76,5 +93,6 @@ let in { inherit + linkPackageConfig mkDepsList; } diff --git a/pkgs/build-support/dart/build-dart-application/hooks/dart-config-hook.sh b/pkgs/build-support/dart/build-dart-application/hooks/dart-config-hook.sh index e9b9a397509b..81e87c651755 100644 --- a/pkgs/build-support/dart/build-dart-application/hooks/dart-config-hook.sh +++ b/pkgs/build-support/dart/build-dart-application/hooks/dart-config-hook.sh @@ -8,8 +8,7 @@ dartConfigHook() { echo "Installing dependencies" mkdir -p .dart_tool - packageName="$(@yq@ --raw-output .name pubspec.yaml)" - @jq@ '.packages |= . + [{ name: "'"$packageName"'", rootUri: "../", packageUri: "lib/" }]' "$packageConfig" > .dart_tool/package_config.json + cp "$packageConfig" .dart_tool/package_config.json echo "Generating the dependency list" dart pub deps --json | @jq@ .packages > deps.json diff --git a/pkgs/build-support/dart/build-dart-application/hooks/default.nix b/pkgs/build-support/dart/build-dart-application/hooks/default.nix index 253d3132ad02..49599128ff63 100644 --- a/pkgs/build-support/dart/build-dart-application/hooks/default.nix +++ b/pkgs/build-support/dart/build-dart-application/hooks/default.nix @@ -3,7 +3,6 @@ { dartConfigHook = makeSetupHook { name = "dart-config-hook"; - substitutions.yq = "${yq}/bin/yq"; substitutions.jq = "${jq}/bin/jq"; } ./dart-config-hook.sh; dartBuildHook = makeSetupHook {