depot/nix/pkgs/baserow/default.nix

255 lines
9 KiB
Nix
Raw Normal View History

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
, lib
2021-12-20 21:05:51 +00:00
, stdenv
, makeWrapper
2024-11-16 16:05:46 +00:00
, python312
, nodejs_22
, 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.29.1";
suffix = lib.optionalString ossOnly "-oss";
src' = fetchFromGitLab {
owner = "baserow";
2021-12-20 21:05:51 +00:00
repo = "baserow";
2021-12-21 19:23:53 +00:00
rev = version;
2024-11-16 16:05:46 +00:00
hash = "sha256-EdSrcs2+jiURpf3Nrv5FJzQkkJ2mcA+UY8ceSkeLOvU=";
2021-12-20 21:05:51 +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
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
'' else src';
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 = [ "pytest-runner" ];
});
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 "poetry.masonry.api" "poetry.core.masonry.api"
'';
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 "baserow-${type}-src" {
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 "baserow-templates" {
inherit src;
} ''
cp -r "$src/backend/templates" $out
'';
backendApp = mkBackendApp {
type = "backend";
fromDir = "backend";
pyproject = ./backend/pyproject.toml;
poetrylock = ./backend/poetry.lock;
srcExtra = ''
substituteInPlace "$out/src/baserow/config/settings/base.py" \
--replace 'APPLICATION_TEMPLATES_DIR = os.path.join(BASE_DIR, "../../../templates")' "APPLICATION_TEMPLATES_DIR = '${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 = "premium-backend";
fromDir = "premium/backend";
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 = "enterprise-backend";
fromDir = "enterprise/backend";
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 {
name = "baserow${suffix}-web-frontend";
2024-11-16 16:05:46 +00:00
inherit src nodejs;
sourceRoot = "source${lib.optionalString ossOnly "-oss"}/web-frontend";
# 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 = "sha256-AILUgSCvqBtl5sEA5/k1ZCV0WhZMeJUlZL/frDbaWPo=";
};
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 '"node": ' '"_node_ignored_": '
'';
# 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="$out/share/baserow"
2024-11-16 16:05:46 +00:00
mkdir -p "$outpath"
cp -R . "$outpath/web-frontend"
rm -rf "$outpath/web-frontend/node_modules"
ln -sf "$node_modules" "$outpath/web-frontend/node_modules"
${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-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 "cd $outpath/web-frontend" \
2024-11-16 16:05:46 +00:00
--set BASEROW_OSS_ONLY "${if ossOnly then "true" else "false"}" \
--add-flags "start --config-file config/nuxt.config.prod.js"
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
}