buildMavenRepo: handle relative artifact paths

This commit is contained in:
Tad Fisher
2024-12-18 17:36:32 -08:00
committed by Tad Fisher
parent 7303a3b097
commit f8c0afcd29

View File

@@ -1,6 +1,7 @@
{ {
lib, lib,
stdenv, stdenvNoCC,
coreutils,
fetchurl, fetchurl,
substitute, substitute,
symlinkJoin, symlinkJoin,
@@ -87,7 +88,7 @@ let
replaceStrings replaceStrings
; ;
inherit (lib) mapAttrsToList readFile; inherit (lib) readFile;
inherit (lib.strings) sanitizeDerivationName; inherit (lib.strings) sanitizeDerivationName;
@@ -123,13 +124,13 @@ let
} // fetchers; } // fetchers;
fetch = fetch =
coords: overrides: name: overrides: path:
{ url, hash }: { url, hash }:
let let
scheme = head (builtins.match "([a-z0-9+.-]+)://.*" url); scheme = head (builtins.match "([a-z0-9+.-]+)://.*" url);
fetch' = getAttr scheme fetchers'; fetch' = getAttr scheme fetchers';
artifact = fetch' { inherit url hash; }; artifact = fetch' { inherit url hash; };
override = overrides.${name} or lib.id; override = overrides.${path} or lib.id;
in in
override artifact; override artifact;
@@ -139,12 +140,17 @@ let
coords = toCoordinates id; coords = toCoordinates id;
modulePath = "${replaceStrings [ "." ] [ "/" ] coords.group}/${coords.module}/${coords.version}"; modulePath = "${replaceStrings [ "." ] [ "/" ] coords.group}/${coords.module}/${coords.version}";
moduleOverrides = overrides.${id} or { }; moduleOverrides = overrides.${id} or { };
fetchArtifact = fetch moduleOverrides;
in in
stdenv.mkDerivation { stdenvNoCC.mkDerivation {
pname = sanitizeDerivationName "${coords.group}-${coords.module}"; pname = sanitizeDerivationName "${coords.group}-${coords.module}";
version = coords.uniqueVersion; version = coords.uniqueVersion;
srcs = mapAttrsToList (fetch coords moduleOverrides) artifacts; nativeBuildInputs = [ coreutils ];
__structuredAttrs = true;
srcs = mapAttrs fetchArtifact artifacts;
dontPatch = true; dontPatch = true;
dontConfigure = true; dontConfigure = true;
@@ -152,12 +158,17 @@ let
dontFixup = true; dontFixup = true;
dontInstall = true; dontInstall = true;
preUnpack = '' unpackPhase = ''
mkdir -p "$out/${modulePath}" for path in "''${!srcs[@]}"; do
''; src="''${srcs[$path]}"
dst="$(${coreutils}/bin/realpath -s -m --relative-base='.' "$out/${modulePath}/$path")"
unpackCmd = '' if [[ "$dst" == \\/* ]]; then
cp "$curSrc" "$out/${modulePath}/$(stripHash "$curSrc")" echo "${id}: artifact path is invalid: $path"
exit 1
fi
mkdir -p "$(dirname "$dst")"
cp "$src" "$dst"
done
''; '';
sourceRoot = "."; sourceRoot = ".";