loomio-nix/pkg/loomio/default.nix

104 lines
1.8 KiB
Nix
Raw Normal View History

2024-08-25 10:26:00 +00:00
{
pkgs,
lib,
buildPackages,
buildNpmPackage,
fetchFromGitHub,
stdenv,
writeShellScriptBin,
writeText,
symlinkJoin,
callPackage,
bundlerEnv,
ruby_3_2,
2024-08-25 10:26:00 +00:00
esbuild,
}:
2024-04-05 12:19:55 +00:00
let
gemfile-patch = callPackage ./gemfile-patch.nix {};
2024-08-25 10:26:00 +00:00
src = callPackage ./source.nix {
patches = [
gemfile-patch
./creds.patch
2024-08-25 10:26:00 +00:00
./esbuild-linux-64.patch
];
};
2024-04-05 12:19:55 +00:00
gems = bundlerEnv {
name = "loomio-env";
ruby = ruby_3_2;
gemset = ./. + "/gemset.nix";
gemdir = src;
};
2024-08-23 08:24:36 +00:00
2024-08-25 10:26:00 +00:00
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
'';
};
2024-08-23 08:24:36 +00:00
databaseConfig = writeText "database.yml" ''
production:
adapter: postgresql
database: <%= ENV['LOOMIO_DATABASE'] %>
host: /var/run/postgresql
2024-08-23 08:24:36 +00:00
'';
2024-04-05 12:19:55 +00:00
in stdenv.mkDerivation {
name = "loomio";
2024-08-25 10:26:00 +00:00
src = vue;
nativeBuildInputs = [ gems gems.wrappedRuby ];
2024-04-05 12:19:55 +00:00
buildInputs = [gems ruby_3_2];
buildPhase = ''
runHook preBuild
cp ${databaseConfig} config/database.yml
cp ${./puma.rb} config/puma.rb
2024-08-25 10:26:00 +00:00
# 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
'';
2024-04-05 12:19:55 +00:00
installPhase = ''
mkdir -p $out
cp -r * $out
2024-04-05 12:19:55 +00:00
'';
}