Skip to content

Commit e32da26

Browse files
HeinrichApfelmusjespercockx
authored andcommitted
Add mkDerivation that is compatible with agda2hs
1 parent 2d11488 commit e32da26

File tree

3 files changed

+91
-5
lines changed

3 files changed

+91
-5
lines changed

nix/agda2hs.nix

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
# this file should be very close to a copy of nixpkgs/pkgs/build-support/agda/default.nix
2-
# I think I took the version from https://github.com/NixOS/nixpkgs/blob/bbe6402ecacfc3a0e2c65e3527c2cbe148b98ff8/pkgs/build-support/agda/default.nix
1+
# This file should be very close to a copy of nixpkgs/pkgs/build-support/agda/default.nix
2+
# The present file appears to be an amalgaman of
3+
# https://github.com/NixOS/nixpkgs/blob/bbe6402ecacfc3a0e2c65e3527c2cbe148b98ff8/pkgs/build-support/agda/default.nix
4+
# https://github.com/NixOS/nixpkgs/blob/583eef75e722741878b186f5bdf5a826d638f868/pkgs/build-support/agda/default.nix
35
# but it would be nice to expose this in upstream so that we don't have to duplicate the file
4-
{stdenv, lib, self, agda2hs, runCommandNoCC, makeWrapper, writeText, mkShell, ghcWithPackages}:
6+
{
7+
stdenv,
8+
lib,
9+
self,
10+
agda2hs,
11+
runCommandNoCC,
12+
makeWrapper,
13+
writeText,
14+
ghcWithPackages,
15+
}:
16+
517
with lib.strings;
618
let
719
withPackages' = {
@@ -26,7 +38,81 @@ let
2638
--add-flags "--local-interfaces"
2739
''; # Local interfaces has been added for now: See https://github.com/agda/agda/issues/4526
2840
withPackages = arg: if builtins.isAttrs arg then withPackages' arg else withPackages' { pkgs = arg; };
41+
42+
extensions = [
43+
"agda"
44+
"agda-lib"
45+
"agdai"
46+
"lagda"
47+
"lagda.md"
48+
"lagda.org"
49+
"lagda.rst"
50+
"lagda.tex"
51+
"lagda.typ"
52+
];
53+
54+
defaults =
55+
{
56+
pname,
57+
meta,
58+
buildInputs ? [ ],
59+
everythingFile ? "./Everything.agda",
60+
includePaths ? [ ],
61+
libraryName ? pname,
62+
libraryFile ? "${libraryName}.agda-lib",
63+
buildPhase ? null,
64+
installPhase ? null,
65+
extraExtensions ? [ ],
66+
...
67+
}:
68+
let
69+
agdaWithArgs = withPackages (filter (p: p ? isAgdaDerivation) buildInputs);
70+
includePathArgs = concatMapStrings (path: "-i" + path + " ") (
71+
includePaths ++ [ (dirOf everythingFile) ]
72+
);
73+
in
74+
{
75+
inherit libraryName libraryFile;
76+
77+
isAgdaDerivation = true;
78+
79+
buildInputs = buildInputs ++ [ agdaWithArgs ];
80+
81+
buildPhase =
82+
if buildPhase != null then
83+
buildPhase
84+
else
85+
''
86+
runHook preBuild
87+
agda2hs ${includePathArgs} ${everythingFile}
88+
rm ${everythingFile} ${everythingFile}i
89+
runHook postBuild
90+
'';
91+
92+
installPhase =
93+
if installPhase != null then
94+
installPhase
95+
else
96+
''
97+
runHook preInstall
98+
mkdir -p $out
99+
find \( ${
100+
concatMapStringsSep " -or " (p: "-name '*.${p}'") (extensions ++ extraExtensions)
101+
} \) -exec cp -p --parents -t "$out" {} +
102+
runHook postInstall
103+
'';
104+
105+
# As documented at https://github.com/NixOS/nixpkgs/issues/172752,
106+
# we need to set LC_ALL to an UTF-8-supporting locale. However, on
107+
# darwin, it seems that there is no standard such locale; luckily,
108+
# the referenced issue doesn't seem to surface on darwin. Hence let's
109+
# set this only on non-darwin.
110+
LC_ALL = optionalString (!stdenv.hostPlatform.isDarwin) "C.UTF-8";
111+
};
112+
29113
in {
114+
mkDerivation = args: stdenv.mkDerivation (args // defaults args);
115+
30116
inherit withPackages;
31117
agda2hs = withPackages [];
32118
}

nix/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let
66
lib = import ./lib.nix { inherit pkgs; };
77
version = "1.3";
88

9-
base-lib = pkgs.agdaPackages.mkDerivation {
9+
base-lib = lib.mkDerivation {
1010
pname = "base";
1111
meta = { };
1212
version = "4.18";

nix/lib.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ in
2525
agda2hs-pkg = hsrc;
2626
agda2hs-hs = hpkg;
2727
agda2hs-expr = expr;
28-
inherit (agda2hs) agda2hs withPackages;
28+
inherit (agda2hs) agda2hs withPackages mkDerivation;
2929
}

0 commit comments

Comments
 (0)