From d480cce48d04d5e4353281f014f66fd61301c393 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sat, 15 Feb 2020 23:03:40 -0800 Subject: Split buildHaskellApp into buildGhc and buildGhcjs Two functions makes it simpler to reason about what is being built and when, even if it is a bit more explicit. I also removed the dumb Apex/Aero naming thing because Server/Client is just easier to remember. --- Com/Simatime/buildGhc.nix | 54 ++++++++++++++++++++++++ Com/Simatime/buildGhcjs.nix | 64 ++++++++++++++++++++++++++++ Com/Simatime/buildHaskellApp.nix | 90 ---------------------------------------- 3 files changed, 118 insertions(+), 90 deletions(-) create mode 100644 Com/Simatime/buildGhc.nix create mode 100644 Com/Simatime/buildGhcjs.nix delete mode 100644 Com/Simatime/buildHaskellApp.nix (limited to 'Com/Simatime') diff --git a/Com/Simatime/buildGhc.nix b/Com/Simatime/buildGhc.nix new file mode 100644 index 0000000..489651e --- /dev/null +++ b/Com/Simatime/buildGhc.nix @@ -0,0 +1,54 @@ + +nixpkgs: + +{ name # the main module namespace +, nick # a short name, for the executable +, deps # deps get passed to ghc +}: + +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"; + }; + + ghc865_ = pkgs.haskell.packages.ghc865.override (oldAttrs: { + overrides = with pkgs.haskell.lib; self: super: { + clay = self.callCabal2nix "clay" claySrc {}; + wai-middleware-metrics = dontCheck super.wai-middleware-metrics; + }; + }); + + ghc = ghc865_.ghcWithPackages (hp: depsToPackageSet hp deps); + +in stdenv.mkDerivation { + name = name; + version = "0"; + src = ../../.; # this is the git root + nativeBuildInputs = [ ghc ]; + strictDeps = true; + buildPhase = '' + # + mkdir -p $out/{bin,static} ${path} + # + # compile with ghc + # + ${ghc}/bin/ghc -Werror -i. \ + --make ${path}.hs \ + -main-is ${name} \ + -o $out/bin/${nick} + ''; + # the install process was handled above + installPhase = "exit 0"; +} // { env = ghc; } 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; } diff --git a/Com/Simatime/buildHaskellApp.nix b/Com/Simatime/buildHaskellApp.nix deleted file mode 100644 index c7bdd1f..0000000 --- a/Com/Simatime/buildHaskellApp.nix +++ /dev/null @@ -1,90 +0,0 @@ - -nixpkgs: - -{ name # the namespace -, nick # a short name, for the executable -, deps # deps get passed to the compilers -}: - -with nixpkgs; - -let - nsToPath = ns: builtins.toString (builtins.replaceStrings ["."] ["/"] ns); - pathToNs = p: builtins.replaceStrings ["/"] ["."] p; - basePath = nsToPath name; - apexPath = basePath + "/Apex"; # compiled with ghc - aeroPath = basePath + "/Aero"; # compiled with ghcjs - - depsToPackageSet = packageSet: deps: - map (s: builtins.getAttr s packageSet) deps; - - claySrc = pkgs.fetchFromGitHub { - owner = "sebastiaanvisser"; - repo = "clay"; - rev = "cc7729b1b42a79e261091ff7835f7fc2a7ae3cee"; - sha256 = "1vd67976lvi5l4qq18zy6j44apynkl44ps04p8vwfx4gzr895dyp"; - }; - - ghc865_ = pkgs.haskell.packages.ghc865.override (oldAttrs: { - overrides = with pkgs.haskell.lib; self: super: { - clay = self.callCabal2nix "clay" claySrc {}; - wai-middleware-metrics = dontCheck super.wai-middleware-metrics; - }; - }); - - 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 (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.both ++ deps.aero)); - -in { - inherit ghc ghcjs; - app = stdenv.mkDerivation { - name = name; - version = "0"; - src = ../../.; # this is the git root - nativeBuildInputs = [ - ghc ghcjs guile - ]; - strictDeps = true; - buildPhase = '' - # - mkdir -p $out/{bin,static} ${basePath} - # - # compile with ghc - # - ${ghc}/bin/ghc -Werror -i. \ - --make ${apexPath}.hs \ - -main-is ${pathToNs apexPath} \ - -o $out/bin/${nick} - # - # compile with ghcjs - # - ${ghcjs}/bin/ghcjs -Werror -i. \ - --make ${aeroPath}.hs \ - -main-is ${pathToNs aeroPath} \ - -o ${aeroPath} - # - # optimize js output - # - ${pkgs.closurecompiler}/bin/closure-compiler \ - ${aeroPath}.jsexe/all.js > $out/static/${nick}.js - ''; - # the install process was handled above - installPhase = "exit 0"; - }; -} -- cgit v1.2.3