elm2nix icon indicating copy to clipboard operation
elm2nix copied to clipboard

[POC] Elm json "source-directories" support

Open turboMaCk opened this issue 6 years ago • 6 comments

~At this moment this is only proof of concept that needs to be discussed and polished.~

Related to #6 and #19

This is an attempt to implement source-directories (elm.json) compatibility for both code generation and nix derivations.

Background

Elm make performs lookups for modules based on optional source-directories attr in elm.json file. If this attribute is not present ./src is a default destination where it looks for .elm files.

  • it's possible to import foo/A.elm within bar/B.elm as import Aand import B if both foo and bar are defined in source-directories
  • it's possible to do elm make foo/A.elm bar/B.elm as well (as an entry).
  • it's possible to use any relative path like ../../baz

Implementation

Because of this, we need to use srcs instead of src. srcs attribute is currently generated in Haskell from elm.json. Paths like ../foo are also valid and needs to be supported. In the case of . (current directory) nix seems to be using the name of the current directory. This means that ["../foo", "."] within app results in 2 directories foo app. Because of changes in directories structure, new elm.json must be produced during the build - done via nix.

Details will be in source comments.

turboMaCk avatar May 19 '19 19:05 turboMaCk

@domenkozar This is ready for a review.

principles followed:

  • as simple and concise as I managed to make it
  • pkgs.mkDerivation of default.nix doesn't contain any hs generated code - all project specific tab is argument defined in in block
  • as much breaking changes as possible

Some of the functions are not exactly most optimal or robust (path handling mostly).

turboMaCk avatar May 25 '19 15:05 turboMaCk

Sorry for taking this long, I've just moved over the continent and don't have immediate time to review this work. Hope you're ok waiting a few more days or so.

domenkozar avatar May 30 '19 09:05 domenkozar

no worries. I'm busy as well. Take your time, there is no need to rush anything. Given the nature of these changes, I expect this to take maybe even a few weeks still

turboMaCk avatar May 30 '19 12:05 turboMaCk

This is how it works on a project with rather complicated source-directories setting in elm.json:

elm2nix-srcs2

That's being said this is still not good enough for merge.

turboMaCk avatar Sep 29 '19 12:09 turboMaCk

What is the status of this pull request?

Also, correct me if I'm wrong, but once merged could it help us import private elm packages?

lewalkingdad avatar Aug 17 '21 01:08 lewalkingdad

I'm not sure how you emulate private packages but if you use source-directories then yes this would solve it. But the PR is on freeze. There are few hacks that made this work and it would probably require some more discussion before being really ready. Other than that I think this PR might still work so you can try to just run elm2nix version from this.

turboMaCk avatar Aug 17 '21 06:08 turboMaCk