buildDartApplication: Link the package_config.json in a separate derivation

authored by

hacker1024 and committed by
FlafyDev
4eb35ef7 4f623fa0

+25 -9
+3 -3
pkgs/build-support/dart/build-dart-application/default.nix
··· 51 51 }@args: 52 52 53 53 let 54 - generators = callPackage ./generators.nix { inherit dart; } { inherit sdkSetupScript; buildDrvArgs = args; }; 54 + generators = callPackage ./generators.nix { inherit dart; } { buildDrvArgs = args; }; 55 55 56 56 generatedDepsList = generators.mkDepsList { inherit pubspecLockFile pubspecLockData packageConfig; }; 57 57 ··· 64 64 65 65 pubspecLockFile = builtins.toJSON pubspecLock; 66 66 pubspecLockData = pub2nix.readPubspecLock { inherit src packageRoot pubspecLock gitHashes sdkSourceBuilders; }; 67 - packageConfig = pub2nix.generatePackageConfig { 67 + packageConfig = generators.linkPackageConfig (pub2nix.generatePackageConfig { 68 68 pname = if args.pname != null then "${args.pname}-${args.version}" else null; 69 69 70 70 dependencies = ··· 78 78 builtins.concatLists (builtins.attrValues pubspecLockData.dependencies); 79 79 80 80 inherit (pubspecLockData) dependencySources; 81 - }; 81 + }); 82 82 83 83 inherit (dartHooks.override { inherit dart; }) dartConfigHook dartBuildHook dartInstallHook dartFixupHook; 84 84
+21 -3
pkgs/build-support/dart/build-dart-application/generators.nix
··· 2 2 , stdenvNoCC 3 3 , dart 4 4 , dartHooks 5 + , jq 5 6 , yq 6 7 , cacert 7 8 }: 8 9 9 10 { 10 - # Commands to run once before using Dart or pub. 11 - sdkSetupScript ? "" 12 11 # Arguments used in the derivation that builds the Dart package. 13 12 # Passing these is recommended to ensure that the same steps are made to 14 13 # prepare the sources in both this derivation and the one that builds the Dart 15 14 # package. 16 - , buildDrvArgs ? { } 15 + buildDrvArgs ? { } 17 16 , ... 18 17 }@args: 19 18 ··· 50 49 drvArgs = buildDrvInheritArgs // (removeAttrs args [ "buildDrvArgs" ]); 51 50 name = (if drvArgs ? name then drvArgs.name else "${drvArgs.pname}-${drvArgs.version}"); 52 51 52 + # Adds the root package to a dependency package_config.json file from pub2nix. 53 + linkPackageConfig = packageConfig: stdenvNoCC.mkDerivation (drvArgs // { 54 + name = "${name}-package-config-with-root.json"; 55 + 56 + nativeBuildInputs = drvArgs.nativeBuildInputs or [ ] ++ args.nativeBuildInputs or [ ] ++ [ jq yq ]; 57 + 58 + dontBuild = true; 59 + 60 + installPhase = '' 61 + runHook preInstall 62 + 63 + packageName="$(yq --raw-output .name pubspec.yaml)" 64 + jq --arg name "$packageName" '.packages |= . + [{ name: $name, rootUri: "../", packageUri: "lib/" }]' '${packageConfig}' > "$out" 65 + 66 + runHook postInstall 67 + ''; 68 + }); 69 + 53 70 mkDepsDrv = { pubspecLockFile, pubspecLockData, packageConfig }: args: stdenvNoCC.mkDerivation (drvArgs // args // { 54 71 inherit pubspecLockFile packageConfig; 55 72 ··· 76 93 in 77 94 { 78 95 inherit 96 + linkPackageConfig 79 97 mkDepsList; 80 98 }
+1 -2
pkgs/build-support/dart/build-dart-application/hooks/dart-config-hook.sh
··· 8 8 9 9 echo "Installing dependencies" 10 10 mkdir -p .dart_tool 11 - packageName="$(@yq@ --raw-output .name pubspec.yaml)" 12 - @jq@ '.packages |= . + [{ name: "'"$packageName"'", rootUri: "../", packageUri: "lib/" }]' "$packageConfig" > .dart_tool/package_config.json 11 + cp "$packageConfig" .dart_tool/package_config.json 13 12 14 13 echo "Generating the dependency list" 15 14 dart pub deps --json | @jq@ .packages > deps.json
-1
pkgs/build-support/dart/build-dart-application/hooks/default.nix
··· 3 3 { 4 4 dartConfigHook = makeSetupHook { 5 5 name = "dart-config-hook"; 6 - substitutions.yq = "${yq}/bin/yq"; 7 6 substitutions.jq = "${jq}/bin/jq"; 8 7 } ./dart-config-hook.sh; 9 8 dartBuildHook = makeSetupHook {