summaryrefslogtreecommitdiff
path: root/Com/Simatime/buildGhcjs.nix
diff options
context:
space:
mode:
Diffstat (limited to 'Com/Simatime/buildGhcjs.nix')
-rw-r--r--Com/Simatime/buildGhcjs.nix52
1 files changed, 34 insertions, 18 deletions
diff --git a/Com/Simatime/buildGhcjs.nix b/Com/Simatime/buildGhcjs.nix
index 0a88ce7..0020fa4 100644
--- a/Com/Simatime/buildGhcjs.nix
+++ b/Com/Simatime/buildGhcjs.nix
@@ -1,17 +1,30 @@
-
-nixpkgs:
-
-{ name # the main module namespace
-, nick # a short name for the output
-, deps # passed to ghcjs
-}:
+nixpkgs: main:
with nixpkgs;
+with nixpkgs.lib;
let
- nsToPath = ns: builtins.toString (builtins.replaceStrings ["."] ["/"] ns);
+ # provided by .envrc
+ root = builtins.getEnv "BIZ_ROOT";
+
+ # general functions to put in a lib
+ lines = s: strings.splitString "\n" s;
+ seq = ls: builtins.filter (x: x!= null) ls;
- path = nsToPath name;
+ # turn the file path into a Haskell module name
+ relpath = builtins.replaceStrings ["${root}/"] [""] (builtins.toString main);
+ module = builtins.replaceStrings ["/" ".hs"] ["." ""] relpath;
+
+ # extract info from special comments
+ content = builtins.readFile main;
+ exe = builtins.head (lists.flatten (seq
+ (map (builtins.match "^-- : exe ([[:alnum:]._-]*)$")
+ (lines content))));
+ deps = lists.flatten (seq
+ (map (builtins.match "^-- : dep ([[:alnum:]._-]*)$")
+ (lines content)));
+
+ # do the build...
depsToPackageSet = packageSet: deps:
map (s: builtins.getAttr s packageSet) deps;
@@ -26,39 +39,42 @@ let
# ghcjs-8.6.0.1
ghcjs_ = pkgs.haskell.packages.ghcjs.override (oldAttrs: {
overrides = with pkgs.haskell.lib; self: super: {
+ QuickCheck = dontCheck super.QuickCheck;
+ base-compat-batteries = dontCheck super.http-types;
clay = dontCheck (self.callCabal2nix "clay" claySrc {});
+ comonad = dontCheck super.comonad;
http-types = dontCheck super.http-types;
- tasty-quickcheck = dontCheck super.tasty-quickcheck;
+ network-uri= dontCheck super.network-uri;
scientific = dontCheck super.scientific; # takes forever
servant = dontCheck super.servant;
- comonad = dontCheck super.comonad;
- QuickCheck = dontCheck super.QuickCheck;
+ tasty-quickcheck = dontCheck super.tasty-quickcheck;
+ time-compat = dontCheck super.time-compat;
};
});
ghcjs = ghcjs_.ghcWithPackages (hp: depsToPackageSet hp deps);
in stdenv.mkDerivation {
- name = name;
+ name = module;
version = "0";
src = ../../.; # the git root
nativeBuildInputs = [ ghcjs ];
strictDeps = true;
buildPhase = ''
#
- mkdir -p $out/{bin,static} ${path}
+ mkdir -p $out/{bin,static} ${baseNameOf relpath}
#
# compile with ghcjs
#
${ghcjs}/bin/ghcjs -Werror -i. \
- --make ${path}.hs \
- -main-is ${name} \
- -o ${path}
+ --make ${main} \
+ -main-is ${module} \
+ -o ${exe}
#
# optimize js output
#
${pkgs.closurecompiler}/bin/closure-compiler \
- ${path}.jsexe/all.js > $out/static/${nick}.js
+ ${exe}.jsexe/all.js > $out/static/${exe}
'';
installPhase = "exit 0";
} // { env = ghcjs; }