haskell: add cabal file hashes to dream-lock

This commit is contained in:
DavHau 2022-09-28 16:31:06 +02:00
parent 2f7f3c1289
commit ea171172d1
3 changed files with 80 additions and 16 deletions

View File

@ -52,11 +52,17 @@ in {
}"
or (throw "Could not find ${subsystemAttrs.compiler.name} version ${subsystemAttrs.compiler.version} in pkgs");
all-cabal-hashes = pkgs.runCommandLocal "all-cabal-hashes" {} ''
mkdir $out
cd $out
tar --strip-components 1 -xf ${pkgs.all-cabal-hashes}
'';
cabalFiles =
l.mapAttrs
(key: hash: let
split = l.splitString "#" key;
in
fetchCabalFile {
inherit hash;
pname = l.head split;
version = l.last split;
})
subsystemAttrs.cabalHashes or {};
# the main package
defaultPackage = allPackages."${defaultPackageName}"."${defaultPackageVersion}";
@ -78,6 +84,38 @@ in {
(version: makeOnePackage name version))
packageVersions;
# fetches a cabal file for a given candidate and cabal-file-hash
fetchCabalFile = {
hash,
pname,
version,
}:
pkgs.runCommand
"${pname}.cabal"
{
buildInputs = [
pkgs.curl
pkgs.cacert
];
outputHash = hash;
outputHashAlgo = "sha256";
outputHashMode = "flat";
}
''
revision=0
while true; do
# will fail if revision does not exist
curl -f https://hackage.haskell.org/package/${pname}-${version}/revision/$revision.cabal > cabal
hash=$(sha256sum cabal | cut -d " " -f 1)
echo "revision $revision: hash $hash; wanted hash: ${hash}"
if [ "$hash" == "${hash}" ]; then
mv cabal $out
break
fi
revision=$(($revision + 1))
done
'';
# Generates a derivation for a specific package name + version
makeOnePackage = name: version: let
pkg = compiler.mkDerivation (rec {
@ -108,8 +146,6 @@ in {
(dep: allPackages."${dep.name}"."${dep.version}")
(getDependencies name version)
);
# TODO: Implement build phases
}
/*
For all transitive dependencies, overwrite cabal file with the one
@ -117,11 +153,18 @@ in {
We want to ensure that the cabal file is the latest revision.
See: https://github.com/haskell-infra/hackage-trustees/blob/master/revisions-information.md
*/
// (l.optionalAttrs (name != defaultPackageName) {
preConfigure = ''
cp ${all-cabal-hashes}/${name}/${version}/${name}.cabal ./
'';
})
// (
l.optionalAttrs
(
(name != defaultPackageName)
&& cabalFiles ? "${name}#${version}"
)
{
preConfigure = ''
cp ${cabalFiles."${name}#${version}"} ./${name}.cabal
'';
}
)
# enable tests only for the top-level package
// (l.optionalAttrs (name == defaultPackageName) {
doCheck = true;

View File

@ -201,6 +201,18 @@ in {
# The structure of this should be defined in:
# ./src/specifications/{subsystem}
subsystemAttrs = {
cabalHashes =
l.listToAttrs
(
l.map
(
rawObj:
l.nameValuePair
"${rawObj.pkg-name}#${rawObj.pkg-version}"
rawObj.pkg-cabal-sha256
)
(l.filter (rawObj: rawObj ? pkg-cabal-sha256) serializedRawObjects)
);
compiler = {
name = l.head compilerInfo;
version = l.last compilerInfo;

View File

@ -243,6 +243,18 @@ in {
# The structure of this should be defined in:
# ./src/specifications/{subsystem}
subsystemAttrs = {
cabalHashes =
l.listToAttrs
(
l.map
(
rawObj:
l.nameValuePair
"${rawObj.name}#${rawObj.version}"
rawObj.hash
)
serializedRawObjects
);
compiler = {
name = compilerName;
version = compilerVersion;
@ -264,10 +276,7 @@ in {
/*
a list of raw package objects
*/
serializedRawObjects =
l.map
parseStackLockEntry
(stackLock.packages ++ snapshot.packages);
inherit serializedRawObjects;
/*
Define extractor functions which each extract one property from