nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenvNoCC,
4 dart,
5 dartHooks,
6 jq,
7 yq,
8 cacert,
9}:
10
11{
12 # Arguments used in the derivation that builds the Dart package.
13 # Passing these is recommended to ensure that the same steps are made to
14 # prepare the sources in both this derivation and the one that builds the Dart
15 # package.
16 buildDrvArgs ? { },
17 ...
18}@args:
19
20# This is a derivation and setup hook that can be used to fetch dependencies for Dart projects.
21# It is designed to be placed in the nativeBuildInputs of a derivation that builds a Dart package.
22# Providing the buildDrvArgs argument is highly recommended.
23let
24 buildDrvInheritArgNames = [
25 "name"
26 "pname"
27 "version"
28 "src"
29 "sourceRoot"
30 "setSourceRoot"
31 "preUnpack"
32 "unpackPhase"
33 "unpackCmd"
34 "postUnpack"
35 "prePatch"
36 "patchPhase"
37 "patches"
38 "patchFlags"
39 "postPatch"
40 ];
41
42 buildDrvInheritArgs = builtins.foldl' (
43 attrs: arg: if buildDrvArgs ? ${arg} then attrs // { ${arg} = buildDrvArgs.${arg}; } else attrs
44 ) { } buildDrvInheritArgNames;
45
46 drvArgs = buildDrvInheritArgs // (removeAttrs args [ "buildDrvArgs" ]);
47 name = (if drvArgs ? name then drvArgs.name else "${drvArgs.pname}-${drvArgs.version}");
48
49 # Adds the root package to a dependency package_config.json file from pub2nix.
50 linkPackageConfig =
51 {
52 pubspecLock,
53 packageConfig,
54 extraSetupCommands ? "",
55 }:
56 stdenvNoCC.mkDerivation (
57 drvArgs
58 // {
59 name = "${name}-package-config-with-root.json";
60
61 nativeBuildInputs =
62 drvArgs.nativeBuildInputs or [ ]
63 ++ args.nativeBuildInputs or [ ]
64 ++ [
65 jq
66 yq
67 ];
68
69 dontBuild = true;
70
71 installPhase =
72 let
73 m = builtins.match "^[[:space:]]*(\\^|>=|>)?[[:space:]]*([0-9]+\\.[0-9]+)\\.[0-9]+.*$" pubspecLock.sdks.dart;
74 languageVersion =
75 if m != null then
76 (builtins.elemAt m 1)
77 else if pubspecLock.sdks.dart == "any" then
78 "null"
79 else
80 # https://github.com/dart-lang/pub/blob/15b96589066884300a30bdc356566f3398794857/lib/src/language_version.dart#L109
81 "2.7";
82 in
83 ''
84 runHook preInstall
85
86 packageName="$(yq --raw-output .name pubspec.yaml)"
87 jq --arg name "$packageName" --arg languageVersion ${languageVersion} '.packages |= . + [{ name: $name, rootUri: "../", packageUri: "lib/", languageVersion: (if $languageVersion == "null" then null else $languageVersion end) }]' '${packageConfig}' > "$out"
88 ${extraSetupCommands}
89
90 runHook postInstall
91 '';
92 }
93 );
94in
95{
96 inherit
97 linkPackageConfig
98 ;
99}