[POC] Elm json "source-directories" support#27
[POC] Elm json "source-directories" support#27turboMaCk wants to merge 23 commits intocachix:masterfrom
Conversation
turboMaCk
left a comment
There was a problem hiding this comment.
commented not so obvious parts of the diff.
| let | ||
| mkDerivation = | ||
| { srcs ? ./elm-srcs.nix | ||
| , src |
| stdenv.mkDerivation { | ||
| inherit name src; | ||
| inherit name srcs; | ||
| sourceRoot = "."; |
There was a problem hiding this comment.
this can be hardcoded - we place generated elm.json with correct paths and the prefix elm make with right dirs.
| -- TODO: there is likely to be even better abstraction | ||
| tryLookup :: HashMap Text Value -> Text -> Either Elm2NixError Value | ||
| tryLookup hm key = maybeToRight (KeyNotFound key) (HM.lookup key hm) | ||
| where |
There was a problem hiding this comment.
reused between parseElmJsonDeps and parseElmJsonSrcs
ce64e0f to
f7b8cc8
Compare
| targets = ["Main"]; | ||
| srcs = ${srcs}; | ||
| srcdir = "${srcdir}"; | ||
| targets = ["./Main"]; |
There was a problem hiding this comment.
BREAKING change: Main.Entry => ./Main/Entry. Supports custom extensions like UPDATE: elm compiler will no longer support entries like this.Main.js.elm or Main.html.elm and entries from different sources (relative path from current dir).
There was a problem hiding this comment.
unfortunetely this is still required.
Imagine you have source-directories like this defined in elm.json:
"source-directories": [
"./src",
"./src2",
"../lib"
]
Now when you set targets = [ "Main" ] it's not clear in which directory this main should be located. It can be any one of those.
Another issue is that with current dir. Imagine having this elm.json:
"source-directories": [
".",
"../lib"
]
since I've used srcs attribute in derivation nix will create structure as:
- $pwd # contains files form
., is named after current durectory - lib # contains files from
../lib
this is why Main is prefixed with ./. We need to replace this ./ prefix with the name of directory to which builder placed actual source from current dir.
I wonder if there is any builtin helper that would help to resolve paths in a way nix does it when srcs attribute on mkDerivation is used. I belive this is done in a this shellscript
| pure (Vector.head dirs) | ||
|
|
||
| lastDir :: FilePath -> FilePath | ||
| lastDir = foldl (\path c -> if c == '/' then "" else path <> [c]) "" |
There was a problem hiding this comment.
not the most efficient way to implement this but quite concise
|
@domenkozar This is ready for a review. principles followed:
Some of the functions are not exactly most optimal or robust (path handling mostly). |
| "type": "application", | ||
| "source-directories": [ | ||
| ".", | ||
| "../b-src/src" |
| { | ||
| "type": "application", | ||
| "source-directories": [ | ||
| ".", |
| stringifySrcs xs = | ||
| "[\n" | ||
| <> foldr (\i acc -> " " <> i <> "\n" <> acc) "" xs | ||
| <> " ]" |
There was a problem hiding this comment.
todo: use QuasiQuotes
|
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. |
|
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 |
|
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? |
|
I'm not sure how you emulate private packages but if you use |
c9c7ad2 to
81bfde0
Compare
|
Closing as too old / outdated. |

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-directoriesattr inelm.jsonfile. If this attribute is not present./srcis a default destination where it looks for.elmfiles.foo/A.elmwithinbar/B.elmasimport Aandimport Bif bothfooandbarare defined insource-directorieselm make foo/A.elm bar/B.elmas well (as an entry).../../bazImplementation
Because of this, we need to use
srcsinstead ofsrc.srcsattribute is currently generated in Haskell fromelm.json. Paths like../fooare 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", "."]withinappresults in 2 directoriesfoo app. Because of changes in directories structure, newelm.jsonmust be produced during the build - done via nix.Details will be in source comments.