Skip to content

Comments

agda: parameterize agda infrastructure by Agda executable name#452961

Merged
ncfavier merged 11 commits intoNixOS:masterfrom
carlostome:parameterize-agda-executable-name
Oct 28, 2025
Merged

agda: parameterize agda infrastructure by Agda executable name#452961
ncfavier merged 11 commits intoNixOS:masterfrom
carlostome:parameterize-agda-executable-name

Conversation

@carlostome
Copy link
Contributor

This PR addresses two issues:

  • build-support/agda/default.nix has the name of the executable provided by the Agda dependency hardcoded everywhere. This prevents reusing the available infrastructure with other agda executables (e.g., provided by custom agda backends such as agda2hs).

  • build-support/agda/default.nix exports agda-mode executable. However, in version 2.8.0 this is deprecated. This PR removes this.

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 12.first-time contribution This PR is the author's first one; please be gentle! labels Oct 17, 2025
@nix-owners nix-owners bot requested a review from alexarice October 17, 2025 15:36
@nixpkgs-ci nixpkgs-ci bot added the 6.topic: agda A dependently typed programming language / interactive theorem prover label Oct 17, 2025
@nix-owners nix-owners bot requested review from iblech, ncfavier, phijor and turion October 17, 2025 15:36
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. and removed 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 6.topic: agda A dependently typed programming language / interactive theorem prover labels Oct 17, 2025
@turion
Copy link
Contributor

turion commented Oct 17, 2025

Sounds sensible. Is this used anywhere though? If not, maybe you can add a derivation to the tests that builds something with agda2hs?

@carlostome
Copy link
Contributor Author

carlostome commented Oct 17, 2025

I intend to use it in: https://github.com/IntersectMBO/formal-ledger-specifications, where we use a custom agda backend.

It is also possible to use it with agda2hs (see here)

Sounds sensible. Is this used anywhere though? If not, maybe you can add a derivation to the tests that builds something with agda2hs?

I don't think agda2hs is currently part of nixpkgs so I don't know how feasible is that. It is indeed part of haskellPackages.

${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.

@carlostome
Copy link
Contributor Author

If not, maybe you can add a derivation to the tests that builds something with agda2hs?

Where would such derivation go?

@nixpkgs-ci nixpkgs-ci bot added the 6.topic: agda A dependently typed programming language / interactive theorem prover label Oct 18, 2025
@carlostome carlostome force-pushed the parameterize-agda-executable-name branch from 8156f06 to f1efa8d Compare October 20, 2025 08:51
@nixpkgs-ci nixpkgs-ci bot added the 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS label Oct 20, 2025
@nix-owners nix-owners bot requested review from infinisil and philiptaron October 20, 2025 08:54
@carlostome carlostome force-pushed the parameterize-agda-executable-name branch from f1efa8d to d56290e Compare October 20, 2025 08:55
Copy link
Contributor

@philiptaron philiptaron left a comment

Choose a reason for hiding this comment

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

I've got a bunch of completely non-blocking comments; my overall comment is that this use of meta.mainProgram as the configuration point seems odd and wrong to me.

Isn't the actual contract that whatever replaces agda needs to fulfill what it does, even if it uses a different name?

In other words, if agda2hs is used, the trivial derivation that makes it symlink to the $out/bin/agda name would also work for your purposes, as I understand it.

@@ -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;

Comment on lines 67 to 69
assert "Hello World!" in machine.succeed(
"./HelloWorld"
), "HelloWorld does not run properly"
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's print what it did output:

Suggested change
assert "Hello World!" in machine.succeed(
"./HelloWorld"
), "HelloWorld does not run properly"
text = machine.succeed("./HelloWorld")
assert "Hello World!" in text, f"HelloWorld does not run properly: output was {text}"

Copy link
Contributor Author

@carlostome carlostome Oct 23, 2025

Choose a reason for hiding this comment

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

I'm happy to add these suggestions. I was trying to be consistent with what was already in https://github.com/carlostome/nixpkgs/blob/d56290ec3cb5b490e5a6cb351e3e11b8df874789/nixos/tests/agda/base.nix

pkgs.runCommand "trivial-backend"
{
version = "${pkgs.haskellPackages.Agda.version}";
meta.mainProgram = "${mainProgram}";
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this:

Suggested change
meta.mainProgram = "${mainProgram}";
meta = { inherit mainProgram; };

?

name = "agda-trivial-backend";
meta = {
maintainers = [
# FIXME
Copy link
Contributor

Choose a reason for hiding this comment

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

Land yourself here?

Comment on lines 5 to 11
hello-world = pkgs.writeText "hello-world" ''
{-# OPTIONS --guardedness #-}
open import IO
open import Level

main = run {0ℓ} (putStrLn "Hello World!")
'';
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd have landed this into the directory rather than using pkgs.writeText.

Comment on lines 20 to 27
cat << EOF > Main.hs
module Main where

import Agda.Main ( runAgda )

main :: IO ()
main = runAgda []
EOF
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd land this into the directory rather than use cat.

Comment on lines 13 to 18
pkgs.runCommand "trivial-backend"
{
version = "${pkgs.haskellPackages.Agda.version}";
meta.mainProgram = "${mainProgram}";
buildInputs = [ (pkgs.haskellPackages.ghcWithPackages (pkgs: [ pkgs.Agda ])) ];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd use stdenvNoCC.mkDerivation here.

@carlostome
Copy link
Contributor Author

carlostome commented Oct 23, 2025

Isn't the actual contract that whatever replaces agda needs to fulfill what it does, even if it uses a different name?

To answer this propertly we would have to define first "what (agda) does". For the change I'm proposing I have two cases in mind where one can be argued to fulfill what agda does and the other clearly does not but still can benefit from the agda nixpkgs infrastructure (mkDerivation, withPackages):

  • Case 1: A backend for Agda that is fully compatible with all Agda libraries present in nixpkgs.
  • Case 2: A backend like agda2hs that is not compatible with the Agda libraries in nixpkgs.

In other words, if agda2hs is used, the trivial derivation that makes it symlink to the $out/bin/agda name would also work for your purposes, as I understand it.

There is a small subtlety here. Agda backends "know" the name of their executable and use this for example with agda --emacs-mode setup. So for instance if we were to use this to drop in a nix shell and use emacs with agda mode then the executable will not be found in the path.

@nixpkgs-ci nixpkgs-ci bot added the 8.has: maintainer-list (update) This PR changes `maintainers/maintainer-list.nix` label Oct 23, 2025
@carlostome carlostome force-pushed the parameterize-agda-executable-name branch from 420027e to 71a7a61 Compare October 23, 2025 09:07
@carlostome carlostome requested a review from ncfavier October 28, 2025 15:21
@philiptaron
Copy link
Contributor

I'm going to let @ncfavier and the Haskell / @NixOS/agda folks review/merge. I don't know enough about this domain to make the proper decision.

@carlostome carlostome force-pushed the parameterize-agda-executable-name branch from ef31bf8 to 55ac814 Compare October 28, 2025 17:21
@nixpkgs-ci nixpkgs-ci bot added 12.approvals: 1 This PR was reviewed and approved by one person. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages. labels Oct 28, 2025
@ncfavier ncfavier added this pull request to the merge queue Oct 28, 2025
Merged via the queue into NixOS:master with commit d1983f3 Oct 28, 2025
30 of 32 checks passed
@ncfavier ncfavier mentioned this pull request Nov 8, 2025
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: agda A dependently typed programming language / interactive theorem prover 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: maintainer-list (update) This PR changes `maintainers/maintainer-list.nix` 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages. 12.first-time contribution This PR is the author's first one; please be gentle!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants