loomio-nix/pkg/loomio/default.nix

104 lines
1.8 KiB
Nix

{
pkgs,
lib,
buildPackages,
buildNpmPackage,
fetchFromGitHub,
stdenv,
writeShellScriptBin,
writeText,
symlinkJoin,
callPackage,
bundlerEnv,
ruby_3_2,
esbuild,
}:
let
gemfile-patch = callPackage ./gemfile-patch.nix {};
src = callPackage ./source.nix {
patches = [
gemfile-patch
./creds.patch
./esbuild-linux-64.patch
];
};
gems = bundlerEnv {
name = "loomio-env";
ruby = ruby_3_2;
gemset = ./. + "/gemset.nix";
gemdir = src;
};
vue = buildNpmPackage {
name = "loomio-vue";
src = "${src}";
npmRoot = "vue";
npmDepsHash = "sha256-DtzB1XIbdhJkLV88h1caKQeWfErwWBBf4OiQuKM/oQc=";
buildPhase = ''
runHook preBuild
if [ -n "''${npmRoot-}" ]; then
pushd "$npmRoot"
fi
npm run build
if [ -n "''${npmRoot-}" ]; then
popd
fi
runHook postBuild
'';
dontNpmInstall = true;
installPhase = ''
mkdir $out
cp -r * $out
'';
};
databaseConfig = writeText "database.yml" ''
production:
adapter: postgresql
database: <%= ENV['LOOMIO_DATABASE'] %>
host: /var/run/postgresql
'';
in stdenv.mkDerivation {
name = "loomio";
src = vue;
nativeBuildInputs = [ gems gems.wrappedRuby ];
buildInputs = [gems ruby_3_2];
buildPhase = ''
runHook preBuild
cp ${databaseConfig} config/database.yml
cp ${./puma.rb} config/puma.rb
# ln -s ''${vueNodeModules} vue/node_modules
# ln -s ''${vue} vue-built
export BUNDLE_FORCE_RUBY_PLATFORM=true
${gems}/bin/bundle exec bootsnap precompile --gemfile app/ lib/
patchShebangs bin/
for b in $(ls ${gems}/bin/)
do
if [ ! -f bin/$b ]; then
ln -s ${gems}/bin/$b bin/$b
fi
done
runHook postBuild
'';
installPhase = ''
mkdir -p $out
cp -r * $out
'';
}