Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agda fails to compile files without --local-interfaces in nixos #4613

Closed
alexarice opened this issue Apr 20, 2020 · 56 comments
Closed

Agda fails to compile files without --local-interfaces in nixos #4613

alexarice opened this issue Apr 20, 2020 · 56 comments
Assignees
Labels
platform: nix Building and running with Nix/NixOS type: bug Issues and pull requests about actual bugs workaround exists
Milestone

Comments

@alexarice
Copy link
Contributor

I'm not sure if this is a nixos problem or an agda problem but currently if you try to compile an empty file with agda 2.6.1 which is not in a library, agda tries to build the interface file in /nix/store/_build which is read only. The problem seems to go away with --local-interfaces

Would be good if anyone has any ideas as to what is causing this.

@turion
Copy link
Contributor

turion commented Apr 20, 2020

Example setup to reproduce:

$ cd /tmp
$ cat mylib/mylib.agda-lib 
name: mylib
include: src

$ cat mylib/src/TestModule.agda 
module TestModule where
import IO

$ cat TestUserLibrary.agda 
import TestModule

$ agda -l standard-library -l mylib -i . TestUserLibrary.agda -v 10000
Importing the primitive modules.
Library dir = "/nix/store/7hbp89vwrih5hhdja12warhh5s8svn4n-Agda-2.6.1-data/share/ghc-8.8.3/x86_64-linux-ghc-8.8.3/Agda-2.6.1/lib"
SetRange is setting the current range to /nix/store/7hbp89vwrih5hhdja12warhh5s8svn4n-Agda-2.6.1-data/share/ghc-8.8.3/x86_64-linux-ghc-8.8.3/Agda-2.6.1/lib/prim/Agda/Primitive.agda:5,8-22 which is outside of the current file Nothing
/nix/store/_build: createDirectory: permission denied (Read-only
file system)

@alexarice
Copy link
Contributor Author

For me I can reproduce just by:

cd $(mktemp -d)
touch test.agda
agda test.agda

@gallais
Copy link
Member

gallais commented Apr 20, 2020

This is very strange. _build directories should only be created at the root
of an Agda project. Surely you don't have an .agda-lib file in /nix/store/?

