]> Git — Sourcephile - tmp/julm/android.git/blob - haskell/default.nix
learnability(haskell): clarify the build
[tmp/julm/android.git] / haskell / default.nix
1 {
2 stdenv,
3 lib,
4 bun,
5 coreutils,
6 miso-lynx,
7 ghc,
8 }:
9 let
10 pname = "counter";
11 src =
12 with lib.fileset;
13 toSource rec {
14 root = ./.;
15 fileset = unions [
16 (root + "/LICENSE")
17 (fileFilter (
18 file:
19 lib.any file.hasExt [
20 "cabal"
21 "hs"
22 ]
23 ) root)
24 ];
25 };
26 haskellJS = ghc.callCabal2nix pname src { };
27 miso-lynx-node_modules = stdenv.mkDerivation {
28 pname = "miso-lynx-node_modules";
29 src = miso-lynx;
30 version = "0.0.0";
31 nativeBuildInputs = [ bun ];
32 dontConfigure = true;
33 # ExplanationNote: fixed-output derivation
34 # cannot reference Nix store paths,
35 # and the fixup phase would change /usr/bin/… into /nix/store/…
36 dontFixup = true;
37 buildPhase = ''
38 export BUN_INSTALL_CACHE_DIR=$(mktemp -d)
39 cp -v ${../nix/pkgs/miso-lynx/bun.lock} bun.lock
40 bun install --force --frozen-lockfile --no-progress --production
41 '';
42 installPhase = ''
43 mkdir -p $out/node_modules
44 cp -R ./node_modules $out
45 '';
46 # CorrectionNote: this has to be updated each time bun.lock is
47 # eg. with `bun install --lockfile-only`
48 outputHash = "sha256-9UsvyZt1PMlPrnEDxQGWN0SOutD826ORZ7ODxbSC8jo=";
49 outputHashAlgo = "sha256";
50 outputHashMode = "recursive";
51 };
52 mainLynxBundle = stdenv.mkDerivation {
53 inherit pname;
54 version = haskellJS.version;
55 src = miso-lynx;
56 nativeBuildInputs = [
57 bun
58 ];
59 configurePhase = ''
60 runHook preConfigure
61
62 cp -r ${miso-lynx-node_modules}/node_modules .
63 substituteInPlace node_modules/.bin/rspack \
64 --replace-fail "#!/usr/bin/env" "#!${coreutils}/bin/env"
65
66 runHook postConfigure
67 '';
68 buildPhase = ''
69 runHook preBuild
70
71 bun run js
72 cp -v ${haskellJS}/bin/counter.jsexe/all.js .
73 bun build --minify all.js --target=bun --outfile=dist/all.js
74 bun run bundle
75
76 runHook postBuild
77 '';
78 installPhase = ''
79 runHook preInstall
80
81 mkdir $out
82 cp -v dist/main.lynx.bundle $out/
83
84 runHook postInstall
85 '';
86 };
87 in
88 mainLynxBundle