NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.06k stars 14.04k forks source link

elm2nix #20601

Closed domenkozar closed 6 years ago

domenkozar commented 7 years ago

Elm is written in Haskell and has a very sane package manager. It shouldn't be too hard to be able to deploy all Elm packages with Nix.

I don't have enough free time to program this atm, but I'd like to drop my research here how I'd do it.

Generating all packages

Elm serves a single JSON (per Elm release) that returns all packages registered upstream:

http://package.elm-lang.org/all-packages (Elm 0.18)

We'd have to create a storage (git repository) with the following metadata per package:

As usual, we'd then build all packages and provide binaries (probably not on hydra.nixos.org).

elm2nix

It would use Elm haskell API to determine the latest versions based on local elm-package.json and generate default.nix to be used to build your project.

Functions for generating versions and names:

https://github.com/elm-lang/elm-compiler/blob/master/src/Elm/Package.hs

Logic that determines if file should be downloaded (and thus where to unpack Nixified elm packages): https://github.com/elm-lang/elm-package/blob/master/src/Install/Fetch.hs#L137

Nix integration would just unpack packages to folders like ./elm-stuff/packages/debois/elm-dom/1.2.2/ and then run elm install . in order to avoid networking at build time.

Questions

1) what if it uses the newest package that is not already indexed by Nix?

This one is tricky, as it's impossible to be able to be up to date without some delay unless a user was able to generate a new set or be able to override (manual work).

We'd have to research if elm install does lookup local folders first and just use those instead of the very latest upon installation.

Relevant work

My estimate is about a few days of work to get a prototype working :)

cc @garbas

zimbatm commented 7 years ago

Do you think we can get upstream to publish the sha256 with each package? That would simplify the pipeline a lot.

domenkozar commented 7 years ago

We'd also need for them to store elm-package.json to generate the dependencies.

I think it's worth trying upstream first.

Ericson2314 commented 7 years ago

I'd be interested to try out the architecture I proposed in https://github.com/haskell/cabal/issues/3882. (It sounds like your plan is somewhere in between that and the cabal2nix approach.)

garbas commented 7 years ago

Hi,

I would be -1 on having this information in nixpkgs and updating them in place. I would rather see a new repository eg. nixpkgs-elm which would accept nixpkgs as an input. I started this for python I think could easily setup the same thing for Elm.

I find it more and more that when working on different project you also need to pick different revision of nixpkgs. Having a collection of language specific packages and switching between different nixpkgs version is a crucial for me this days.

ofcourse nixpks-elm repository can also have an entry in nixpkgs via fetchGitHub for specific revision.

for those interested in Elm. there actually already is elm2nix command but you need to check the files and comments in pkgs/development/compilers/elm. At Mozilla we then have an update script which runs this on nightly basis: https://github.com/mozilla-releng/services/blob/master/nix/lib/default.nix#L384. for now this is working ok but it would be even better if we would have this already packaged in nix.

my 2c

domenkozar commented 7 years ago

I never proposed for packages to be in nixpkgs, since they wouldn't be built anyway :)

But this is irrelevant and minor compared to making the infrastructure work.

@Ericson2314 that means involving upstream and looks like the timing is right: https://github.com/elm-lang/package.elm-lang.org/issues/208

FRidh commented 7 years ago

Unless we have other packages depending on the Elm packages it's fine keeping it entirely separate from Nixpkgs. As soon as Nixpkgs packages do depend on the Elm packages we might start using fetchTarball with hash.

domenkozar commented 7 years ago

I'll wait for Elm 0.19 before automating this, since it's going to help a lot: https://groups.google.com/forum/#!topic/elm-dev/qdu3NqOqGrY

domenkozar commented 6 years ago

I took a bit different path and made https://github.com/domenkozar/elm2nix today. Wanted it to be simple so it can be done within a day. Let me know what you think!

tomberek commented 6 years ago

close as old?

domenkozar commented 5 years ago

https://blog.hercules-ci.com/elm/2019/01/03/elm2nix-0.1/