mirror of
https://github.com/simplex-chat/haskell.nix.git
synced 2026-06-03 09:17:32 +00:00
* Add parser combinators to parse SPDX license expressions The most important parser is `compoundExpression` it parses any SPDX license expression into a list of SPDX simple-expressions. The rationale is Nixpkgs' license metadata isn't capable of distinguishing between the AND and OR relationships. License exceptions aren't currently taken into account. * Add tests for the SPDX parser combinators I simply added a file with expressions that are expected to fail to parse or parse successfully. * Add the SPDX license list The SPDX license list as attrsets following the nixpkgs lib.licenses convention. This uses fetchurl which is not ideal because it's not available during pure evaluation. It does not yet include the SPDX exceptions list. * Refactor cabal-licenses.nix to use spdx/licenses.nix The handling of the generic licenses is undecided still. Some have been removed because they have better official identifiers. * Refactor license mapping in builders The common code in the comp- and setup-builders has been extracted and refactored to use the SPDX expression parser. * Use spdx-license-list-data from nixpkgs This conveniently solves the impurity problem with using fetchurl : ) I'm not sure threading `pkgs` through everything to get access to the spdx license list package is the right way to go about this. * hscolour to "LGPL-2.1-only" and remove "LGPL" * Use evalPackages for spdx and move shim to overlay * Better fix for LGPL packages. Co-authored-by: Hamish Mackenzie <Hamish.Mackenzie@iohk.io>
98 lines
3.2 KiB
Nix
98 lines
3.2 KiB
Nix
{ pkgs, stdenv, lib, buildPackages, haskellLib, ghc, nonReinstallablePkgs, hsPkgs, makeSetupConfigFiles, pkgconfig }:
|
|
|
|
{ component, package, name, src, flags ? {}, revision ? null, patches ? [], defaultSetupSrc
|
|
, preUnpack ? component.preUnpack, postUnpack ? component.postUnpack
|
|
, prePatch ? null, postPatch ? null
|
|
, preBuild ? component.preBuild , postBuild ? component.postBuild
|
|
, preInstall ? component.preInstall , postInstall ? component.postInstall
|
|
, cleanSrc ? haskellLib.cleanCabalComponent package component "setup" src
|
|
}:
|
|
|
|
let
|
|
cleanSrc' = haskellLib.rootAndSubDir cleanSrc;
|
|
|
|
fullName = "${name}-setup";
|
|
|
|
includeGhcPackage = lib.any (p: p.identifier.name == "ghc") component.depends;
|
|
|
|
configFiles = makeSetupConfigFiles {
|
|
inherit (package) identifier;
|
|
inherit fullName flags component;
|
|
};
|
|
hooks = haskellLib.optionalHooks {
|
|
inherit
|
|
preUnpack postUnpack
|
|
prePatch postPatch
|
|
preBuild postBuild
|
|
preInstall postInstall
|
|
;
|
|
};
|
|
|
|
executableToolDepends =
|
|
(lib.concatMap (c: if c.isHaskell or false
|
|
then builtins.attrValues (c.components.exes or {})
|
|
else [c]) component.build-tools) ++
|
|
lib.optional (component.pkgconfig != []) pkgconfig;
|
|
|
|
drv =
|
|
stdenv.mkDerivation ({
|
|
name = "${ghc.targetPrefix}${fullName}";
|
|
src = cleanSrc'.root;
|
|
buildInputs = component.libs
|
|
++ component.frameworks
|
|
++ builtins.concatLists component.pkgconfig;
|
|
nativeBuildInputs = [ghc] ++ executableToolDepends;
|
|
|
|
passthru = {
|
|
inherit (package) identifier;
|
|
config = component;
|
|
srcSubDir = cleanSrc'.subDir;
|
|
srcSubDirPath = cleanSrc'.root + cleanSrc'.subDir;
|
|
cleanSrc = cleanSrc';
|
|
inherit configFiles;
|
|
};
|
|
|
|
meta = {
|
|
homepage = package.homepage or "";
|
|
description = package.synopsis or "";
|
|
license = haskellLib.cabalToNixpkgsLicense package.license;
|
|
platforms = if component.platforms == null then stdenv.lib.platforms.all else component.platforms;
|
|
};
|
|
|
|
phases = ["unpackPhase" "patchPhase" "buildPhase" "installPhase"];
|
|
buildPhase = ''
|
|
runHook preBuild
|
|
if [[ ! -f ./Setup.hs && ! -f ./Setup.lhs ]]; then
|
|
cat ${defaultSetupSrc} > Setup.hs
|
|
fi
|
|
for f in Setup.hs Setup.lhs; do
|
|
if [ -f $f ]; then
|
|
echo Compiling package $f
|
|
ghc $f -threaded '' + (if includeGhcPackage then "-package ghc " else "")
|
|
+ ''-package-db ${configFiles}/${configFiles.packageCfgDir} --make -o ./Setup
|
|
setup=$(pwd)/Setup
|
|
fi
|
|
done
|
|
[ -f ./Setup ] || (echo Failed to build Setup && exit 1)
|
|
runHook preBuild
|
|
'';
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
mkdir -p $out/bin
|
|
install ./Setup $out/bin/Setup
|
|
runHook postInstall
|
|
'';
|
|
}
|
|
// (lib.optionalAttrs (cleanSrc'.subDir != "") {
|
|
prePatch =
|
|
# If the package is in a sub directory `cd` there first
|
|
''
|
|
cd ${lib.removePrefix "/" cleanSrc'.subDir}
|
|
'';
|
|
})
|
|
// (lib.optionalAttrs (patches != []) { patches = map (p: if builtins.isFunction p then p { inherit (package.identifier) version; inherit revision; } else p) patches; })
|
|
// hooks
|
|
);
|
|
in drv
|