agda / agda2hs

Compiling Agda code to readable Haskell

Home Page:https://agda.github.io/agda2hs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nix binary ignores interface files

stites opened this issue · comments

I am expecting that agda2hs will not recompile the interface files, but it looks like this is not the case for the binary on my system. Is this expected behavior? If it is, can someone help me get a nix derivation that can also load the standard-library?

First, I needed to ensure standard-library is compiled with `--local-interfaces` (which is different behavior compared to 1.7.x). See below:
{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    agda2hs.url = "github:agda/agda2hs";
  };
  outputs = { nixpkgs, agda2hs, ... }: {
    devShells."x86_64-linux".default = let
      pkgs = nixpkgs.legacyPackages."x86_64-linux";
      inherit (agda2hs.packages."x86_64-linux") agda2hs-lib;
      inherit (pkgs.agdaPackages) standard-library;
      stdlib = standard-library.overrideAttrs(o: {
        buildPhase = ''
          runHook preBuild
          agda --local-interfaces -i. ./Everything.agda
          rm ./Everything.agda ./Everything.agdai
          runHook postBuild
        '';
      });
      agda-pkgs = { pkgs = [ stdlib agda2hs-lib ]; };
    in pkgs.mkShell {
      nativeBuildInputs = [
        (agda2hs.lib."x86_64-linux".withPackages agda-pkgs)
        (pkgs.agda.withPackages agda-pkgs)
      ];
    };
  };
}

I can see that the library files are correctly loaded in the nix develop shell:

$ cat $(cat $(which agda) | \grep --only-matching 'library-file=[^ ]*' | \sed 's/library-file=\([^ ]*\)/\1/')
/nix/store/mgplhlsvhiajq30klgr47brh9nyi05b4-standard-library-2.0/standard-library.agda-lib
/nix/store/87b7jrncfwmbsddznf7ajhvc5q4iisc4-agda2hs-1.3/agda2hs.agda-lib

$ cat $(cat $(which agda2hs) | \grep --only-matching 'library-file=[^ ]*' | \sed 's/library-file=\([^ ]*\)/\1/')
/nix/store/mgplhlsvhiajq30klgr47brh9nyi05b4-standard-library-2.0/standard-library.agda-lib
/nix/store/87b7jrncfwmbsddznf7ajhvc5q4iisc4-agda2hs-1.3/agda2hs.agda-lib

Now if I try to compile a trivial module, I get a permissions error as agda2hs attempts to compile Data/Unit/Base.agdai in the /nix/store:

$ cat Foo.agda
module Foo where
open import Data.Bool

$ agda2hs Foo.agda -o .
Checking Foo (/home/stites/stuff/Foo.agda).
 Checking Data.Bool (/nix/store/mgplhlsvhiajq30klgr47brh9nyi05b4-standard-library-2.0/src/Data/Bool.agda).
  Checking Data.Bool.Base (/nix/store/mgplhlsvhiajq30klgr47brh9nyi05b4-standard-library-2.0/src/Data/Bool/Base.agda).
   Checking Data.Unit.Base (/nix/store/mgplhlsvhiajq30klgr47brh9nyi05b4-standard-library-2.0/src/Data/Unit/Base.agda).
Failed to write interface /nix/store/mgplhlsvhiajq30klgr47brh9nyi05b4-standard-library-2.0/src/Data/Unit/Base.agdai.
/nix/store/mgplhlsvhiajq30klgr47brh9nyi05b4-standard-library-2.0/src/Data/Bool/Base.agda:11,1-37
/nix/store/mgplhlsvhiajq30klgr47brh9nyi05b4-standard-library-2.0/src/Data/Unit/Base.agdai:
removeLink: permission denied (Read-only file system)

However, this interface file does not need to be recompiled:

$ ls /nix/store/mgplhlsvhiajq30klgr47brh9nyi05b4-standard-library-2.0/src/Data/Unit/Base.agda*
/nix/store/mgplhlsvhiajq30klgr47brh9nyi05b4-standard-library-2.0/src/Data/Unit/Base.agda
/nix/store/mgplhlsvhiajq30klgr47brh9nyi05b4-standard-library-2.0/src/Data/Unit/Base.agdai

I'm not a Nix user so I'm afraid I'm not really able to provide any help here.