From 7e043f5f28da0813c0317deb5478475abb8a6156 Mon Sep 17 00:00:00 2001 From: hacker1024 Date: Thu, 26 Oct 2023 15:40:37 +1100 Subject: [PATCH] buildDartApplication: Accept additional package_config.json setup commands --- .../dart/build-dart-application/default.nix | 30 +++++++++++-------- .../build-dart-application/generators.nix | 3 +- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/pkgs/build-support/dart/build-dart-application/default.nix b/pkgs/build-support/dart/build-dart-application/default.nix index 2f38a17d2442..f160cb757e48 100644 --- a/pkgs/build-support/dart/build-dart-application/default.nix +++ b/pkgs/build-support/dart/build-dart-application/default.nix @@ -19,6 +19,7 @@ , sdkSetupScript ? "" , pubGetScript ? "dart pub get" +, extraPackageConfigSetup ? "" # Output type to produce. Can be any kind supported by dart # https://dart.dev/tools/dart-compile#types-of-output @@ -64,21 +65,24 @@ let pubspecLockFile = builtins.toJSON pubspecLock; pubspecLockData = pub2nix.readPubspecLock { inherit src packageRoot pubspecLock gitHashes sdkSourceBuilders; }; - packageConfig = generators.linkPackageConfig (pub2nix.generatePackageConfig { - pname = if args.pname != null then "${args.pname}-${args.version}" else null; + 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); + 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; - }); + inherit (pubspecLockData) dependencySources; + }; + extraSetupCommands = extraPackageConfigSetup; + }; 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 67b5fd81b4cd..6af9a66b2f7f 100644 --- a/pkgs/build-support/dart/build-dart-application/generators.nix +++ b/pkgs/build-support/dart/build-dart-application/generators.nix @@ -50,7 +50,7 @@ let 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 // { + linkPackageConfig = { packageConfig, extraSetupCommands ? "" }: stdenvNoCC.mkDerivation (drvArgs // { name = "${name}-package-config-with-root.json"; nativeBuildInputs = drvArgs.nativeBuildInputs or [ ] ++ args.nativeBuildInputs or [ ] ++ [ jq yq ]; @@ -62,6 +62,7 @@ let packageName="$(yq --raw-output .name pubspec.yaml)" jq --arg name "$packageName" '.packages |= . + [{ name: $name, rootUri: "../", packageUri: "lib/" }]' '${packageConfig}' > "$out" + ${extraSetupCommands} runHook postInstall '';