From d446f2ead3b8f8393e8b29088b920054d6b3fcf8 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sat, 2 Nov 2019 13:46:54 -0700 Subject: fix buildHaskellApp nix function --- com/simatime/buildHaskellApp.nix | 53 +++++++++++++++++++++++++--------------- default.nix | 1 + 2 files changed, 34 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"; } diff --git a/default.nix b/default.nix index 42b6c3a..ceb0d12 100644 --- a/default.nix +++ b/default.nix @@ -77,6 +77,7 @@ in { } // { ibb = buildHaskellApp { name = "Com.Influencedbybooks"; + nick = "ibb"; apex = "Com.Influencedbybooks.Apex"; aero = "Com.Influencedbybooks.Aero"; deps = { -- cgit v1.2.3