2023-10-25 11:29:28 +00:00
|
|
|
{ lib
|
|
|
|
, fetchurl
|
|
|
|
, fetchgit
|
|
|
|
, runCommand
|
|
|
|
}:
|
|
|
|
|
|
|
|
{
|
|
|
|
# The source directory of the package.
|
|
|
|
src
|
|
|
|
|
|
|
|
# The package subdirectory within src.
|
|
|
|
# Useful if the package references sibling packages with relative paths.
|
|
|
|
, packageRoot ? "."
|
|
|
|
|
|
|
|
# The pubspec.lock file, in attribute set form.
|
|
|
|
, pubspecLock
|
|
|
|
|
|
|
|
# Hashes for Git dependencies.
|
|
|
|
# Pub does not record these itself, so they must be manually provided.
|
|
|
|
, 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 ? { }
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
dependencyVersions = builtins.mapAttrs (name: details: details.version) pubspecLock.packages;
|
|
|
|
|
|
|
|
dependencyTypes = {
|
|
|
|
"direct main" = "main";
|
|
|
|
"direct dev" = "dev";
|
|
|
|
"direct overridden" = "overridden";
|
|
|
|
"transitive" = "transitive";
|
|
|
|
};
|
|
|
|
|
|
|
|
dependencies = lib.foldlAttrs
|
|
|
|
(dependencies: name: details: dependencies // { ${dependencyTypes.${details.dependency}} = dependencies.${dependencyTypes.${details.dependency}} ++ [ name ]; })
|
|
|
|
(lib.genAttrs (builtins.attrValues dependencyTypes) (dependencyType: [ ]))
|
|
|
|
pubspecLock.packages;
|
|
|
|
|
|
|
|
mkHostedDependencySource = name: details:
|
|
|
|
let
|
|
|
|
archive = fetchurl {
|
|
|
|
name = "pub-${name}-${details.version}.tar.gz";
|
|
|
|
url = "${details.description.url}/packages/${details.description.name}/versions/${details.version}.tar.gz";
|
|
|
|
sha256 = details.description.sha256;
|
|
|
|
};
|
|
|
|
in
|
2023-10-25 13:34:58 +00:00
|
|
|
runCommand "pub-${name}-${details.version}" { passthru.packageRoot = "."; } ''
|
2023-10-25 11:29:28 +00:00
|
|
|
mkdir -p "$out"
|
|
|
|
tar xf '${archive}' -C "$out"
|
|
|
|
'';
|
|
|
|
|
2023-10-25 13:34:58 +00:00
|
|
|
mkGitDependencySource = name: details: (fetchgit {
|
2023-10-25 11:29:28 +00:00
|
|
|
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.");
|
2023-10-25 13:34:58 +00:00
|
|
|
}).overrideAttrs ({ passthru ? { }, ... }: {
|
|
|
|
passthru = passthru // {
|
|
|
|
packageRoot = details.description.path;
|
|
|
|
};
|
|
|
|
});
|
2023-10-25 11:29:28 +00:00
|
|
|
|
|
|
|
mkPathDependencySource = name: details:
|
2023-10-25 13:34:58 +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}";
|
|
|
|
};
|
|
|
|
});
|
2023-10-25 11:29:28 +00:00
|
|
|
|
|
|
|
mkSdkDependencySource = name: details:
|
|
|
|
(sdkSourceBuilders.${details.description} or (throw "No SDK source builder has been given for ${details.description}!")) name;
|
|
|
|
|
2023-10-28 11:30:12 +00:00
|
|
|
addDependencySourceUtils = dependencySource: details: dependencySource.overrideAttrs ({ passthru, ... }: {
|
2023-10-26 05:28:54 +00:00
|
|
|
passthru = passthru // {
|
2023-10-28 11:30:12 +00:00
|
|
|
inherit (details) version;
|
2023-10-26 05:28:54 +00:00
|
|
|
packagePath = dependencySource + "/${dependencySource.packageRoot}";
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2023-10-25 11:29:28 +00:00
|
|
|
dependencySources = lib.filterAttrs (name: src: src != null) (builtins.mapAttrs
|
2023-10-28 11:30:12 +00:00
|
|
|
(name: details:
|
|
|
|
addDependencySourceUtils
|
|
|
|
(({
|
|
|
|
"hosted" = mkHostedDependencySource;
|
|
|
|
"git" = mkGitDependencySource;
|
|
|
|
"path" = mkPathDependencySource;
|
|
|
|
"sdk" = mkSdkDependencySource;
|
|
|
|
}.${details.source} name) details)
|
|
|
|
details)
|
2023-10-25 11:29:28 +00:00
|
|
|
pubspecLock.packages);
|
|
|
|
in
|
|
|
|
{
|
|
|
|
inherit
|
|
|
|
# An attribute set of dependency categories to package name lists.
|
|
|
|
dependencies
|
|
|
|
|
|
|
|
# An attribute set of package names to their versions.
|
|
|
|
dependencyVersions
|
|
|
|
|
|
|
|
# An attribute set of package names to their sources.
|
|
|
|
dependencySources;
|
|
|
|
}
|