(Note that there is another, unrelated, issue with nix that should get fixed in
a minor release: #4526)

@gallais gallais added platform: nix Building and running with Nix/NixOS status: info-needed More information is needed from the bug reporter to confirm the issue. type: bug Issues and pull requests about actual bugs labels Apr 20, 2020
@gallais gallais added this to the 2.6.1.1 milestone Apr 20, 2020
@alexarice
Copy link
Contributor Author

I think there probably is a .agda-lib file in my nix store but It was my understanding that it shouldn't matter because as it's in a different directory to my temp directory?

@gallais
Copy link
Member

gallais commented Apr 20, 2020

With the (new) project-based interface stashes, we do not dump the .agdai files
next to the corresponding source file anymore if we can find a project root
(i.e. an .agda-lib file somewhere up in the hierarchy).
This allows us to avoid retypechecking a project from scratch every time a user
switches between versions of Agda.

Here the presence of an .agda-lib file in /nix/store leads Agda to believe
that the root project for the primitives is /nix/store and so it tries to
regenerate the agdai files for the builtins there (well, in _build/2.6.1
to be exact).

I think this demonstrates we do need to ship an .agda-lib for the builtins
and get them compiled into the appropriate _build/VERSION at installation
time.

@alexarice
Copy link
Contributor Author

Ah I forgot about the primitives, that makes perfect sense

@turion
Copy link
Contributor

turion commented Apr 20, 2020

So we could patch this quickly by distributing our own .agda-lib for builtins in Nixos I guess?

@alexarice
Copy link
Contributor Author

That might be the best solution

@gallais
Copy link
Member

gallais commented Apr 20, 2020

If you do so, you need to make sure that the .agdai files for the builtins
end up in the corresponding _build/2.6.1 directory. At the moment Setup.hs
compiles the builtins using --local-interfaces so they are dumped next to the
source file (the assumption was that there would never be an .agda-lib file
for Agda to find but that was a really bad assumption to make in retrospect.
Sorry about that! 😭).

So you could:

  • add an .agda-lib file for the builtins
  • remove --local-interfaces from Setup.hs

and hopefully that should do it? 🤞

@alexarice
Copy link
Contributor Author

Should the .agda-lib file just go in the same folder as the builtins?

@gallais
Copy link
Member

gallais commented Apr 20, 2020

I would put a file agda-builtins.agda-lib in lib/prim/:

name: agda-builtins
include: .

@laMudri
Copy link

laMudri commented Apr 21, 2020

I think there probably is a .agda-lib file in my nix store

Wait, surely not? I thought everything directly in /nix/store/ was a directory or a .drv.

@alexarice
Copy link
Contributor Author

I think there probably is a .agda-lib file in my nix store

Wait, surely not? I thought everything directly in /nix/store/ was a directory or a .drv.

Ah, this only started when we started trying to write tests, this is why it took so long to notice

@alexarice
Copy link
Contributor Author

$ ls | grep ".agda-lib"
blxg8dm9ipq86028q9qp8qij2j4rr8rn-mylib.agda-lib
bqp854jr20z2y9x9v0391hm6cjswyska-mylib.agda-lib.drv
hlyi5ims19lca5rmzhhgxwkfjrmaaklq-mylib.agda-lib.drv
qcfx5glrzps4mf67clrknsw551f7bms7-mylib.agda-lib

@laMudri
Copy link

laMudri commented Apr 21, 2020

Aah, are blxg8dm9ipq86028q9qp8qij2j4rr8rn-mylib.agda-lib and qcfx5glrzps4mf67clrknsw551f7bms7-mylib.agda-lib actually directories whose names happen to end with .agda-lib?

@alexarice
Copy link
Contributor Author

no they are files, A derivation can be a single file

@laMudri
Copy link

laMudri commented Apr 21, 2020

Oh okay, I suppose this should be a won't-fix from the Agda side, then.

@gallais
Copy link
Member

gallais commented Apr 21, 2020

Oh okay, I suppose this should be a won't-fix from the Agda side, then.

I think our fix should be to add an .agda-lib file to the lib/prim.

@alexarice
Copy link
Contributor Author

As a side note, Agda also seems to recognise directories as agda-lib files for the purposes of determining what a library is

gallais added a commit that referenced this issue Apr 21, 2020
And also ensure we only rely on *files* named .agda-lib and ignore
directories.

NB: this does not implement the more efficient directory exploration
strategy discussed in #4526
@guilhermehas
Copy link

In my machine, it compiles, but it takes a very long time.

@turion
Copy link
Contributor

turion commented Apr 23, 2020

In my machine, it compiles, but it takes a very long time.

What system do you have?

@guilhermehas
Copy link

guilhermehas commented Apr 23, 2020

What system do you have?

Nixos too.

@alexarice
Copy link
Contributor Author

The problem only occurs if you end up with an .agda-lib file in your nix store. This only happened to us when we tried to make some nixos tests

@gallais
Copy link
Member

gallais commented Apr 23, 2020

@guilhermehas is probably suffering from #4526

@jespercockx jespercockx modified the milestones: 2.6.3, icebox, later Aug 26, 2022
ibbem added a commit to ibbem/agda that referenced this issue Nov 12, 2023
By default Agda tries to traverse the filesystem upwards until it hits
the filesystem root or it finds a .agda-lib file. This traversal can be
very slow if the Agda builtin sources are contained in a big directory
(e.g. on NixOS where /nix/store, inside which Agda is stored, often
contains ten to hundred thousand files). Hence we introduce the
.agda-lib file to prevent this traversal for the Agda builtins.

Co-authored-by: Guillaume Allais <guillaume.allais@ens-lyon.org>
ibbem added a commit to ibbem/agda that referenced this issue Nov 12, 2023
By default Agda tries to traverse the filesystem upwards until it hits
the filesystem root or it finds a .agda-lib file. This traversal can be
very slow if the Agda builtin sources are contained in a big directory
(e.g. on NixOS where /nix/store, inside which Agda is stored, often
contains ten to hundred thousand files). Hence we introduce the
.agda-lib file to prevent this traversal for the Agda builtins.

Co-authored-by: Guillaume Allais <guillaume.allais@ens-lyon.org>
ibbem added a commit to ibbem/agda that referenced this issue Nov 12, 2023
By default Agda tries to traverse the filesystem upwards until it hits
the filesystem root or it finds a .agda-lib file. This traversal can be
very slow if the Agda builtin sources are contained in a big directory
(e.g. on NixOS where /nix/store, inside which Agda is stored, often
contains ten to hundred thousand files). Hence we introduce the
.agda-lib file to prevent this traversal for the Agda builtins.

Co-authored-by: Guillaume Allais <guillaume.allais@ens-lyon.org>
UlfNorell pushed a commit that referenced this issue Jan 30, 2024
* Ignore directories with an .agda-lib suffix

Co-authored-by: ibbem <ibbem@ibbem.net>

* Fix #4526, #4613: Add .agda-lib for builtins

By default Agda tries to traverse the filesystem upwards until it hits
the filesystem root or it finds a .agda-lib file. This traversal can be
very slow if the Agda builtin sources are contained in a big directory
(e.g. on NixOS where /nix/store, inside which Agda is stored, often
contains ten to hundred thousand files). Hence we introduce the
.agda-lib file to prevent this traversal for the Agda builtins.

Co-authored-by: Guillaume Allais <guillaume.allais@ens-lyon.org>

* Decide between interface files based on their existence

---------

Co-authored-by: Guillaume Allais <guillaume.allais@ens-lyon.org>
@andreasabel
Copy link
Member

@gallais : Is this fixed by this PR?

@andreasabel andreasabel modified the milestones: later, 2.6.4.2 Feb 8, 2024
andreasabel pushed a commit that referenced this issue Feb 8, 2024
* Ignore directories with an .agda-lib suffix

Co-authored-by: ibbem <ibbem@ibbem.net>

* Fix #4526, #4613: Add .agda-lib for builtins

By default Agda tries to traverse the filesystem upwards until it hits
the filesystem root or it finds a .agda-lib file. This traversal can be
very slow if the Agda builtin sources are contained in a big directory
(e.g. on NixOS where /nix/store, inside which Agda is stored, often
contains ten to hundred thousand files). Hence we introduce the
.agda-lib file to prevent this traversal for the Agda builtins.

Co-authored-by: Guillaume Allais <guillaume.allais@ens-lyon.org>

* Decide between interface files based on their existence

---------

Co-authored-by: Guillaume Allais <guillaume.allais@ens-lyon.org>
@gallais
Copy link
Member

gallais commented Feb 23, 2024

I don't know, I'm not a nix user. :D

@andreasabel andreasabel added status: info-needed More information is needed from the bug reporter to confirm the issue. and removed PR welcome Welcome to submit a PR fixing this issue labels Feb 23, 2024
@andreasabel andreasabel modified the milestones: 2.6.4.2, later Feb 23, 2024
@andreasabel
Copy link
Member

Ok, I'll remove it from the milestone again. I also removed your assignment.
We would need new input from users whether this is still a problem.

@alexarice
Copy link
Contributor Author

I'll check this now, though need to built the release candidate

@alexarice
Copy link
Contributor Author

As far as I can tell, everything is working with release candidate 2, with or without the --local-interfaces flag

@andreasabel andreasabel removed the status: info-needed More information is needed from the bug reporter to confirm the issue. label Feb 23, 2024
@andreasabel andreasabel modified the milestones: later, 2.6.4.2 Feb 23, 2024
VitalyAnkh pushed a commit to VitalyAnkh/agda that referenced this issue Mar 5, 2024
* Ignore directories with an .agda-lib suffix

Co-authored-by: ibbem <ibbem@ibbem.net>

* Fix agda#4526, agda#4613: Add .agda-lib for builtins

By default Agda tries to traverse the filesystem upwards until it hits
the filesystem root or it finds a .agda-lib file. This traversal can be
very slow if the Agda builtin sources are contained in a big directory
(e.g. on NixOS where /nix/store, inside which Agda is stored, often
contains ten to hundred thousand files). Hence we introduce the
.agda-lib file to prevent this traversal for the Agda builtins.

Co-authored-by: Guillaume Allais <guillaume.allais@ens-lyon.org>

* Decide between interface files based on their existence

---------

Co-authored-by: Guillaume Allais <guillaume.allais@ens-lyon.org>
JobPetrovcic pushed a commit to JobPetrovcic/agda that referenced this issue Apr 12, 2024
* Ignore directories with an .agda-lib suffix

Co-authored-by: ibbem <ibbem@ibbem.net>

* Fix agda#4526, agda#4613: Add .agda-lib for builtins

By default Agda tries to traverse the filesystem upwards until it hits
the filesystem root or it finds a .agda-lib file. This traversal can be
very slow if the Agda builtin sources are contained in a big directory
(e.g. on NixOS where /nix/store, inside which Agda is stored, often
contains ten to hundred thousand files). Hence we introduce the
.agda-lib file to prevent this traversal for the Agda builtins.

Co-authored-by: Guillaume Allais <guillaume.allais@ens-lyon.org>

* Decide between interface files based on their existence

---------

Co-authored-by: Guillaume Allais <guillaume.allais@ens-lyon.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: nix Building and running with Nix/NixOS type: bug Issues and pull requests about actual bugs workaround exists
Projects
None yet
Development

No branches or pull requests

10 participants