Files
inter-hub/flake.nix
tegwick 3283ad62ee
Some checks failed
Build and Deploy / build-push-deploy (push) Has been cancelled
fix(nix): intercept callCabal2nix to patch inter-hub-models
Previous attempt failed: inter-hub-models is not a named attribute in
haskellPackages (IHP creates it via callCabal2nix locally), so the
hasAttr guard bailed silently.

New approach: override callCabal2nix itself. When called with
name == "inter-hub-models", inject a postUnpack phase that copies
TypesPart1/TypesPart2 into the build sandbox and replaces Types.hs
with the thin wrapper. Applied to both haskellPackages and
haskell.packages.ghc910 to cover whichever set IHP uses.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-30 00:38:12 +02:00

186 lines
9.4 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 ];
# GHC 9.10.3 crash fix: Generated.Types imports 119 modules, pushing the
# combined interface-file read past a ~287 MB binary-deserialization limit.
#
# inter-hub-models is NOT a named attribute in haskellPackages — IHP creates
# it as a local derivation via callCabal2nix. We intercept at callCabal2nix:
# when called with name "inter-hub-models", we add a postUnpack phase that
# injects TypesPart1/TypesPart2 and replaces Types.hs with a thin wrapper.
#
# Applied to both haskellPackages (IHP's modified default set) and
# haskell.packages.ghc910 (the specific GHC version, whichever IHP uses).
nixpkgs.overlays = [
(let
patchCallCabal2nix = hsPackages: hsPackages.extend (hfinal: hprev: {
callCabal2nix = name: src: args:
let drv = hprev.callCabal2nix name src args;
in if name == "inter-hub-models"
then drv.overrideAttrs (old: {
postUnpack = (old.postUnpack or "") + ''
cp ${./build/Generated/TypesPart1.hs} \
"$sourceRoot/build/Generated/TypesPart1.hs"
cp ${./build/Generated/TypesPart2.hs} \
"$sourceRoot/build/Generated/TypesPart2.hs"
printf '%s\n' \
'-- Split wrapper: GHC 9.10.3 interface-file overflow workaround.' \
'module Generated.Types (' \
' module Generated.TypesPart1,' \
' module Generated.TypesPart2' \
' ) where' \
'import Generated.TypesPart1' \
'import Generated.TypesPart2' \
> "$sourceRoot/build/Generated/Types.hs"
cabal_file=$(ls "$sourceRoot"/*.cabal | head -1)
awk '/Generated\.LearningInsightInclude/{
print
print " Generated.TypesPart1"
print " Generated.TypesPart2"
next
}{print}' "$cabal_file" > /tmp/patched-models.cabal
mv /tmp/patched-models.cabal "$cabal_file"
'';
})
else drv;
});
in final: prev: {
# IHP likely rewrites haskellPackages to point to GHC 9.10.3; cover both.
haskellPackages = patchCallCabal2nix prev.haskellPackages;
haskell = prev.haskell // {
packages = prev.haskell.packages // {
ghc910 = patchCallCabal2nix prev.haskell.packages.ghc910;
};
};
})
];
perSystem = { pkgs, config, ... }: {
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 ];
# 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"
];
};
}