summaryrefslogtreecommitdiffstats
path: root/nixos/tests/agda/override-with-backend.nix
blob: bb64a473ee5d47a93b989ccb19788c339d1f7184 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{ pkgs, ... }:
let
  mainProgram = "agda-trivial-backend";

  hello-world = ./files/HelloWorld.agda;

  agda-trivial-backend = pkgs.stdenvNoCC.mkDerivation {
    name = "trivial-backend";
    meta = { inherit mainProgram; };
    version = "${pkgs.haskellPackages.Agda.version}";
    src = ./files/TrivialBackend.hs;
    buildInputs = [
      (pkgs.haskellPackages.ghcWithPackages (pkgs: [ pkgs.Agda ]))
    ];
    dontUnpack = true;
    buildPhase = ''
      ghc $src -o ${mainProgram}
    '';
    installPhase = ''
      mkdir -p $out/bin
      cp ${mainProgram} $out/bin
    '';
  };
in
{
  name = "agda-trivial-backend";
  meta = with pkgs.lib.maintainers; {
    maintainers = [
      carlostome
    ];
  };

  nodes.machine =
    { pkgs, ... }:
    let
      agdaPackages = pkgs.agdaPackages.override (oldAttrs: {
        Agda = agda-trivial-backend;
      });
    in
    {
      environment.systemPackages = [
        (agdaPackages.agda.withPackages {
          pkgs = p: [ p.standard-library ];
        })
      ];
      virtualisation.memorySize = 2000; # Agda uses a lot of memory
    };

  testScript = ''
    # agda and agda-mode are not in path
    machine.fail("agda --version")
    machine.fail("agda-mode")
    # backend is present
    text = machine.succeed("${mainProgram} --help")
    assert "${mainProgram}" in text
    # Hello world
    machine.succeed(
        "cp ${hello-world} HelloWorld.agda"
    )
    machine.succeed("${mainProgram} -l standard-library -i . -c HelloWorld.agda")
    # Check execution
    text = machine.succeed("./HelloWorld")
    assert "Hello World!" in text, f"HelloWorld does not run properly: output was {text}"
  '';
}