pub2nix.readPubspecLock: Include entire source in package derivations
This allows references to paths above the package being built, e.g. bc5d988f32/packages/libtokyo_flutter/pubspec.yaml (L42)
This commit is contained in:
parent
6552dc5c90
commit
34ce9c64c9
5 changed files with 56 additions and 56 deletions
|
@ -28,7 +28,7 @@ flutter.buildFlutterApplication rec {
|
|||
|
||||
gitHashes = {
|
||||
keyboard_shortcuts = "sha256-U74kRujftHPvpMOIqVT0Ph+wi1ocnxNxIFA1krft4Os=";
|
||||
wakelock_windows = "sha256-/zq8HFnYpBG61R1OTJ80WAaPjZqmHs+8Ww4Gv4rLXAM=";
|
||||
wakelock_windows = "sha256-Dfwe3dSScD/6kvkP67notcbb+EgTQ3kEYcH7wpra2dI=";
|
||||
};
|
||||
|
||||
desktopItem = makeDesktopItem {
|
||||
|
|
|
@ -14,7 +14,10 @@
|
|||
}:
|
||||
|
||||
let
|
||||
packages = lib.getAttrs dependencies dependencySources;
|
||||
packages = lib.genAttrs dependencies (dependency: rec {
|
||||
src = dependencySources.${dependency};
|
||||
inherit (src) packageRoot;
|
||||
});
|
||||
in
|
||||
(runCommand "${lib.optionalString (pname != null) "${pname}-"}package-config.json" {
|
||||
inherit packages;
|
||||
|
@ -23,35 +26,43 @@ in
|
|||
|
||||
__structuredAttrs = true;
|
||||
}) ''
|
||||
declare -A packages
|
||||
while IFS='=' read -r name path; do
|
||||
packages["$name"]="$path"
|
||||
done < <(jq -r '.packages | to_entries | map("\(.key)=\(.value)") | .[]' "$NIX_ATTRS_JSON_FILE")
|
||||
declare -A packageSources
|
||||
declare -A packageRoots
|
||||
while IFS=',' read -r name src packageRoot; do
|
||||
packageSources["$name"]="$src"
|
||||
packageRoots["$name"]="$packageRoot"
|
||||
done < <(jq -r '.packages | to_entries | map("\(.key),\(.value.src),\(.value.packageRoot)") | .[]' "$NIX_ATTRS_JSON_FILE")
|
||||
|
||||
jq > "$out" --slurp '{
|
||||
for package in "''${!packageSources[@]}"; do
|
||||
if [ ! -e "''${packageSources["$package"]}/''${packageRoots["$package"]}/pubspec.yaml" ]; then
|
||||
echo >&2 "The package sources for $package are missing. Is the following path inside the source derivation?"
|
||||
echo >&2 "Source path: ''${packageSources["$package"]}/''${packageRoots["$package"]}/pubspec.yaml"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
languageConstraint="$(yq -r .environment.sdk "''${packageSources["$package"]}/''${packageRoots["$package"]}/pubspec.yaml")"
|
||||
if [[ "$languageConstraint" =~ ^[[:space:]]*(\^|>=|>|)[[:space:]]*([[:digit:]]+\.[[:digit:]]+)\.[[:digit:]]+.*$ ]]; then
|
||||
languageVersionJson="\"''${BASH_REMATCH[2]}\""
|
||||
elif [ "$languageConstraint" = 'any' ]; then
|
||||
languageVersionJson='null'
|
||||
else
|
||||
# https://github.com/dart-lang/pub/blob/68dc2f547d0a264955c1fa551fa0a0e158046494/lib/src/language_version.dart#L106C35-L106C35
|
||||
languageVersionJson='"2.7"'
|
||||
fi
|
||||
|
||||
jq --null-input \
|
||||
--arg name "$package" \
|
||||
--arg path "''${packageSources["$package"]}/''${packageRoots["$package"]}" \
|
||||
--argjson languageVersion "$languageVersionJson" \
|
||||
'{
|
||||
name: $name,
|
||||
rootUri: "file://\($path)",
|
||||
packageUri: "lib/",
|
||||
languageVersion: $languageVersion,
|
||||
}'
|
||||
done | jq > "$out" --slurp '{
|
||||
configVersion: 2,
|
||||
generator: "nixpkgs",
|
||||
packages: .,
|
||||
}' <(for package in "''${!packages[@]}"; do
|
||||
languageConstraint="$(yq -r .environment.sdk "''${packages["$package"]}/pubspec.yaml")"
|
||||
if [[ "$languageConstraint" =~ ^[[:space:]]*(\^|>=|>|)[[:space:]]*([[:digit:]]+\.[[:digit:]]+)\.[[:digit:]]+.*$ ]]; then
|
||||
languageVersionJson="\"''${BASH_REMATCH[2]}\""
|
||||
elif [ "$languageConstraint" = 'any' ]; then
|
||||
languageVersionJson='null'
|
||||
else
|
||||
# https://github.com/dart-lang/pub/blob/68dc2f547d0a264955c1fa551fa0a0e158046494/lib/src/language_version.dart#L106C35-L106C35
|
||||
languageVersionJson='"2.7"'
|
||||
fi
|
||||
|
||||
jq --null-input \
|
||||
--arg name "$package" \
|
||||
--arg path "''${packages["$package"]}" \
|
||||
--argjson languageVersion "$languageVersionJson" \
|
||||
'{
|
||||
name: $name,
|
||||
rootUri: "file://\($path)",
|
||||
packageUri: "lib/",
|
||||
languageVersion: $languageVersion,
|
||||
}'
|
||||
done)
|
||||
}'
|
||||
''
|
||||
|
|
|
@ -47,40 +47,29 @@ let
|
|||
sha256 = details.description.sha256;
|
||||
};
|
||||
in
|
||||
runCommand "pub-${name}-${details.version}"
|
||||
{ } ''
|
||||
runCommand "pub-${name}-${details.version}" { passthru.packageRoot = "."; } ''
|
||||
mkdir -p "$out"
|
||||
tar xf '${archive}' -C "$out"
|
||||
'';
|
||||
|
||||
mkGitDependencySource = name: details: fetchgit {
|
||||
mkGitDependencySource = name: details: (fetchgit {
|
||||
name = "pub-${name}-${details.version}";
|
||||
url = details.description.url;
|
||||
rev = details.description.resolved-ref;
|
||||
postFetch = ''
|
||||
if [ "$(realpath "$out/${details.description.path}")" != "$(realpath "$out")" ]; then
|
||||
(shopt -s dotglob; mv "$out"/* .)
|
||||
rmdir "$out"
|
||||
mv '${details.description.path}' "$out"
|
||||
fi
|
||||
'';
|
||||
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;
|
||||
};
|
||||
});
|
||||
|
||||
mkPathDependencySource = name: details:
|
||||
if builtins.isPath src
|
||||
then
|
||||
# When src is a path, avoid copying it to the store entirely, and allow
|
||||
# non-relative paths.
|
||||
(builtins.path {
|
||||
name = "pub-${name}-${details.version}";
|
||||
path = if details.description.relative then src + "/${packageRoot}" + "/${details.description.path}" else details.description.path;
|
||||
})
|
||||
else
|
||||
assert lib.assertMsg details.description.relative "Only relative paths are supported!";
|
||||
runCommand "pub-${name}-${details.version}" { } ''
|
||||
cp -r '${src}/${packageRoot}/${details.description.path}' "$out"
|
||||
'';
|
||||
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}";
|
||||
};
|
||||
});
|
||||
|
||||
mkSdkDependencySource = name: details:
|
||||
(sdkSourceBuilders.${details.description} or (throw "No SDK source builder has been given for ${details.description}!")) name;
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
|
||||
sdkSourceBuilders = {
|
||||
# https://github.com/dart-lang/pub/blob/68dc2f547d0a264955c1fa551fa0a0e158046494/lib/src/sdk/flutter.dart#L81
|
||||
"flutter" = name: runCommand "flutter-sdk-${name}" { } ''
|
||||
"flutter" = name: runCommand "flutter-sdk-${name}" { passthru.packageRoot = "."; } ''
|
||||
for path in '${flutter}/packages/${name}' '${flutter}/bin/cache/pkg/${name}'; do
|
||||
if [ -d "$path" ]; then
|
||||
ln -s "$path" "$out"
|
||||
|
|
|
@ -18,8 +18,8 @@ flutter.buildFlutterApplication rec {
|
|||
depsListFile = ./deps.json;
|
||||
|
||||
gitHashes = {
|
||||
libtokyo = "sha256-NC0EvLCLl0uMoLDlzoPwbJ0V3otkPWPFU1mgUBkOfsI=";
|
||||
libtokyo_flutter = "sha256-ltpDYcKQx5ZKup4zJSrrYClgHxtMPkUNBszLsmgAI3g=";
|
||||
libtokyo = "sha256-T0+vyfSfijLv7MvM+zt3bkVpb3aVrlDnse2xyNMp9GU=";
|
||||
libtokyo_flutter = "sha256-T0+vyfSfijLv7MvM+zt3bkVpb3aVrlDnse2xyNMp9GU=";
|
||||
};
|
||||
|
||||
postInstall = ''
|
||||
|
|
Loading…
Reference in a new issue