]> Git — Sourcephile - tmp/julm/android.git/blob - haskell/default.nix
appropriateness: enable `git-hooks`
[tmp/julm/android.git] / haskell / default.nix
1 {
2 inputs,
3 pkgs,
4 stdenv,
5 lib,
6 bun,
7 coreutils,
8 miso-lynx,
9 ghc,
10 }:
11 rec {
12 pname = "demo";
13 src =
14 with lib.fileset;
15 toSource rec {
16 root = ./.;
17 fileset = unions [
18 (root + "/LICENSE")
19 (fileFilter (
20 file:
21 lib.any file.hasExt [
22 "cabal"
23 "hs"
24 ]
25 ) root)
26 ];
27 };
28 haskellPackages = pkgs.pkgsCross.ghcjs.haskell.packages.${ghc}.extend (
29 with pkgs.haskell.lib;
30 finalHaskellPkgs: previousHaskellPkgs: {
31 # Includes BigInt patch to support the jsbi polyfill, for Quick/PrimJS
32 ghc = previousHaskellPkgs.ghc.overrideAttrs (
33 drv:
34 drv
35 // {
36 patches = (drv.patches or [ ]) ++ [ "${inputs.miso}/nix/patches/jsbi.patch" ];
37 }
38 );
39
40 # miso
41 miso = finalHaskellPkgs.callCabal2nix "miso" inputs.miso { };
42 miso-lynx = finalHaskellPkgs.callCabal2nix "miso-lynx" inputs.miso-lynx { };
43
44 # deps
45 jsaddle = finalHaskellPkgs.callCabal2nix "jsaddle" "${inputs.miso.inputs.jsaddle}/jsaddle" { };
46 ghcjs-base = finalHaskellPkgs.callCabal2nix "ghcjs-base" inputs.ghcjs-base { };
47
48 # cruft
49 crypton = dontCheck previousHaskellPkgs.crypton;
50 cryptonite = dontCheck previousHaskellPkgs.cryptonite;
51 monad-logger = doJailbreak previousHaskellPkgs.monad-logger;
52 string-interpolate = doJailbreak previousHaskellPkgs.string-interpolate;
53 servant-server = doJailbreak previousHaskellPkgs.servant-server;
54 }
55 );
56 package = haskellPackages.callCabal2nix pname src { };
57 miso-lynx-node_modules = stdenv.mkDerivation {
58 pname = "miso-lynx-node_modules";
59 src = miso-lynx;
60 version = "0.0.0";
61 nativeBuildInputs = [ bun ];
62 dontConfigure = true;
63 # ExplanationNote: fixed-output derivation
64 # cannot reference Nix store paths,
65 # and the fixup phase would change /usr/bin/… into /nix/store/…
66 dontFixup = true;
67 buildPhase = ''
68 export BUN_INSTALL_CACHE_DIR=$(mktemp -d)
69 cp -v ${libs/miso-lynx/bun.lock} bun.lock
70 bun install --force --frozen-lockfile --no-progress --production
71 '';
72 installPhase = ''
73 mkdir -p $out/node_modules
74 cp -R ./node_modules $out
75 '';
76 # CorrectionNote: this has to be updated each time bun.lock is
77 # eg. with `bun install --lockfile-only`
78 outputHash = "sha256-9UsvyZt1PMlPrnEDxQGWN0SOutD826ORZ7ODxbSC8jo=";
79 outputHashAlgo = "sha256";
80 outputHashMode = "recursive";
81 };
82 mainLynxBundle = stdenv.mkDerivation {
83 inherit pname;
84 version = package.version;
85 src = miso-lynx;
86 nativeBuildInputs = [
87 bun
88 ];
89 configurePhase = ''
90 runHook preConfigure
91
92 cp -r ${miso-lynx-node_modules}/node_modules .
93 substituteInPlace node_modules/.bin/rspack \
94 --replace-fail "#!/usr/bin/env" "#!${coreutils}/bin/env"
95
96 runHook postConfigure
97 '';
98 buildPhase = ''
99 runHook preBuild
100
101 bun run js
102 cp -v ${package}/bin/counter.jsexe/all.js .
103 bun build --minify all.js --target=bun --outfile=dist/all.js
104 bun run bundle
105
106 runHook postBuild
107 '';
108 installPhase = ''
109 runHook preInstall
110
111 mkdir $out
112 cp -v dist/main.lynx.bundle $out/
113
114 runHook postInstall
115 '';
116 };
117 }