1 # Builder for Agda packages.
3 { stdenv, lib, self, Agda, runCommand, makeWrapper, writeText, ghcWithPackages, nixosTests }:
22 mkLibraryFile = pkgs: let
23 pkgs' = if isList pkgs then pkgs else pkgs self;
24 in writeText "libraries" ''
25 ${(concatMapStringsSep "\n" (p: "${p}/${p.libraryFile}") pkgs')}
30 ghc ? ghcWithPackages (p: with p; [ ieee754 ])
32 library-file = mkLibraryFile pkgs;
33 pname = "agdaWithPackages";
34 version = Agda.version;
35 in runCommand "${pname}-${version}" {
36 inherit pname version;
37 nativeBuildInputs = [ makeWrapper ];
42 inherit (nixosTests) agda;
43 allPackages = withPackages (filter self.lib.isUnbrokenAgdaPackage (attrValues self));
46 # Agda is a split package with multiple outputs; do not inherit them here.
47 meta = removeAttrs Agda.meta [ "outputsToInstall" ];
50 makeWrapper ${Agda.bin}/bin/agda $out/bin/agda \
51 --add-flags "--with-compiler=${ghc}/bin/ghc" \
52 --add-flags "--library-file=${library-file}"
53 ln -s ${Agda.bin}/bin/agda-mode $out/bin/agda-mode
56 withPackages = arg: if isAttrs arg then withPackages' arg else withPackages' { pkgs = arg; };
74 , everythingFile ? "./Everything.agda"
77 , libraryFile ? "${libraryName}.agda-lib"
80 , extraExtensions ? []
83 agdaWithArgs = withPackages (filter (p: p ? isAgdaDerivation) buildInputs);
84 includePathArgs = concatMapStrings (path: "-i" + path + " ") (includePaths ++ [(dirOf everythingFile)]);
87 inherit libraryName libraryFile;
89 isAgdaDerivation = true;
91 buildInputs = buildInputs ++ [ agdaWithArgs ];
93 buildPhase = if buildPhase != null then buildPhase else ''
95 agda ${includePathArgs} ${everythingFile}
96 rm ${everythingFile} ${lib.interfaceFile Agda.version everythingFile}
100 installPhase = if installPhase != null then installPhase else ''
103 find \( ${concatMapStringsSep " -or " (p: "-name '*.${p}'") (extensions ++ extraExtensions)} \) -exec cp -p --parents -t "$out" {} +
107 # As documented at https://github.com/NixOS/nixpkgs/issues/172752,
108 # we need to set LC_ALL to an UTF-8-supporting locale. However, on
109 # darwin, it seems that there is no standard such locale; luckily,
110 # the referenced issue doesn't seem to surface on darwin. Hence let's
111 # set this only on non-darwin.
112 LC_ALL = optionalString (!stdenv.hostPlatform.isDarwin) "C.UTF-8";
114 meta = if meta.broken or false then meta // { hydraPlatforms = platforms.none; } else meta;
116 # Retrieve all packages from the finished package set that have the current package as a dependency and build them
118 filterAttrs (name: pkg: self.lib.isUnbrokenAgdaPackage pkg && elem pname (map (pkg: pkg.pname) pkg.buildInputs)) self;
122 mkDerivation = args: stdenv.mkDerivation (args // defaults args);
124 inherit mkLibraryFile withPackages withPackages';