2024-05-13 21:24:10 +00:00
|
|
|
{ lib, callPackage, fetchurl, fetchgit, runCommand }:
|
2024-05-02 00:46:19 +00:00
|
|
|
|
|
|
|
{
|
2024-05-13 21:24:10 +00:00
|
|
|
# The source directory of the package.
|
|
|
|
src
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
# The package subdirectory within src.
|
|
|
|
# Useful if the package references sibling packages with relative paths.
|
2024-05-02 00:46:19 +00:00
|
|
|
, packageRoot ? "."
|
|
|
|
|
|
|
|
# The pubspec.lock file, in attribute set form.
|
|
|
|
, pubspecLock
|
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
# Hashes for Git dependencies.
|
|
|
|
# Pub does not record these itself, so they must be manually provided.
|
2024-05-02 00:46:19 +00:00
|
|
|
, gitHashes ? { }
|
|
|
|
|
|
|
|
# Functions to generate SDK package sources.
|
|
|
|
# The function names should match the SDK names, and the package name is given as an argument.
|
|
|
|
, sdkSourceBuilders ? { }
|
|
|
|
|
|
|
|
# Functions that create custom package source derivations.
|
|
|
|
#
|
|
|
|
# The function names should match the package names, and the package version,
|
|
|
|
# source, and source files are given in an attribute set argument.
|
|
|
|
#
|
|
|
|
# The passthru of the source derivation should be propagated.
|
2024-05-13 21:24:10 +00:00
|
|
|
, customSourceBuilders ? { } }:
|
2024-05-02 00:46:19 +00:00
|
|
|
|
|
|
|
let
|
2024-05-13 21:24:10 +00:00
|
|
|
dependencyVersions =
|
|
|
|
builtins.mapAttrs (name: details: details.version) pubspecLock.packages;
|
2024-05-02 00:46:19 +00:00
|
|
|
|
|
|
|
dependencyTypes = {
|
|
|
|
"direct main" = "main";
|
|
|
|
"direct dev" = "dev";
|
|
|
|
"direct overridden" = "overridden";
|
|
|
|
"transitive" = "transitive";
|
|
|
|
};
|
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
dependencies = lib.foldlAttrs (dependencies: name: details:
|
|
|
|
dependencies // {
|
|
|
|
${dependencyTypes.${details.dependency}} =
|
|
|
|
dependencies.${dependencyTypes.${details.dependency}} ++ [ name ];
|
|
|
|
})
|
2024-05-02 00:46:19 +00:00
|
|
|
(lib.genAttrs (builtins.attrValues dependencyTypes) (dependencyType: [ ]))
|
|
|
|
pubspecLock.packages;
|
|
|
|
|
|
|
|
# fetchTarball fails with "tarball contains an unexpected number of top-level files". This is a workaround.
|
|
|
|
# https://discourse.nixos.org/t/fetchtarball-with-multiple-top-level-directories-fails/20556
|
|
|
|
mkHostedDependencySource = name: details:
|
|
|
|
let
|
|
|
|
archive = fetchurl {
|
|
|
|
name = "pub-${name}-${details.version}.tar.gz";
|
2024-05-13 21:24:10 +00:00
|
|
|
url =
|
|
|
|
"${details.description.url}/packages/${details.description.name}/versions/${details.version}.tar.gz";
|
2024-05-02 00:46:19 +00:00
|
|
|
sha256 = details.description.sha256;
|
|
|
|
};
|
2024-05-13 21:24:10 +00:00
|
|
|
in runCommand "pub-${name}-${details.version}" {
|
|
|
|
passthru.packageRoot = ".";
|
|
|
|
} ''
|
2024-05-02 00:46:19 +00:00
|
|
|
mkdir -p "$out"
|
|
|
|
tar xf '${archive}' -C "$out"
|
|
|
|
'';
|
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
mkGitDependencySource = name: details:
|
|
|
|
(fetchgit {
|
|
|
|
name = "pub-${name}-${details.version}";
|
|
|
|
url = details.description.url;
|
|
|
|
rev = details.description.resolved-ref;
|
|
|
|
hash = gitHashes.${name} or (throw
|
|
|
|
"A Git hash is required for ${name}! Set to an empty string to obtain it.");
|
|
|
|
}).overrideAttrs ({ passthru ? { }, ... }: {
|
|
|
|
passthru = passthru // { packageRoot = details.description.path; };
|
|
|
|
});
|
2024-05-02 00:46:19 +00:00
|
|
|
|
|
|
|
mkPathDependencySource = name: details:
|
2024-05-13 21:24:10 +00:00
|
|
|
assert lib.assertMsg details.description.relative
|
|
|
|
"Only relative paths are supported - ${name} has an absolue path!";
|
|
|
|
(if lib.isDerivation src then
|
|
|
|
src
|
|
|
|
else
|
|
|
|
(runCommand "pub-${name}-${details.version}" { }
|
|
|
|
''cp -r '${src}' "$out"'')).overrideAttrs ({ passthru ? { }, ... }: {
|
|
|
|
passthru = passthru // {
|
|
|
|
packageRoot = "${packageRoot}/${details.description.path}";
|
|
|
|
};
|
|
|
|
});
|
2024-05-02 00:46:19 +00:00
|
|
|
|
|
|
|
mkSdkDependencySource = name: details:
|
2024-05-13 21:24:10 +00:00
|
|
|
(sdkSourceBuilders.${details.description} or (throw
|
|
|
|
"No SDK source builder has been given for ${details.description}!")) name;
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
addDependencySourceUtils = dependencySource: details:
|
|
|
|
dependencySource.overrideAttrs ({ passthru, ... }: {
|
|
|
|
passthru = passthru // { inherit (details) version; };
|
|
|
|
});
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
sourceBuilders =
|
|
|
|
callPackage ../../../development/compilers/dart/package-source-builders { }
|
|
|
|
// customSourceBuilders;
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
dependencySources = lib.filterAttrs (name: src: src != null)
|
|
|
|
(builtins.mapAttrs (name: details:
|
2024-05-02 00:46:19 +00:00
|
|
|
(sourceBuilders.${name} or ({ src, ... }: src)) {
|
|
|
|
inherit (details) version source;
|
|
|
|
src = ((addDependencySourceUtils (({
|
|
|
|
"hosted" = mkHostedDependencySource;
|
|
|
|
"git" = mkGitDependencySource;
|
|
|
|
"path" = mkPathDependencySource;
|
|
|
|
"sdk" = mkSdkDependencySource;
|
|
|
|
}.${details.source} name) details)) details);
|
2024-05-13 21:24:10 +00:00
|
|
|
}) pubspecLock.packages);
|
|
|
|
in {
|
2024-05-02 00:46:19 +00:00
|
|
|
inherit
|
2024-05-13 21:24:10 +00:00
|
|
|
# An attribute set of dependency categories to package name lists.
|
2024-05-02 00:46:19 +00:00
|
|
|
dependencies
|
|
|
|
|
|
|
|
# An attribute set of package names to their versions.
|
|
|
|
dependencyVersions
|
|
|
|
|
|
|
|
# An attribute set of package names to their sources.
|
|
|
|
dependencySources;
|
|
|
|
}
|