Skip to content

Commit d1983f3

Browse files
authored
agda: parameterize agda infrastructure by Agda executable name (NixOS#452961)
2 parents d766fcf + 55ac814 commit d1983f3

File tree

9 files changed

+101
-13
lines changed

9 files changed

+101
-13
lines changed

ci/OWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ pkgs/development/python-modules/buildcatrust/ @ajs124 @lukegb @mweinelt
343343
/pkgs/top-level/agda-packages.nix @NixOS/agda
344344
/pkgs/development/libraries/agda @NixOS/agda
345345
/doc/languages-frameworks/agda.section.md @NixOS/agda
346-
/nixos/tests/agda.nix @NixOS/agda
346+
/nixos/tests/agda @NixOS/agda
347347

348348
# Idris
349349
/pkgs/development/idris-modules @Infinisil

maintainers/maintainer-list.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4254,6 +4254,11 @@
42544254
githubId = 498906;
42554255
name = "Karolis Stasaitis";
42564256
};
4257+
carlostome = {
4258+
name = "Carlos Tomé Cortiñas";
4259+
github = "carlostome";
4260+
githubId = 2206578;
4261+
};
42574262
carlsverre = {
42584263
email = "accounts@carlsverre.com";
42594264
github = "carlsverre";
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
{ pkgs, ... }:
22

33
let
4-
hello-world = pkgs.writeText "hello-world" ''
5-
{-# OPTIONS --guardedness #-}
6-
open import IO
7-
open import Level
8-
9-
main = run {0ℓ} (putStrLn "Hello World!")
10-
'';
4+
hello-world = ./files/HelloWorld.agda;
115
in
126
{
137
name = "agda";
@@ -30,6 +24,10 @@ in
3024
};
3125

3226
testScript = ''
27+
# agda and agda-mode are in path
28+
machine.succeed("agda --version")
29+
machine.succeed("agda-mode")
30+
3331
# Minimal script that typechecks
3432
machine.succeed("touch TestEmpty.agda")
3533
machine.succeed("agda TestEmpty.agda")

nixos/tests/agda/default.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{ runTest }:
2+
{
3+
base = runTest ./base.nix;
4+
override-with-backend = runTest ./override-with-backend.nix;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{-# OPTIONS --guardedness #-}
2+
open import IO
3+
open import Level
4+
5+
main = run {0ℓ} (putStrLn "Hello World!")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Main where
2+
3+
import Agda.Main ( runAgda )
4+
5+
main :: IO ()
6+
main = runAgda []
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{ pkgs, ... }:
2+
let
3+
mainProgram = "agda-trivial-backend";
4+
5+
hello-world = ./files/HelloWorld.agda;
6+
7+
agda-trivial-backend = pkgs.stdenvNoCC.mkDerivation {
8+
name = "trivial-backend";
9+
meta = { inherit mainProgram; };
10+
version = "${pkgs.haskellPackages.Agda.version}";
11+
src = ./files/TrivialBackend.hs;
12+
buildInputs = [
13+
(pkgs.haskellPackages.ghcWithPackages (pkgs: [ pkgs.Agda ]))
14+
];
15+
dontUnpack = true;
16+
buildPhase = ''
17+
ghc $src -o ${mainProgram}
18+
'';
19+
installPhase = ''
20+
mkdir -p $out/bin
21+
cp ${mainProgram} $out/bin
22+
'';
23+
};
24+
in
25+
{
26+
name = "agda-trivial-backend";
27+
meta = with pkgs.lib.maintainers; {
28+
maintainers = [
29+
carlostome
30+
];
31+
};
32+
33+
nodes.machine =
34+
{ pkgs, ... }:
35+
let
36+
agdaPackages = pkgs.agdaPackages.override (oldAttrs: {
37+
Agda = agda-trivial-backend;
38+
});
39+
in
40+
{
41+
environment.systemPackages = [
42+
(agdaPackages.agda.withPackages {
43+
pkgs = p: [ p.standard-library ];
44+
})
45+
];
46+
virtualisation.memorySize = 2000; # Agda uses a lot of memory
47+
};
48+
49+
testScript = ''
50+
# agda and agda-mode are not in path
51+
machine.fail("agda --version")
52+
machine.fail("agda-mode")
53+
# backend is present
54+
text = machine.succeed("${mainProgram} --help")
55+
assert "${mainProgram}" in text
56+
# Hello world
57+
machine.succeed(
58+
"cp ${hello-world} HelloWorld.agda"
59+
)
60+
machine.succeed("${mainProgram} -l standard-library -i . -c HelloWorld.agda")
61+
# Check execution
62+
text = machine.succeed("./HelloWorld")
63+
assert "Hello World!" in text, f"HelloWorld does not run properly: output was {text}"
64+
'';
65+
}

nixos/tests/all-tests.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ in
203203
adguardhome = runTest ./adguardhome.nix;
204204
aesmd = runTestOn [ "x86_64-linux" ] ./aesmd.nix;
205205
agate = runTest ./web-servers/agate.nix;
206-
agda = runTest ./agda.nix;
206+
agda = import ./agda {
207+
inherit runTest;
208+
};
207209
age-plugin-tpm-decrypt = runTest ./age-plugin-tpm-decrypt.nix;
208210
agnos = discoverTests (import ./agnos.nix);
209211
agorakit = runTest ./web-apps/agorakit.nix;

pkgs/build-support/agda/default.nix

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ let
4545
}:
4646
let
4747
libraryFile = mkLibraryFile pkgs;
48-
pname = "agdaWithPackages";
48+
pname = "${Agda.meta.mainProgram}WithPackages";
4949
version = Agda.version;
5050
in
5151
runCommand "${pname}-${version}"
@@ -68,10 +68,12 @@ let
6868
}
6969
''
7070
mkdir -p $out/bin
71-
makeWrapper ${lib.getExe Agda} $out/bin/agda \
71+
makeWrapper ${lib.getExe Agda} $out/bin/${Agda.meta.mainProgram} \
7272
${lib.optionalString (ghc != null) ''--add-flags "--with-compiler=${ghc}/bin/ghc"''} \
7373
--add-flags "--library-file=${libraryFile}"
74-
ln -s ${lib.getExe' Agda "agda-mode"} $out/bin/agda-mode
74+
if [ -e ${lib.getExe' Agda "agda-mode"} ]; then
75+
ln -s ${lib.getExe' Agda "agda-mode"} $out/bin/agda-mode
76+
fi
7577
'';
7678

7779
withPackages = arg: if isAttrs arg then withPackages' arg else withPackages' { pkgs = arg; };
@@ -116,7 +118,7 @@ let
116118
else
117119
''
118120
runHook preBuild
119-
agda --build-library
121+
${lib.getExe agdaWithPkgs} --build-library
120122
runHook postBuild
121123
'';
122124

0 commit comments

Comments
 (0)