]> Git — Sourcephile - tmp/julm/android.git/blob - haskell/default.nix
Maintainability/Analysability(shell): add `apkeep`
[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 bun install --force --frozen-lockfile --no-progress --production
70 '';
71 installPhase = ''
72 mkdir -p $out/node_modules
73 cp -R ./node_modules $out
74 '';
75 # CorrectionNote: this has to be updated each time `${miso-lynx}/bun.lock` is updated
76 # eg. with `bun install --lockfile-only`
77 outputHash = "sha256-d3LP42/XGKs/GUnPQ8sO3JE4fVsacWuIfYEbsNlDZTE=";
78 outputHashAlgo = "sha256";
79 outputHashMode = "recursive";
80 };
81 mainLynxBundle = stdenv.mkDerivation {
82 inherit pname;
83 version = package.version;
84 src = miso-lynx;
85 nativeBuildInputs = [
86 bun
87 ];
88 configurePhase = ''
89 runHook preConfigure
90
91 cp -r ${miso-lynx-node_modules}/node_modules .
92 substituteInPlace node_modules/.bin/rspack \
93 --replace-fail "#!/usr/bin/env" "#!${coreutils}/bin/env"
94
95 runHook postConfigure
96 '';
97 buildPhase = ''
98 runHook preBuild
99
100 bun run js
101 cp -v ${package}/bin/demo.jsexe/all.js .
102 bun build --minify all.js --target=bun --outfile=dist/all.js
103 bun run bundle
104
105 runHook postBuild
106 '';
107 installPhase = ''
108 runHook preInstall
109
110 mkdir $out
111 cp -v dist/main.lynx.bundle $out/
112
113 runHook postInstall
114 '';
115 };
116 }