]> Git — Sourcephile - tmp/julm/android.git/blob - haskell/default.nix
compatibility(haskell): enable `ghcPackages.shellFor`
[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 (drv: drv // {
33 patches = (drv.patches or []) ++ [ "${inputs.miso}/nix/patches/jsbi.patch" ];
34 });
35
36 # miso
37 miso = finalHaskellPkgs.callCabal2nix "miso" inputs.miso {};
38 miso-lynx = finalHaskellPkgs.callCabal2nix "miso-lynx" inputs.miso-lynx {};
39
40 # deps
41 jsaddle = finalHaskellPkgs.callCabal2nix "jsaddle" "${inputs.miso.inputs.jsaddle}/jsaddle" {};
42 ghcjs-base = finalHaskellPkgs.callCabal2nix "ghcjs-base" inputs.ghcjs-base {};
43
44 # cruft
45 crypton = dontCheck previousHaskellPkgs.crypton;
46 cryptonite = dontCheck previousHaskellPkgs.cryptonite;
47 monad-logger = doJailbreak previousHaskellPkgs.monad-logger;
48 string-interpolate = doJailbreak previousHaskellPkgs.string-interpolate;
49 servant-server = doJailbreak previousHaskellPkgs.servant-server;
50 });
51 package = haskellPackages.callCabal2nix pname src { };
52 miso-lynx-node_modules = stdenv.mkDerivation {
53 pname = "miso-lynx-node_modules";
54 src = miso-lynx;
55 version = "0.0.0";
56 nativeBuildInputs = [ bun ];
57 dontConfigure = true;
58 # ExplanationNote: fixed-output derivation
59 # cannot reference Nix store paths,
60 # and the fixup phase would change /usr/bin/… into /nix/store/…
61 dontFixup = true;
62 buildPhase = ''
63 export BUN_INSTALL_CACHE_DIR=$(mktemp -d)
64 cp -v ${../nix/pkgs/miso-lynx/bun.lock} bun.lock
65 bun install --force --frozen-lockfile --no-progress --production
66 '';
67 installPhase = ''
68 mkdir -p $out/node_modules
69 cp -R ./node_modules $out
70 '';
71 # CorrectionNote: this has to be updated each time bun.lock is
72 # eg. with `bun install --lockfile-only`
73 outputHash = "sha256-9UsvyZt1PMlPrnEDxQGWN0SOutD826ORZ7ODxbSC8jo=";
74 outputHashAlgo = "sha256";
75 outputHashMode = "recursive";
76 };
77 mainLynxBundle = stdenv.mkDerivation {
78 inherit pname;
79 version = package.version;
80 src = miso-lynx;
81 nativeBuildInputs = [
82 bun
83 ];
84 configurePhase = ''
85 runHook preConfigure
86
87 cp -r ${miso-lynx-node_modules}/node_modules .
88 substituteInPlace node_modules/.bin/rspack \
89 --replace-fail "#!/usr/bin/env" "#!${coreutils}/bin/env"
90
91 runHook postConfigure
92 '';
93 buildPhase = ''
94 runHook preBuild
95
96 bun run js
97 cp -v ${package}/bin/counter.jsexe/all.js .
98 bun build --minify all.js --target=bun --outfile=dist/all.js
99 bun run bundle
100
101 runHook postBuild
102 '';
103 installPhase = ''
104 runHook preInstall
105
106 mkdir $out
107 cp -v dist/main.lynx.bundle $out/
108
109 runHook postInstall
110 '';
111 };
112 }