1{ lib, stdenv, buildEnv, haskell, nodejs, fetchurl, fetchpatch, makeWrapper }:
2
3# To update:
4# 1) Update versions in ./update-elm.rb and run it.
5# 2) Checkout elm-reactor and run `elm-package install -y` inside.
6# 3) Run ./elm2nix.rb in elm-reactor's directory.
7# 4) Move the resulting 'package.nix' to 'packages/elm-reactor-elm.nix'.
8
9let
10 makeElmStuff = deps:
11 let json = builtins.toJSON (lib.mapAttrs (name: info: info.version) deps);
12 cmds = lib.mapAttrsToList (name: info: let
13 pkg = stdenv.mkDerivation {
14
15 name = lib.replaceChars ["/"] ["-"] name + "-${info.version}";
16
17 src = fetchurl {
18 url = "https://github.com/${name}/archive/${info.version}.tar.gz";
19 meta.homepage = "https://github.com/${name}/";
20 inherit (info) sha256;
21 };
22
23 phases = [ "unpackPhase" "installPhase" ];
24
25 installPhase = ''
26 mkdir -p $out
27 cp -r * $out
28 '';
29
30 };
31 in ''
32 mkdir -p elm-stuff/packages/${name}
33 ln -s ${pkg} elm-stuff/packages/${name}/${info.version}
34 '') deps;
35 in ''
36 export HOME=/tmp
37 mkdir elm-stuff
38 cat > elm-stuff/exact-dependencies.json <<EOF
39 ${json}
40 EOF
41 '' + lib.concatStrings cmds;
42
43 hsPkgs = haskell.packages.ghc802.override {
44 overrides = self: super:
45 let hlib = haskell.lib;
46 elmRelease = import ./packages/release.nix { inherit (self) callPackage; };
47 elmPkgs' = elmRelease.packages;
48 elmPkgs = elmPkgs' // {
49
50 elm-reactor = hlib.overrideCabal elmPkgs'.elm-reactor (drv: {
51 buildTools = drv.buildTools or [] ++ [ self.elm-make ];
52 preConfigure = makeElmStuff (import ./packages/elm-reactor-elm.nix);
53 });
54
55 elm-repl = hlib.overrideCabal elmPkgs'.elm-repl (drv: {
56 doCheck = false;
57 buildTools = drv.buildTools or [] ++ [ makeWrapper ];
58 postInstall =
59 let bins = lib.makeBinPath [ nodejs self.elm-make ];
60 in ''
61 wrapProgram $out/bin/elm-repl \
62 --prefix PATH ':' ${bins}
63 '';
64 });
65
66 /*
67 This is not a core Elm package, and it's hosted on GitHub.
68 To update, run:
69
70 cabal2nix --jailbreak --revision refs/tags/foo http://github.com/avh4/elm-format > packages/elm-format.nix
71
72 where foo is a tag for a new version, for example "0.3.1-alpha".
73 */
74 elm-format = self.callPackage ./packages/elm-format.nix { };
75 elm-interface-to-json = self.callPackage ./packages/elm-interface-to-json.nix {
76 aeson-pretty = self.aeson-pretty_0_7_2;
77 };
78 };
79 in elmPkgs // {
80 inherit elmPkgs;
81 elmVersion = elmRelease.version;
82 # needed for elm-package
83 http-client = hlib.overrideCabal super.http-client (drv: {
84 version = "0.4.31.2";
85 sha256 = "12yq2l6bvmxg5w6cw5ravdh39g8smwn1j44mv36pfmkhm5402h8n";
86 });
87 http-client-tls = hlib.overrideCabal super.http-client-tls (drv: {
88 version = "0.2.4.1";
89 sha256 = "18wbca7jg15p0ds3339f435nqv2ng0fqc4bylicjzlsww625ij4d";
90 });
91 # https://github.com/elm-lang/elm-compiler/issues/1566
92 indents = hlib.overrideCabal super.indents (drv: {
93 version = "0.3.3";
94 sha256 = "16lz21bp9j14xilnq8yym22p3saxvc9fsgfcf5awn2a6i6n527xn";
95 libraryHaskellDepends = drv.libraryHaskellDepends ++ [super.concatenative];
96 });
97 };
98 };
99in hsPkgs.elmPkgs // {
100 elm = lib.hiPrio (buildEnv {
101 name = "elm-${hsPkgs.elmVersion}";
102 paths = lib.mapAttrsToList (name: pkg: pkg) hsPkgs.elmPkgs;
103 pathsToLink = [ "/bin" ];
104 });
105}