]> Git — Sourcephile - tmp/julm/android.git/blob - haskell/default.nix
learnability(nix): add a `README.md`
[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 updated
77 # eg. with `bun install --lockfile-only`
78 # AppropriatenessToDo: miso-lynx should provide bun.lock
79 outputHash = "sha256-9UsvyZt1PMlPrnEDxQGWN0SOutD826ORZ7ODxbSC8jo=";
80 outputHashAlgo = "sha256";
81 outputHashMode = "recursive";
82 };
83 mainLynxBundle = stdenv.mkDerivation {
84 inherit pname;
85 version = package.version;
86 src = miso-lynx;
87 nativeBuildInputs = [
88 bun
89 ];
90 configurePhase = ''
91 runHook preConfigure
92
93 cp -r ${miso-lynx-node_modules}/node_modules .
94 substituteInPlace node_modules/.bin/rspack \
95 --replace-fail "#!/usr/bin/env" "#!${coreutils}/bin/env"
96
97 runHook postConfigure
98 '';
99 buildPhase = ''
100 runHook preBuild
101
102 bun run js
103 cp -v ${package}/bin/demo.jsexe/all.js .
104 bun build --minify all.js --target=bun --outfile=dist/all.js
105 bun run bundle
106
107 runHook postBuild
108 '';
109 installPhase = ''
110 runHook preInstall
111
112 mkdir $out
113 cp -v dist/main.lynx.bundle $out/
114
115 runHook postInstall
116 '';
117 };
118 }