Skip to content
Merged
2 changes: 1 addition & 1 deletion ci/OWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ pkgs/development/python-modules/buildcatrust/ @ajs124 @lukegb @mweinelt
/pkgs/top-level/agda-packages.nix @NixOS/agda
/pkgs/development/libraries/agda @NixOS/agda
/doc/languages-frameworks/agda.section.md @NixOS/agda
/nixos/tests/agda.nix @NixOS/agda
/nixos/tests/agda @NixOS/agda

# Idris
/pkgs/development/idris-modules @Infinisil
Expand Down
5 changes: 5 additions & 0 deletions maintainers/maintainer-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4254,6 +4254,11 @@
githubId = 498906;
name = "Karolis Stasaitis";
};
carlostome = {
name = "Carlos Tomé Cortiñas";
github = "carlostome";
githubId = 2206578;
};
carlsverre = {
email = "accounts@carlsverre.com";
github = "carlsverre";
Expand Down
12 changes: 5 additions & 7 deletions nixos/tests/agda.nix → nixos/tests/agda/base.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
{ pkgs, ... }:

let
hello-world = pkgs.writeText "hello-world" ''
{-# OPTIONS --guardedness #-}
open import IO
open import Level

main = run {0ℓ} (putStrLn "Hello World!")
'';
hello-world = ./files/HelloWorld.agda;
in
{
name = "agda";
Expand All @@ -30,6 +24,10 @@ in
};

testScript = ''
# agda and agda-mode are in path
machine.succeed("agda --version")
machine.succeed("agda-mode")

# Minimal script that typechecks
machine.succeed("touch TestEmpty.agda")
machine.succeed("agda TestEmpty.agda")
Expand Down
5 changes: 5 additions & 0 deletions nixos/tests/agda/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{ runTest }:
{
base = runTest ./base.nix;
override-with-backend = runTest ./override-with-backend.nix;
}
5 changes: 5 additions & 0 deletions nixos/tests/agda/files/HelloWorld.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{-# OPTIONS --guardedness #-}
open import IO
open import Level

main = run {0ℓ} (putStrLn "Hello World!")
6 changes: 6 additions & 0 deletions nixos/tests/agda/files/TrivialBackend.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main where

import Agda.Main ( runAgda )

main :: IO ()
main = runAgda []
65 changes: 65 additions & 0 deletions nixos/tests/agda/override-with-backend.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,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}"
'';
}
4 changes: 3 additions & 1 deletion nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ in
adguardhome = runTest ./adguardhome.nix;
aesmd = runTestOn [ "x86_64-linux" ] ./aesmd.nix;
agate = runTest ./web-servers/agate.nix;
agda = runTest ./agda.nix;
agda = import ./agda {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tangent about nested attrsets in this file

I see this is following the pattern of the rest of the imports in this file; in other files, I would have expected lib.recurseIntoAttrs to make the set of tests here built and eval'd by CI.

I don't really understand @roberth's change #191540 that introduced this stanza which deals with that...

findTests =
tree:
if tree ? recurseForDerivations && tree.recurseForDerivations then
mapAttrs (k: findTests) (builtins.removeAttrs tree [ "recurseForDerivations" ])
else
callTest tree;
runTest =
arg:
let
r = doRunTest arg;
in
findTests r;

inherit runTest;
};
age-plugin-tpm-decrypt = runTest ./age-plugin-tpm-decrypt.nix;
agnos = discoverTests (import ./agnos.nix);
agorakit = runTest ./web-apps/agorakit.nix;
Expand Down
10 changes: 6 additions & 4 deletions pkgs/build-support/agda/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let
}:
let
libraryFile = mkLibraryFile pkgs;
pname = "agdaWithPackages";
pname = "${Agda.meta.mainProgram}WithPackages";
version = Agda.version;
in
runCommand "${pname}-${version}"
Expand All @@ -68,10 +68,12 @@ let
}
''
mkdir -p $out/bin
makeWrapper ${lib.getExe Agda} $out/bin/agda \
makeWrapper ${lib.getExe Agda} $out/bin/${Agda.meta.mainProgram} \
${lib.optionalString (ghc != null) ''--add-flags "--with-compiler=${ghc}/bin/ghc"''} \
--add-flags "--library-file=${libraryFile}"
ln -s ${lib.getExe' Agda "agda-mode"} $out/bin/agda-mode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to remove this now? If not I would prefer to follow upstream's deprecation cycle. The executable currently prints a deprecation message when run.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is to be compatible with backends that do not have an agda-mode executable.

Copy link
Member

@ncfavier ncfavier Oct 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like the kind of out-of-tree compatibility that would be hard to maintain in nixpkgs since we don't have any non-default backends here.

Adding a test derivation in nixpkgs as suggested by @turion could address this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd still prefer to conditionally link agda-mode if it exists.

if [ -e ${lib.getExe' Agda "agda-mode"} ]; then
ln -s ${lib.getExe' Agda "agda-mode"} $out/bin/agda-mode
fi
'';

withPackages = arg: if isAttrs arg then withPackages' arg else withPackages' { pkgs = arg; };
Expand Down Expand Up @@ -116,7 +118,7 @@ let
else
''
runHook preBuild
agda --build-library
${lib.getExe agdaWithPkgs} --build-library
runHook postBuild
'';

Expand Down
Loading