buildDartApplication: Accept additional package_config.json setup commands

authored by

hacker1024 and committed by
FlafyDev
7e043f5f 4eb35ef7

+19 -14
+17 -13
pkgs/build-support/dart/build-dart-application/default.nix
··· 19 19 20 20 , sdkSetupScript ? "" 21 21 , pubGetScript ? "dart pub get" 22 + , extraPackageConfigSetup ? "" 22 23 23 24 # Output type to produce. Can be any kind supported by dart 24 25 # https://dart.dev/tools/dart-compile#types-of-output ··· 64 65 65 66 pubspecLockFile = builtins.toJSON pubspecLock; 66 67 pubspecLockData = pub2nix.readPubspecLock { inherit src packageRoot pubspecLock gitHashes sdkSourceBuilders; }; 67 - packageConfig = generators.linkPackageConfig (pub2nix.generatePackageConfig { 68 - pname = if args.pname != null then "${args.pname}-${args.version}" else null; 68 + packageConfig = generators.linkPackageConfig { 69 + packageConfig = pub2nix.generatePackageConfig { 70 + pname = if args.pname != null then "${args.pname}-${args.version}" else null; 69 71 70 - dependencies = 71 - # Ideally, we'd only include the main dependencies and their transitive 72 - # dependencies. 73 - # 74 - # The pubspec.lock file does not contain information about where 75 - # transitive dependencies come from, though, and it would be weird to 76 - # include the transitive dependencies of dev and override dependencies 77 - # without including the dev and override dependencies themselves. 78 - builtins.concatLists (builtins.attrValues pubspecLockData.dependencies); 72 + dependencies = 73 + # Ideally, we'd only include the main dependencies and their transitive 74 + # dependencies. 75 + # 76 + # The pubspec.lock file does not contain information about where 77 + # transitive dependencies come from, though, and it would be weird to 78 + # include the transitive dependencies of dev and override dependencies 79 + # without including the dev and override dependencies themselves. 80 + builtins.concatLists (builtins.attrValues pubspecLockData.dependencies); 79 81 80 - inherit (pubspecLockData) dependencySources; 81 - }); 82 + inherit (pubspecLockData) dependencySources; 83 + }; 84 + extraSetupCommands = extraPackageConfigSetup; 85 + }; 82 86 83 87 inherit (dartHooks.override { inherit dart; }) dartConfigHook dartBuildHook dartInstallHook dartFixupHook; 84 88
+2 -1
pkgs/build-support/dart/build-dart-application/generators.nix
··· 50 50 name = (if drvArgs ? name then drvArgs.name else "${drvArgs.pname}-${drvArgs.version}"); 51 51 52 52 # Adds the root package to a dependency package_config.json file from pub2nix. 53 - linkPackageConfig = packageConfig: stdenvNoCC.mkDerivation (drvArgs // { 53 + linkPackageConfig = { packageConfig, extraSetupCommands ? "" }: stdenvNoCC.mkDerivation (drvArgs // { 54 54 name = "${name}-package-config-with-root.json"; 55 55 56 56 nativeBuildInputs = drvArgs.nativeBuildInputs or [ ] ++ args.nativeBuildInputs or [ ] ++ [ jq yq ]; ··· 62 62 63 63 packageName="$(yq --raw-output .name pubspec.yaml)" 64 64 jq --arg name "$packageName" '.packages |= . + [{ name: $name, rootUri: "../", packageUri: "lib/" }]' '${packageConfig}' > "$out" 65 + ${extraSetupCommands} 65 66 66 67 runHook postInstall 67 68 '';