summaryrefslogtreecommitdiff
path: root/com/simatime
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2019-11-02 13:46:54 -0700
committerBen Sima <ben@bsima.me>2019-11-02 13:46:54 -0700
commitd446f2ead3b8f8393e8b29088b920054d6b3fcf8 (patch)
tree0d4f92b403d4c2eaf4e865490add4b0267e7ff7e /com/simatime
parent6094867053604fd911d2f71f4ce03c173dc5256a (diff)
fix buildHaskellApp nix function
Diffstat (limited to 'com/simatime')
-rw-r--r--com/simatime/buildHaskellApp.nix53
1 files changed, 33 insertions, 20 deletions
diff --git a/com/simatime/buildHaskellApp.nix b/com/simatime/buildHaskellApp.nix
index d9cb211..e9edb0a 100644
--- a/com/simatime/buildHaskellApp.nix
+++ b/com/simatime/buildHaskellApp.nix
@@ -10,9 +10,10 @@ nixpkgs:
# the namespace. We can't figure this out with Nix code, but when we port to
# guix/scheme we should be able to
name
+, nick # a short name, for the executable
, apex # compiled with ghc
, aero # compiled with ghcjs
- # deps get passed to GHC
+ # deps get passed to the compilers
, deps
}:
@@ -20,21 +21,24 @@ nixpkgs:
with nixpkgs;
let
- nsToPath = ns:
- builtins.toString (builtins.replaceStrings ["."] ["/"] ns);
+ nsToPath = ns: builtins.toString (builtins.replaceStrings ["."] ["/"] ns);
+ aeroPath = nsToPath aero;
+ apexPath = nsToPath apex;
+ basePath = lib.strings.removeSuffix "/Apex" apexPath;
depsToPackageSet = packageSet: deps:
map (s: builtins.getAttr s packageSet) deps;
- ghc844_ = pkgs.haskell.packages.ghc844.override (oldAttrs: {
+ ghc865_ = pkgs.haskell.packages.ghc865.override (oldAttrs: {
overrides = with pkgs.haskell.lib; self: super: {
clay = dontCheck super.clay;
};
});
- ghc = ghc844_.ghcWithPackages (hp: depsToPackageSet hp
+ ghc = ghc865_.ghcWithPackages (hp: depsToPackageSet hp
(deps.both ++ deps.apex));
+ # ghcjs-8.6.0.1
ghcjs_ = pkgs.haskell.packages.ghcjs.override (oldAttrs: {
overrides = with pkgs.haskell.lib; self: super: {
clay = dontCheck super.clay;
@@ -59,21 +63,30 @@ in stdenv.mkDerivation {
];
strictDeps = true;
buildPhase = ''
- echo ":: build"
- . .envrc
+ # capitalize paths for 'ghc --make'
+ source .envrc
guile -e '(com simatime caplinks)' -s ./com/simatime/caplinks.scm .
- mkdir -p _bild/${nsToPath apex}
- mkdir -p _bild/${nsToPath aero}
- ${ghc}/bin/ghc -i. --make ${nsToPath apex}.hs -main-is ${apex} \
- -o _bild/${nsToPath apex}
- ${ghcjs}/bin/ghcjs -i. --make ${nsToPath aero}.hs -main-is ${aero} \
- -o _bild/${nsToPath aero}
- '';
- installPhase = ''
- echo ":: install"
- mkdir -p $out
- pwd && ls -al .
- cp -r ./${nsToPath apex}* $out/${apex}
- cp -r ./${nsToPath aero}* $out/${aero}
+ #
+ mkdir -p $out/{bin,static} ${basePath}
+ #
+ # compile with ghc
+ #
+ ${ghc}/bin/ghc -i. --make ${apexPath}.hs -main-is ${apex} \
+ -o ${apexPath}
+ #
+ # compile with ghcjs
+ #
+ ${ghcjs}/bin/ghcjs -i. --make ${aeroPath}.hs -main-is ${aero} \
+ -o ${aeroPath}
+ #
+ # optimize js output
+ #
+ ${pkgs.closurecompiler}/bin/closure-compiler \
+ --compilation_level ADVANCED_OPTIMIZATIONS \
+ --jscomp_off=checkVars \
+ --externs=${aeroPath}.jsexe/all.js.externs \
+ ${aeroPath}.jsexe/all.js > $out/static/${nick}.js
'';
+ # the install process was handled above
+ installPhase = "exit 0";
}