generated from coulomb/repo-seed
Some checks failed
Build and Deploy / build-push-deploy (push) Has been cancelled
Root cause: any module re-exporting all 119 IHP entities produces a .hi file ≥ 287 MB, crashing GHC 9.10.3 Data.Binary.Get at exactly position 287,686,318 — even after 4-way split (30 entities × 9.6 MB/entity = 287 MB). Fix: - 8-way split of Generated.Types (~15 entities each, ~144 MB .hi — safe) - Generated.Types replaced with empty stub, removed from exposed-modules (any re-export hub for 119 entities → ~1.1 GB .hi → crash downstream) - pname == "inter-hub-lib" postUnpack patches all 148 `import Generated.Types` lines to import Generated.TypesPart1 through TypesPart8 directly Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
226 lines
13 KiB
Nix
226 lines
13 KiB
Nix
{
|
|
inputs = {
|
|
ihp.url = "github:digitallyinduced/ihp/v1.5";
|
|
nixpkgs.follows = "ihp/nixpkgs";
|
|
nixpkgs-nixos.follows = "ihp/nixpkgs-nixos";
|
|
flake-parts.follows = "ihp/flake-parts";
|
|
devenv.follows = "ihp/devenv";
|
|
systems.follows = "ihp/systems";
|
|
devenv-root = {
|
|
url = "file+file:///dev/null";
|
|
flake = false;
|
|
};
|
|
};
|
|
|
|
outputs = inputs@{ self, nixpkgs, nixpkgs-nixos, ihp, flake-parts, systems, ... }:
|
|
flake-parts.lib.mkFlake { inherit inputs; } {
|
|
|
|
systems = import systems;
|
|
imports = [ ihp.flakeModules.default ];
|
|
|
|
perSystem = { pkgs, config, lib, ... }: {
|
|
ihp = {
|
|
appName = "inter-hub";
|
|
enable = true;
|
|
projectPath = ./.;
|
|
packages = with pkgs; [
|
|
tailwindcss
|
|
];
|
|
haskellPackages = p: with p; [
|
|
# Haskell dependencies go here
|
|
p.ihp
|
|
base
|
|
wai
|
|
text
|
|
# ihp-mail # Email support: https://ihp.digitallyinduced.com/Guide/mail.html
|
|
# ihp-datasync # Real-time DataSync
|
|
# ihp-job-dashboard # Job dashboard UI
|
|
# ihp-typed-sql # Type-safe SQL queries
|
|
# ihp-pglistener # PostgreSQL LISTEN/NOTIFY
|
|
# Phase 5: Anthropic API calls
|
|
http-conduit
|
|
aeson
|
|
string-conversions
|
|
# Phase 9: External API, crypto, SDK generation
|
|
cryptohash-sha256
|
|
base16-bytestring
|
|
random-bytestring
|
|
yaml
|
|
network-uri
|
|
];
|
|
devHaskellPackages = p: with p; [
|
|
cabal-install
|
|
hlint
|
|
hspec
|
|
ihp-hspec
|
|
];
|
|
|
|
# Hoogle documentation server — disabled to save ~400 MB on constrained host
|
|
withHoogle = false;
|
|
|
|
# Disable relation type machinery for faster compilation
|
|
# relationSupport = false;
|
|
|
|
# Skip tests/haddock for specific packages to speed up builds
|
|
# dontCheckPackages = [ "my-package" ];
|
|
# doJailbreakPackages = [ "my-package" ];
|
|
# dontHaddockPackages = [ "my-package" ];
|
|
|
|
# Production build tuning
|
|
# optimizationLevel = "2"; # Default: "1", use "2" for more optimized production binaries
|
|
# rtsFlags = "-A96m -N"; # GHC runtime flags for compiled binaries
|
|
|
|
# Mount additional directories under /static/ in production builds
|
|
# static.extraDirs = {
|
|
# # Frontend = self.packages.${system}.frontend;
|
|
# };
|
|
# static.makeBundling = true; # Set false if not using Makefile for CSS/JS bundling
|
|
};
|
|
|
|
# OCI container image for Kubernetes deployment (Railiance01).
|
|
# Build: nix build .#docker
|
|
# Push: skopeo copy docker-archive:result docker://92.205.130.254:32166/coulomb/inter-hub:SHA
|
|
# Uses IHP's built-in unoptimized image; binary is /bin/RunProdServer.
|
|
packages.docker = config.packages.unoptimized-docker-image;
|
|
|
|
# Custom configuration that will start with `devenv up`
|
|
devenv.shells.default = {
|
|
# Start Mailhog on local development to catch outgoing emails
|
|
# services.mailhog.enable = true;
|
|
|
|
# PostgreSQL extensions
|
|
# services.postgres.extensions = extensions: [ extensions.postgis ];
|
|
|
|
# GHC 9.10.3 crash fix: Generated.Types imports 119 modules, exceeding
|
|
# the ~287 MB interface-file binary-deserialization limit.
|
|
#
|
|
# pkgs is built from `import nixpkgs { overlays = devenv.shells.default.overlays; }`.
|
|
# IHP adds ihp.overlays.default to this list, which sets
|
|
# pkgs.ghc = haskellPackages.override { overrides = ihpOverrides }.
|
|
# We extend pkgs.ghc with a mkDerivation override (lib.mkAfter ensures
|
|
# we run after IHP's overlay, so prev.ghc is already IHP's package set).
|
|
# 2-way split (60 entities) still crashes — TypesPart1.hi itself hits 287 MB.
|
|
# 4-way split (~30 entities, ~150 MB .hi each) stays safely under the limit.
|
|
# When pname == "inter-hub-models", postUnpack replaces the monolithic
|
|
# Types.hs → empty stub (not compiled); inter-hub-lib imports TypesPart1-8 directly.
|
|
overlays = lib.mkAfter [
|
|
(final: prev: {
|
|
ghc = prev.ghc.extend (hfinal: hprev: {
|
|
mkDerivation = args:
|
|
let drv = hprev.mkDerivation args;
|
|
in if (args.pname or "") == "inter-hub-models"
|
|
then drv.overrideAttrs (old: {
|
|
# 8-way split: ~15 entities per TypesPart → ~144 MB .hi each.
|
|
# Root cause: any re-export hub for 119 IHP entities produces
|
|
# a .hi file ≥ 287 MB (the GHC 9.10.3 Data.Binary.Get limit).
|
|
# Generated.Types is replaced with an empty stub and removed
|
|
# from exposed-modules; inter-hub-lib imports TypesPart1-8 directly.
|
|
# -O0 strips unfoldings/specialisations for additional size reduction.
|
|
configureFlags = (old.configureFlags or []) ++ [ "--ghc-option=-O0" ];
|
|
postUnpack = (old.postUnpack or "") + ''
|
|
_types="$sourceRoot/build/Generated/Types.hs"
|
|
|
|
# Create TypesPart1-8: 8-way split, ~15 entities each, ~144 MB .hi
|
|
for _k in 1 2 3 4 5 6 7 8; do
|
|
awk -v K=$_k 'BEGIN{n=0; N=8}
|
|
/^import Generated\./{n++; mods[n]=$2}
|
|
END{
|
|
q_prev = (K==1) ? 0 : int((K-1)*n/N)+1
|
|
q_curr = (K==N) ? n : int(K*n/N)+1
|
|
s = q_prev+1; e = q_curr
|
|
print "module Generated.TypesPart" K " ("
|
|
for(i=s;i<=e;i++){
|
|
if(i<e) print " module " mods[i] ","
|
|
else print " module " mods[i]
|
|
}
|
|
print " ) where"
|
|
for(i=s;i<=e;i++) print "import " mods[i]
|
|
}' "$_types" > "$sourceRoot/build/Generated/TypesPart${_k}.hs"
|
|
done
|
|
|
|
# Empty stub: Generated.Types is NOT a re-export hub.
|
|
# Re-exporting all 119 entities would produce ~1.1 GB .hi,
|
|
# crashing GHC when any downstream module reads it.
|
|
# inter-hub-lib imports TypesPart1-8 directly instead.
|
|
printf '%s\n' 'module Generated.Types () where' > "$_types"
|
|
|
|
# Update cabal: add TypesPart1-8, remove bare Generated.Types
|
|
# (empty stub is kept as a file but not exposed/compiled).
|
|
# 8-space indent required — 4-space is a new stanza field.
|
|
_cabal=$(ls "$sourceRoot"/*.cabal | head -1)
|
|
if ! grep -q 'Generated\.TypesPart1' "$_cabal"; then
|
|
awk '/Generated\.Types$/ && !/TypesPart/{next}
|
|
/^ exposed-modules:/{
|
|
print " ghc-options: -O0"
|
|
print; next
|
|
}
|
|
/Generated\.LearningInsightInclude/{
|
|
print
|
|
for(k=1;k<=8;k++) print " Generated.TypesPart" k
|
|
next
|
|
}
|
|
{print}' "$_cabal" > "$_cabal.new"
|
|
mv "$_cabal.new" "$_cabal"
|
|
fi
|
|
'';
|
|
})
|
|
else if (args.pname or "") == "inter-hub-lib"
|
|
then drv.overrideAttrs (old: {
|
|
# Generated.Types is an empty stub in models (no re-export hub).
|
|
# Replace every bare `import Generated.Types` with 8 TypesPart imports
|
|
# so app modules get all entity types without touching a huge .hi file.
|
|
postUnpack = (old.postUnpack or "") + ''
|
|
find "$sourceRoot" -name "*.hs" | while read _f; do
|
|
if grep -qE "^import Generated\.Types$" "$_f"; then
|
|
awk '/^import Generated\.Types$/{
|
|
for(k=1;k<=8;k++) print "import Generated.TypesPart" k
|
|
next
|
|
}{print}' "$_f" > "$_f.new" && mv "$_f.new" "$_f"
|
|
fi
|
|
done
|
|
'';
|
|
})
|
|
else drv;
|
|
});
|
|
})
|
|
];
|
|
|
|
# Resource limits for constrained host (2 CPU, ~3.8 GiB RAM).
|
|
# -A32m: smaller minor heap (reduces GC pressure).
|
|
# -M2g: hard heap ceiling (prevents OOM on large compiles).
|
|
# Note: -N1 is intentionally omitted — it requires -threaded and
|
|
# would break build-generated-code and similar tools.
|
|
# GHC parallel module compilation is capped via -j1 in .ghci.
|
|
env.GHCRTS = "-A32m -M2g";
|
|
|
|
# Custom processes that don't appear in https://devenv.sh/reference/options/
|
|
processes = {
|
|
tailwind.exec = "tailwindcss -c tailwind/tailwind.config.js -i ./tailwind/app.css -o static/app.css --watch=always";
|
|
};
|
|
};
|
|
};
|
|
|
|
# Adding the new NixOS configuration for "production"
|
|
# See https://ihp.digitallyinduced.com/Guide/deployment.html#deploying-with-deploytonixos for more info
|
|
# Used to deploy the IHP application
|
|
flake.nixosConfigurations."production" = import ./Config/nix/hosts/production/host.nix { inherit inputs; };
|
|
};
|
|
|
|
# The following configuration speeds up build times by using the devenv, cachix and digitallyinduced binary caches
|
|
# You can add your own cachix cache here to speed up builds. For that uncomment the following lines and replace `CHANGE-ME` with your cachix cache name
|
|
nixConfig = {
|
|
extra-substituters = [
|
|
"https://devenv.cachix.org"
|
|
"https://cachix.cachix.org"
|
|
"https://digitallyinduced.cachix.org"
|
|
# "https://CHANGE-ME.cachix.org"
|
|
];
|
|
extra-trusted-public-keys = [
|
|
"devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="
|
|
"cachix.cachix.org-1:eWNHQldwUO7G2VkjpnjDbWwy4KQ/HNxht7H4SSoMckM="
|
|
"digitallyinduced.cachix.org-1:y+wQvrnxQ+PdEsCt91rmvv39qRCYzEgGQaldK26hCKE="
|
|
# "CHANGE-ME.cachix.org-1:CHANGE-ME-PUBLIC-KEY"
|
|
];
|
|
};
|
|
}
|