diff options
Diffstat (limited to 'Com/Simatime/buildGhcjs.nix')
-rw-r--r-- | Com/Simatime/buildGhcjs.nix | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/Com/Simatime/buildGhcjs.nix b/Com/Simatime/buildGhcjs.nix new file mode 100644 index 0000000..0a88ce7 --- /dev/null +++ b/Com/Simatime/buildGhcjs.nix @@ -0,0 +1,64 @@ + +nixpkgs: + +{ name # the main module namespace +, nick # a short name for the output +, deps # passed to ghcjs +}: + +with nixpkgs; + +let + nsToPath = ns: builtins.toString (builtins.replaceStrings ["."] ["/"] ns); + + path = nsToPath name; + + depsToPackageSet = packageSet: deps: + map (s: builtins.getAttr s packageSet) deps; + + claySrc = pkgs.fetchFromGitHub { + owner = "sebastiaanvisser"; + repo = "clay"; + rev = "cc7729b1b42a79e261091ff7835f7fc2a7ae3cee"; + sha256 = "1vd67976lvi5l4qq18zy6j44apynkl44ps04p8vwfx4gzr895dyp"; + }; + + # ghcjs-8.6.0.1 + ghcjs_ = pkgs.haskell.packages.ghcjs.override (oldAttrs: { + overrides = with pkgs.haskell.lib; self: super: { + clay = dontCheck (self.callCabal2nix "clay" claySrc {}); + http-types = dontCheck super.http-types; + tasty-quickcheck = dontCheck super.tasty-quickcheck; + scientific = dontCheck super.scientific; # takes forever + servant = dontCheck super.servant; + comonad = dontCheck super.comonad; + QuickCheck = dontCheck super.QuickCheck; + }; + }); + + ghcjs = ghcjs_.ghcWithPackages (hp: depsToPackageSet hp deps); + +in stdenv.mkDerivation { + name = name; + version = "0"; + src = ../../.; # the git root + nativeBuildInputs = [ ghcjs ]; + strictDeps = true; + buildPhase = '' + # + mkdir -p $out/{bin,static} ${path} + # + # compile with ghcjs + # + ${ghcjs}/bin/ghcjs -Werror -i. \ + --make ${path}.hs \ + -main-is ${name} \ + -o ${path} + # + # optimize js output + # + ${pkgs.closurecompiler}/bin/closure-compiler \ + ${path}.jsexe/all.js > $out/static/${nick}.js + ''; + installPhase = "exit 0"; +} // { env = ghcjs; } |