2023-11-19 20:12:05 +00:00
{ depot
, fetchFromGitLab
2021-12-20 21:05:51 +00:00
, pkgs
2024-11-16 16:05:46 +00:00
, mkYarnPackage
, fetchYarnDeps
2021-12-21 19:39:11 +00:00
, lib
2021-12-20 21:05:51 +00:00
, stdenv
, makeWrapper
2024-11-16 16:05:46 +00:00
, python312
, nodejs_22
2021-12-21 19:39:11 +00:00
, ossOnly ? true
2021-12-20 21:05:51 +00:00
} :
let
2024-11-16 16:05:46 +00:00
python3 = python312 ;
nodejs = nodejs_22 ;
version = " 1 . 2 9 . 1 " ;
2021-12-21 19:39:11 +00:00
suffix = lib . optionalString ossOnly " - o s s " ;
src' = fetchFromGitLab {
2023-05-11 11:09:49 +00:00
owner = " b a s e r o w " ;
2021-12-20 21:05:51 +00:00
repo = " b a s e r o w " ;
2021-12-21 19:23:53 +00:00
rev = version ;
2024-11-16 16:05:46 +00:00
hash = " s h a 2 5 6 - E d S r c s 2 + j i U R p f 3 N r v 5 F J z Q k k J 2 m c A + U Y 8 c e S k e L O v U = " ;
2021-12-20 21:05:51 +00:00
} ;
2021-12-21 19:39:11 +00:00
src = if ossOnly then pkgs . runCommand " ${ src' . name } ${ suffix } " { } ''
cp - R $ { src' } $ out
chmod - R u + w $ out
rm - rf $ out/premium
2023-01-14 21:26:29 +00:00
rm - rf $ out/enterprise
2021-12-21 19:39:11 +00:00
2023-01-14 21:26:29 +00:00
sed - i - e ' /baserow_premium/d ' - e ' /baserow_enterprise/d ' $ out/backend/src/baserow/config/settings/base.py
2021-12-21 19:39:11 +00:00
'' e l s e s r c ' ;
2021-12-21 00:18:16 +00:00
2023-11-19 20:12:05 +00:00
inherit ( depot . third_party ) poetry2nix ;
2023-04-02 01:20:15 +00:00
poetry2nixOverrides = poetry2nix . defaultPoetryOverrides . overrideOverlay ( self : super : let
addBuildInputs = f : buildInputs : f . overridePythonAttrs ( old : {
buildInputs = ( old . buildInputs or [ ] ) ++ buildInputs ;
} ) ;
in {
2024-11-16 16:05:46 +00:00
#kombu = let
# kombuVersion = "5.2.4";
#in assert lib.assertMsg (super.kombu.version == kombuVersion) "kombu (${super.kombu.version}) is different version to what I expected (${kombuVersion}); maybe remove the override?"; super.kombu.overridePythonAttrs (old: {
# buildInputs = (old.buildInputs or []) ++ [ self.setuptools ];
# postPatch = ''
# ${old.postPatch or ""}
# substituteInPlace requirements/test.txt --replace "pytz>dev" "pytz"
# '';
#});
2023-04-02 01:20:15 +00:00
opentelemetry-instrumentation-aiohttp = addBuildInputs super . opentelemetry-instrumentation-aiohttp [ self . hatchling ] ;
opentelemetry-instrumentation-aiohttp-client = addBuildInputs super . opentelemetry-instrumentation-aiohttp-client [ self . hatchling ] ;
opentelemetry-instrumentation-botocore = addBuildInputs super . opentelemetry-instrumentation-botocore [ self . hatchling ] ;
opentelemetry-instrumentation-celery = addBuildInputs super . opentelemetry-instrumentation-celery [ self . hatchling ] ;
opentelemetry-instrumentation-dbapi = addBuildInputs super . opentelemetry-instrumentation-dbapi [ self . hatchling ] ;
opentelemetry-instrumentation-django = addBuildInputs super . opentelemetry-instrumentation-django [ self . hatchling ] ;
opentelemetry-instrumentation-grpc = addBuildInputs super . opentelemetry-instrumentation-grpc [ self . hatchling ] ;
opentelemetry-instrumentation-logging = addBuildInputs super . opentelemetry-instrumentation-logging [ self . hatchling ] ;
opentelemetry-instrumentation-psycopg2 = addBuildInputs super . opentelemetry-instrumentation-psycopg2 [ self . hatchling ] ;
opentelemetry-instrumentation-redis = addBuildInputs super . opentelemetry-instrumentation-redis [ self . hatchling ] ;
opentelemetry-instrumentation-requests = addBuildInputs super . opentelemetry-instrumentation-requests [ self . hatchling ] ;
opentelemetry-instrumentation-wsgi = addBuildInputs super . opentelemetry-instrumentation-wsgi [ self . hatchling ] ;
2024-11-16 16:05:46 +00:00
opentelemetry-propagator-aws-xray = addBuildInputs super . opentelemetry-propagator-aws-xray [ self . setuptools ] ;
2024-09-29 18:26:00 +00:00
django-health-check = super . django-health-check . overridePythonAttrs ( old : {
buildInputs = ( old . buildInputs or [ ] ) ++ [
self . sphinx
self . setuptools-scm
] ;
postPatch = ''
sed - i ' /pytest-runner/d ' setup . cfg
'' ;
} ) ;
2023-04-02 01:20:15 +00:00
pysaml2 = addBuildInputs super . pysaml2 [ self . poetry-core ] ;
2024-11-16 16:05:46 +00:00
jira2markdown = addBuildInputs super . jira2markdown [ self . poetry-core ] ;
mistralai = addBuildInputs super . mistralai [ self . poetry-core ] ;
2024-04-26 17:02:05 +00:00
pystemmer = addBuildInputs super . pystemmer [ self . cython ] ;
2024-09-29 18:26:00 +00:00
pytest-runner = null ;
2024-11-16 16:05:46 +00:00
tokenizers = null ;
2024-09-29 18:26:00 +00:00
uvloop = super . uvloop . overridePythonAttrs ( old : {
nativeBuildInputs = ( old . nativeBuildInputs or [ ] ) ++ [
self . pythonRelaxDepsHook
self . setuptools
] ;
pythonRemoveDeps = [ " p y t e s t - r u n n e r " ] ;
} ) ;
2024-11-16 16:05:46 +00:00
orjson = super . orjson . override { preferWheel = true ; } ;
jiter = super . jiter . override { preferWheel = true ; } ;
numpy = python3 . pkgs . numpy ;
django-cachalot = addBuildInputs super . django-cachalot [ self . setuptools ] ;
celery-singleton = super . celery-singleton . overridePythonAttrs ( old : {
postPatch = ''
substituteInPlace pyproject . toml \
- - replace-fail " p o e t r y . m a s o n r y . a p i " " p o e t r y . c o r e . m a s o n r y . a p i "
'' ;
buildInputs = ( old . buildInputs or [ ] ) ++ [ self . poetry-core ] ;
} ) ;
prosemirror = super . prosemirror . overridePythonAttrs ( old : {
buildInputs = ( old . buildInputs or [ ] ) ++ [ self . poetry-core ] ;
nativeBuildInputs = ( old . nativeBuildInputs or [ ] ) ++ [
pkgs . unzip
] ;
} ) ;
anthropic = addBuildInputs super . anthropic [ self . hatch-fancy-pypi-readme ] ;
2023-04-02 01:20:15 +00:00
} ) ;
mkBackendSrc = { type , fromDir , pyproject , poetrylock , extra ? " " }: pkgs . runCommand " b a s e r o w - ${ type } - s r c " {
inherit src pyproject poetrylock fromDir ;
} ''
cp - r $ src / $ fromDir $ out
chmod - R + w $ out
cp $ pyproject $ out/pyproject.toml
cp $ poetrylock $ out/poetry.lock
cp $ src/README.md $ out
$ { extra }
'' ;
mkBackendApp = {
type , fromDir , pyproject , poetrylock , srcExtra ? " " , postInstall ? " "
} : let
src = mkBackendSrc { inherit type fromDir pyproject poetrylock ; extra = srcExtra ; } ;
in poetry2nix . mkPoetryApplication {
projectDir = src ;
inherit pyproject poetrylock postInstall ;
overrides = poetry2nixOverrides ;
python = python3 ;
passthru . src = src ;
} ;
templates = pkgs . runCommand " b a s e r o w - t e m p l a t e s " {
inherit src ;
} ''
cp - r " $ s r c / b a c k e n d / t e m p l a t e s " $ out
'' ;
backendApp = mkBackendApp {
type = " b a c k e n d " ;
fromDir = " b a c k e n d " ;
pyproject = ./backend/pyproject.toml ;
poetrylock = ./backend/poetry.lock ;
srcExtra = ''
substituteInPlace " $ o u t / s r c / b a s e r o w / c o n f i g / s e t t i n g s / b a s e . p y " \
- - replace ' APPLICATION_TEMPLATES_DIR = os . path . join ( BASE_DIR , " . . / . . / . . / t e m p l a t e s " ) ' " A P P L I C A T I O N _ T E M P L A T E S _ D I R = ' ${ templates } ' "
'' ;
postInstall = ''
install - m 0755 $ { ./backend/gunicorn.py } $ out/bin/baserow-gunicorn
install - m 0755 $ { ./backend/celery.py } $ out/bin/baserow-celery
'' ;
} ;
premiumBackendApp = mkBackendApp {
type = " p r e m i u m - b a c k e n d " ;
fromDir = " p r e m i u m / b a c k e n d " ;
pyproject = ./premium-backend/pyproject.toml ;
poetrylock = ./premium-backend/poetry.lock ;
2021-12-21 00:18:16 +00:00
} ;
2023-04-02 01:20:15 +00:00
enterpriseBackendApp = mkBackendApp {
type = " e n t e r p r i s e - b a c k e n d " ;
fromDir = " e n t e r p r i s e / b a c k e n d " ;
pyproject = ./enterprise-backend/pyproject.toml ;
poetrylock = ./enterprise-backend/poetry.lock ;
} ;
backendEnv = backendApp . python . buildEnv . override ( old : {
extraLibs = [ backendApp ] ++ lib . optionals ( ! ossOnly ) [ premiumBackendApp enterpriseBackendApp ] ;
} ) ;
2021-12-21 00:18:16 +00:00
in
{
2024-11-16 16:05:46 +00:00
inherit src ;
2021-12-20 21:05:51 +00:00
2024-11-16 16:05:46 +00:00
web-frontend = mkYarnPackage {
2021-12-21 19:39:11 +00:00
name = " b a s e r o w ${ suffix } - w e b - f r o n t e n d " ;
2024-11-16 16:05:46 +00:00
inherit src nodejs ;
sourceRoot = " s o u r c e ${ lib . optionalString ossOnly " - o s s " } / w e b - f r o n t e n d " ;
# upgraded nan to work with our newer node
packageJSON = ./web-frontend/package.json ;
yarnLock = ./web-frontend/yarn.lock ;
offlineCache = fetchYarnDeps {
yarnLock = ./web-frontend/yarn.lock ;
hash = " s h a 2 5 6 - A I L U g S C v q B t l 5 s E A 5 / k 1 Z C V 0 W h Z M e J U l Z L / f r D b a W P o = " ;
} ;
2021-12-20 21:05:51 +00:00
nativeBuildInputs = [ makeWrapper ] ;
2024-11-16 16:05:46 +00:00
env . BASEROW_OSS_ONLY = ossOnly ;
env . NUXT_TELEMETRY_DISABLED = true ;
pkgConfig = {
node-sass = {
buildInputs = with pkgs ; [ python3 python3 . pkgs . distutils libsass pkg-config ] ;
postInstall = ''
mkdir - p $ HOME/.node-gyp / $ { nodejs . version }
echo 9 > $ HOME/.node-gyp / $ { nodejs . version } /installVersion
ln - sfv $ { nodejs } /include $ HOME/.node-gyp / $ { nodejs . version }
export npm_config_nodedir = $ { nodejs }
LIBSASS_EXT = auto yarn - - offline run build
rm build/config.gypi
'' ;
} ;
} ;
postPatch = ''
substituteInPlace package . json \
- - replace-fail ' " n o d e " : ' ' " _ n o d e _ i g n o r e d _ " : '
'' ;
# Have to override configurePhase since we have a monorepo structure.
configurePhase = ''
runHook preConfigure
cp - r $ node_modules node_modules
chmod - R + w node_modules
runHook postConfigure
'' ;
2021-12-20 21:05:51 +00:00
buildPhase = ''
runHook preBuild
2024-11-16 16:05:46 +00:00
export HOME = $ ( mktemp - d )
yarn - - offline build
runHook postBuild
'' ;
doDist = false ;
installPhase = ''
runHook preInstall
2021-12-20 21:05:51 +00:00
outpath = " $ o u t / s h a r e / b a s e r o w "
2024-11-16 16:05:46 +00:00
mkdir - p " $ o u t p a t h "
cp - R . " $ o u t p a t h / w e b - f r o n t e n d "
rm - rf " $ o u t p a t h / w e b - f r o n t e n d / n o d e _ m o d u l e s "
ln - sf " $ n o d e _ m o d u l e s " " $ o u t p a t h / w e b - f r o n t e n d / n o d e _ m o d u l e s "
2021-12-21 19:39:11 +00:00
$ { lib . optionalString ( ! ossOnly ) ''
mkdir - p $ outpath/premium
2024-11-16 16:05:46 +00:00
cp - R ../premium/web-frontend $ outpath/premium/web-frontend
2023-01-14 21:26:29 +00:00
mkdir - p $ outpath/enterprise
2024-11-16 16:05:46 +00:00
cp - R ../enterprise/web-frontend $ outpath/enterprise/web-frontend
2021-12-21 19:39:11 +00:00
'' }
2021-12-20 21:05:51 +00:00
mkdir $ out/bin
2024-11-16 16:05:46 +00:00
makeWrapper $ node_modules/nuxt/bin/nuxt.js $ out/bin/baserow-web-frontend \
2021-12-20 21:05:51 +00:00
- - run " c d $ o u t p a t h / w e b - f r o n t e n d " \
2024-11-16 16:05:46 +00:00
- - set BASEROW_OSS_ONLY " ${ if ossOnly then " t r u e " else " f a l s e " } " \
- - add-flags " s t a r t - - c o n f i g - f i l e c o n f i g / n u x t . c o n f i g . p r o d . j s "
2021-12-20 21:05:51 +00:00
2024-11-16 16:05:46 +00:00
runHook postInstall
2021-12-20 21:05:51 +00:00
'' ;
} ;
2021-12-21 00:18:16 +00:00
2023-04-02 01:20:15 +00:00
backend = backendEnv ;
2021-12-20 21:05:51 +00:00
}