depot/nix/pkgs/baserow/default.nix

149 lines
5.2 KiB
Nix
Raw Normal View History

2021-12-21 19:23:53 +00:00
{ fetchFromGitLab
2021-12-20 21:05:51 +00:00
, pkgs
, lib
2021-12-20 21:05:51 +00:00
, stdenv
, makeWrapper
2021-12-21 00:18:16 +00:00
, python3
, nodejs-16_x
, ossOnly ? true
2021-12-20 21:05:51 +00:00
}:
let
2023-01-14 21:26:29 +00:00
version = "1.13.3";
suffix = lib.optionalString ossOnly "-oss";
src' = fetchFromGitLab {
2021-12-21 19:23:53 +00:00
owner = "bramw";
2021-12-20 21:05:51 +00:00
repo = "baserow";
2021-12-21 19:23:53 +00:00
rev = version;
2023-01-14 21:26:29 +00:00
sha256 = "00fi5hqz55k08y7wwds42d1z6q1ax2hpb2x5fi1nyc3ymk7khr09";
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
sed -i -e '/premium/d' -e '/enterprise/d' $out/web-frontend/config/nuxt.config.base.js
'' else src';
2021-12-20 21:05:51 +00:00
web-frontend-deps = import ./web-frontend {
inherit pkgs nodejs;
inherit (pkgs) system;
src = "${src}/web-frontend";
};
2021-12-21 00:18:16 +00:00
nodejs = nodejs-16_x;
2021-12-21 00:18:16 +00:00
python = python3.override {
packageOverrides = self: super:
let
oss = import ./backend/pynixify/overlay.nix self super;
premium = import ./premium-backend/pynixify/overlay.nix self super;
2023-01-14 21:26:29 +00:00
enterprise = import ./enterprise-backend/pynixify/overlay.nix self super;
baserow-premium-backend = premium.baserow-premium-backend.overridePythonAttrs (_: {
inherit version;
src = "${src}/premium/backend";
postInstall = ''
install -m0644 $src/src/baserow_premium/public_key.pem $out/${python.sitePackages}/baserow_premium/public_key.pem
'';
});
2023-01-14 21:26:29 +00:00
baserow-enterprise-backend = enterprise.baserow-enterprise-backend.overridePythonAttrs (_: {
inherit version;
src = "${src}/enterprise/backend";
postPatch = ''
pushd src/baserow_enterprise
find . -name '*.py' -printf '%h\n' | sort | uniq | while read pydir; do
thisdir=$pydir
while [[ "$thisdir" != "." ]]; do
test -f $thisdir/__init__.py || touch $thisdir/__init__.py
thisdir="$(dirname $thisdir)"
done
done
popd
'';
2023-01-14 21:26:29 +00:00
});
2021-12-21 00:18:16 +00:00
in
oss // (if !ossOnly then premium else {}) // {
2021-12-21 00:18:16 +00:00
baserow-backend = oss.baserow-backend.overridePythonAttrs (oldAttrs: {
inherit version;
2021-12-21 00:18:16 +00:00
src = "${src}/backend";
prePatch = ''
# Yeet. Just assume everything is installed in the environment already.
> requirements/base.txt
'';
2023-01-14 21:26:29 +00:00
propagatedBuildInputs = oldAttrs.propagatedBuildInputs ++ lib.optionals (!ossOnly) [ baserow-premium-backend baserow-enterprise-backend ];
2021-12-21 00:18:16 +00:00
});
2023-01-14 21:26:29 +00:00
} // (if !ossOnly then { inherit baserow-premium-backend baserow-enterprise-backend; } else {});
2021-12-21 00:18:16 +00:00
};
in
{
2022-11-02 02:08:52 +00:00
inherit src web-frontend-deps python;
2021-12-20 21:05:51 +00:00
web-frontend = stdenv.mkDerivation {
name = "baserow${suffix}-web-frontend";
2021-12-21 19:23:53 +00:00
inherit src version;
2021-12-20 21:05:51 +00:00
buildInputs = [ nodejs ];
nativeBuildInputs = [ makeWrapper ];
nodeDependencies = web-frontend-deps.shell.nodeDependencies;
buildPhase = ''
runHook preBuild
outpath="$out/share/baserow"
mkdir -p $outpath
2021-12-20 21:05:51 +00:00
cp -R web-frontend $outpath/web-frontend
${lib.optionalString (!ossOnly) ''
mkdir -p $outpath/premium
cp -R premium/web-frontend $outpath/premium/web-frontend
2023-01-14 21:26:29 +00:00
mkdir -p $outpath/enterprise
cp -R enterprise/web-frontend $outpath/enterprise/web-frontend
''}
2021-12-20 21:05:51 +00:00
# Disable prompts
export MINIMAL=true
export NODE_OPTIONS=--openssl-legacy-provider
2021-12-20 21:05:51 +00:00
pushd $outpath/web-frontend
mkdir node_modules
for f in $nodeDependencies/lib/node_modules/*; do
ln -s "$f" ./node_modules
done
export PATH="$nodeDependencies/bin:$PATH"
./node_modules/nuxt/bin/nuxt.js build --config-file config/nuxt.config.local.js
popd
mkdir $out/bin
makeWrapper $nodeDependencies/lib/node_modules/nuxt/bin/nuxt.js $out/bin/baserow-web-frontend \
--run "cd $outpath/web-frontend" \
--add-flags "start --config-file config/nuxt.config.local.js"
runHook postBuild
'';
dontInstall = true;
};
2021-12-21 00:18:16 +00:00
backend = python.pkgs.baserow-backend.overridePythonAttrs (oldAttrs: {
2021-12-21 19:23:53 +00:00
inherit version;
2021-12-21 00:18:16 +00:00
src = "${src}/backend";
prePatch = ''
# Yeet. Just assume everything is installed in the environment already.
> requirements/base.txt
2021-12-21 05:48:40 +00:00
substituteInPlace src/baserow/config/settings/base.py \
--replace 'APPLICATION_TEMPLATES_DIR = os.path.join(BASE_DIR, "../../../templates")' "APPLICATION_TEMPLATES_DIR = '$out/share/baserow/templates'"
2021-12-21 00:18:16 +00:00
'';
postInstall = ''
comm -23 <(find $src/src/baserow/ -type d | sed "s,$src/src/baserow/,," | sort) <(find $out/${python.sitePackages}/baserow/ -type d | sed "s,$out/${python.sitePackages}/baserow/,," | sort) | while read missingDir; do
test -e "$out/${python.sitePackages}/baserow/$missingDir" && continue
cp -R "$src/src/baserow/$missingDir" "$out/${python.sitePackages}/baserow/$missingDir"
done
2021-12-21 05:48:40 +00:00
install -d -m 0755 $out/share/baserow
cp -R "$src/templates" "$out/share/baserow/templates"
install -m 0755 ${./backend/gunicorn.py} $out/bin/baserow-gunicorn
install -m 0755 ${./backend/celery.py} $out/bin/baserow-celery
'';
2021-12-21 00:18:16 +00:00
});
2021-12-20 21:05:51 +00:00
}