nixpkgs/pkgs/build-support/agda/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

108 lines
3.6 KiB
Nix
Raw Normal View History

2019-12-29 12:14:16 +00:00
# Builder for Agda packages.
2014-08-31 17:40:11 +00:00
{ stdenv, lib, self, Agda, runCommand, makeWrapper, writeText, ghcWithPackages, nixosTests }:
2014-08-31 17:40:11 +00:00
2019-12-29 12:14:16 +00:00
with lib.strings;
2014-08-31 17:40:11 +00:00
let
2019-12-29 12:14:16 +00:00
withPackages' = {
pkgs,
ghc ? ghcWithPackages (p: with p; [ ieee754 ])
2019-12-29 12:14:16 +00:00
}: let
pkgs' = if builtins.isList pkgs then pkgs else pkgs self;
library-file = writeText "libraries" ''
${(concatMapStringsSep "\n" (p: "${p}/${p.libraryFile}") pkgs')}
'';
2019-12-29 12:14:16 +00:00
pname = "agdaWithPackages";
version = Agda.version;
in runCommand "${pname}-${version}" {
2019-12-29 12:14:16 +00:00
inherit pname version;
nativeBuildInputs = [ makeWrapper ];
passthru = {
unwrapped = Agda;
inherit withPackages;
tests = {
inherit (nixosTests) agda;
allPackages = withPackages (lib.filter self.lib.isUnbrokenAgdaPackage (lib.attrValues self));
};
};
2023-01-12 19:49:20 +00:00
inherit (Agda) meta;
2019-12-29 12:14:16 +00:00
} ''
mkdir -p $out/bin
makeWrapper ${Agda}/bin/agda $out/bin/agda \
--add-flags "--with-compiler=${ghc}/bin/ghc" \
--add-flags "--library-file=${library-file}" \
--add-flags "--local-interfaces"
2023-01-12 19:49:20 +00:00
ln -s ${Agda}/bin/agda-mode $out/bin/agda-mode
2019-12-29 12:14:16 +00:00
''; # Local interfaces has been added for now: See https://github.com/agda/agda/issues/4526
withPackages = arg: if builtins.isAttrs arg then withPackages' arg else withPackages' { pkgs = arg; };
2020-05-31 10:02:48 +00:00
extensions = [
"agda"
"agda-lib"
"agdai"
"lagda"
"lagda.md"
"lagda.org"
"lagda.rst"
"lagda.tex"
"lagda.typ"
2020-05-31 10:02:48 +00:00
];
2019-12-29 12:14:16 +00:00
defaults =
{ pname
, meta
2019-12-29 12:14:16 +00:00
, buildInputs ? []
, everythingFile ? "./Everything.agda"
, includePaths ? []
2019-12-29 12:14:16 +00:00
, libraryName ? pname
, libraryFile ? "${libraryName}.agda-lib"
, buildPhase ? null
, installPhase ? null
2020-05-31 10:02:48 +00:00
, extraExtensions ? []
2019-12-29 12:14:16 +00:00
, ...
}: let
agdaWithArgs = withPackages (builtins.filter (p: p ? isAgdaDerivation) buildInputs);
includePathArgs = concatMapStrings (path: "-i" + path + " ") (includePaths ++ [(dirOf everythingFile)]);
2019-12-29 12:14:16 +00:00
in
{
inherit libraryName libraryFile;
isAgdaDerivation = true;
buildInputs = buildInputs ++ [ agdaWithArgs ];
buildPhase = if buildPhase != null then buildPhase else ''
runHook preBuild
agda ${includePathArgs} ${everythingFile}
2019-12-29 12:14:16 +00:00
runHook postBuild
'';
installPhase = if installPhase != null then installPhase else ''
runHook preInstall
mkdir -p $out
find -not \( -path ${everythingFile} -or -path ${lib.interfaceFile everythingFile} \) -and \( ${concatMapStringsSep " -or " (p: "-name '*.${p}'") (extensions ++ extraExtensions)} \) -exec cp -p --parents -t "$out" {} +
2019-12-29 12:14:16 +00:00
runHook postInstall
'';
2023-01-31 21:33:20 +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.
LC_ALL = lib.optionalString (!stdenv.isDarwin) "C.UTF-8";
meta = if meta.broken or false then meta // { hydraPlatforms = lib.platforms.none; } else meta;
# Retrieve all packages from the finished package set that have the current package as a dependency and build them
passthru.tests = with builtins;
lib.filterAttrs (name: pkg: self.lib.isUnbrokenAgdaPackage pkg && elem pname (map (pkg: pkg.pname) pkg.buildInputs)) self;
2014-08-31 17:40:11 +00:00
};
in
2019-12-29 12:14:16 +00:00
{
mkDerivation = args: stdenv.mkDerivation (args // defaults args);
inherit withPackages withPackages';
}