2020-05-15 21:57:56 +00:00
|
|
|
# Builder for Agda packages.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-08-18 13:19:15 +00:00
|
|
|
{ stdenv, lib, self, Agda, runCommand, makeWrapper, writeText, ghcWithPackages, nixosTests }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
let
|
2024-04-21 15:54:59 +00:00
|
|
|
inherit (lib)
|
|
|
|
attrValues
|
|
|
|
elem
|
|
|
|
filter
|
|
|
|
filterAttrs
|
|
|
|
isAttrs
|
|
|
|
isList
|
|
|
|
platforms
|
|
|
|
;
|
|
|
|
|
|
|
|
inherit (lib.strings)
|
|
|
|
concatMapStrings
|
|
|
|
concatMapStringsSep
|
|
|
|
optionalString
|
|
|
|
;
|
|
|
|
|
2020-05-15 21:57:56 +00:00
|
|
|
withPackages' = {
|
|
|
|
pkgs,
|
2021-02-05 17:12:51 +00:00
|
|
|
ghc ? ghcWithPackages (p: with p; [ ieee754 ])
|
2020-05-15 21:57:56 +00:00
|
|
|
}: let
|
2024-04-21 15:54:59 +00:00
|
|
|
pkgs' = if isList pkgs then pkgs else pkgs self;
|
2020-05-15 21:57:56 +00:00
|
|
|
library-file = writeText "libraries" ''
|
|
|
|
${(concatMapStringsSep "\n" (p: "${p}/${p.libraryFile}") pkgs')}
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
2020-05-15 21:57:56 +00:00
|
|
|
pname = "agdaWithPackages";
|
|
|
|
version = Agda.version;
|
2021-08-18 13:19:15 +00:00
|
|
|
in runCommand "${pname}-${version}" {
|
2020-05-15 21:57:56 +00:00
|
|
|
inherit pname version;
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
2021-04-05 15:23:46 +00:00
|
|
|
passthru = {
|
|
|
|
unwrapped = Agda;
|
2023-02-22 10:55:15 +00:00
|
|
|
inherit withPackages;
|
|
|
|
tests = {
|
|
|
|
inherit (nixosTests) agda;
|
2024-04-21 15:54:59 +00:00
|
|
|
allPackages = withPackages (filter self.lib.isUnbrokenAgdaPackage (attrValues self));
|
2023-02-22 10:55:15 +00:00
|
|
|
};
|
2021-04-05 15:23:46 +00:00
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
# Agda is a split package with multiple outputs; do not inherit them here.
|
|
|
|
meta = removeAttrs Agda.meta [ "outputsToInstall" ];
|
2020-05-15 21:57:56 +00:00
|
|
|
} ''
|
|
|
|
mkdir -p $out/bin
|
2024-04-21 15:54:59 +00:00
|
|
|
makeWrapper ${Agda.bin}/bin/agda $out/bin/agda \
|
2020-05-15 21:57:56 +00:00
|
|
|
--add-flags "--with-compiler=${ghc}/bin/ghc" \
|
2024-04-21 15:54:59 +00:00
|
|
|
--add-flags "--library-file=${library-file}"
|
|
|
|
ln -s ${Agda.bin}/bin/agda-mode $out/bin/agda-mode
|
|
|
|
'';
|
2020-05-15 21:57:56 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
withPackages = arg: if isAttrs arg then withPackages' arg else withPackages' { pkgs = arg; };
|
2020-05-15 21:57:56 +00:00
|
|
|
|
2020-06-18 07:06:33 +00:00
|
|
|
extensions = [
|
|
|
|
"agda"
|
|
|
|
"agda-lib"
|
|
|
|
"agdai"
|
|
|
|
"lagda"
|
|
|
|
"lagda.md"
|
|
|
|
"lagda.org"
|
|
|
|
"lagda.rst"
|
|
|
|
"lagda.tex"
|
2023-11-16 04:20:00 +00:00
|
|
|
"lagda.typ"
|
2020-06-18 07:06:33 +00:00
|
|
|
];
|
2020-05-15 21:57:56 +00:00
|
|
|
|
|
|
|
defaults =
|
|
|
|
{ pname
|
2021-08-05 21:33:18 +00:00
|
|
|
, meta
|
2020-05-15 21:57:56 +00:00
|
|
|
, buildInputs ? []
|
|
|
|
, everythingFile ? "./Everything.agda"
|
2021-10-07 14:46:35 +00:00
|
|
|
, includePaths ? []
|
2020-05-15 21:57:56 +00:00
|
|
|
, libraryName ? pname
|
|
|
|
, libraryFile ? "${libraryName}.agda-lib"
|
|
|
|
, buildPhase ? null
|
|
|
|
, installPhase ? null
|
2020-06-18 07:06:33 +00:00
|
|
|
, extraExtensions ? []
|
2020-05-15 21:57:56 +00:00
|
|
|
, ...
|
|
|
|
}: let
|
2024-04-21 15:54:59 +00:00
|
|
|
agdaWithArgs = withPackages (filter (p: p ? isAgdaDerivation) buildInputs);
|
2021-10-07 14:46:35 +00:00
|
|
|
includePathArgs = concatMapStrings (path: "-i" + path + " ") (includePaths ++ [(dirOf everythingFile)]);
|
2020-05-15 21:57:56 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
inherit libraryName libraryFile;
|
|
|
|
|
|
|
|
isAgdaDerivation = true;
|
|
|
|
|
|
|
|
buildInputs = buildInputs ++ [ agdaWithArgs ];
|
|
|
|
|
|
|
|
buildPhase = if buildPhase != null then buildPhase else ''
|
|
|
|
runHook preBuild
|
2021-10-07 14:46:35 +00:00
|
|
|
agda ${includePathArgs} ${everythingFile}
|
2024-04-21 15:54:59 +00:00
|
|
|
rm ${everythingFile} ${lib.interfaceFile Agda.version everythingFile}
|
2020-05-15 21:57:56 +00:00
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = if installPhase != null then installPhase else ''
|
|
|
|
runHook preInstall
|
|
|
|
mkdir -p $out
|
2024-04-21 15:54:59 +00:00
|
|
|
find \( ${concatMapStringsSep " -or " (p: "-name '*.${p}'") (extensions ++ extraExtensions)} \) -exec cp -p --parents -t "$out" {} +
|
2020-05-15 21:57:56 +00:00
|
|
|
runHook postInstall
|
|
|
|
'';
|
2021-10-17 09:34:42 +00:00
|
|
|
|
2023-02-22 10:55:15 +00:00
|
|
|
# As documented at https://github.com/NixOS/nixpkgs/issues/172752,
|
|
|
|
# we need to set LC_ALL to an UTF-8-supporting locale. However, on
|
|
|
|
# darwin, it seems that there is no standard such locale; luckily,
|
|
|
|
# the referenced issue doesn't seem to surface on darwin. Hence let's
|
|
|
|
# set this only on non-darwin.
|
2024-04-21 15:54:59 +00:00
|
|
|
LC_ALL = optionalString (!stdenv.isDarwin) "C.UTF-8";
|
2023-02-22 10:55:15 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
meta = if meta.broken or false then meta // { hydraPlatforms = platforms.none; } else meta;
|
2021-10-17 09:34:42 +00:00
|
|
|
|
|
|
|
# Retrieve all packages from the finished package set that have the current package as a dependency and build them
|
2024-04-21 15:54:59 +00:00
|
|
|
passthru.tests =
|
|
|
|
filterAttrs (name: pkg: self.lib.isUnbrokenAgdaPackage pkg && elem pname (map (pkg: pkg.pname) pkg.buildInputs)) self;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
in
|
2020-05-15 21:57:56 +00:00
|
|
|
{
|
|
|
|
mkDerivation = args: stdenv.mkDerivation (args // defaults args);
|
|
|
|
|
|
|
|
inherit withPackages withPackages';
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|