bundix
bundix copied to clipboard
Using local gems
Hello,
I'm trying to package openproject for nix, but am relatively new to both nix packaging and the ruby ecosystem. The Gemfile for op contains a couple of gems that are part of the git repository itself. Bundix generates a gemset.nix with e.g. the following gem:
budgets = {
groups = ["opf_plugins"];
platforms = [];
source = {
path = modules/budgets;
type = "path";
};
version = "1.0.0";
};
This of course breaks when trying to get a bundlerEnv going, since the modules/budgets path is not available outside of the openproject repo.
My initial idea was to download the sources, apply the gemset via a patch, and then use the source derivation as the gemdir. However, this breaks dramatically with nix-build running into a segfault.
Any ideas? My current derivation attempt is below.
{ lib, stdenv, fetchurl, bundlerEnv, ruby, makeWrapper }:
let
version = "11.3.1";
source = stdenv.mkDerivation rec {
pname = "openproject-source-${version}";
src = fetchurl {
url = "https://github.com/opf/openproject/archive/refs/tags/v${version}.tar.gz";
sha256 = "sha256-f4A4uiHGywQbTOSivUNsiuwlwDV1E7X6GASWRfZtSb8=";
};
patches = [ ./gemset.patch ];
buildPhase = "";
installPhase = ''
mkdir -p $out/share/openproject
cp -r . $out/share/openproject
'';
};
rubyEnv = bundlerEnv {
name = "openproject-env-${version}";
inherit ruby;
gemdir = "${source}" + ./share/openproject; # just `source` also does not work
groups = [ "development" "production" "sentry" "ldap" "postgres" "test" ];
};
in
stdenv.mkDerivation rec {
pname = "openproject";
inherit version;
nativeBuildInputs = [ makeWrapper ];
buildInputs = [ rubyEnv rubyEnv.wrappedRuby rubyEnv.bundler ];
buildPhase = ''
#stuff
'';
installPhase = ''
# stuff
makeWrapper ${rubyEnv.wrappedRuby}/bin/ruby $out/bin/openproject
'';
}
I should add that building just the source derivation in the code above works fine and applies the patch without problems. I'm guessing this is a problem with stuff being available while the nix language evaluates vs. when derivations are built; source is built after rubyEnv is evaluated. However, how would you then go about doing this?
I could get local gems to work by adding the modules to extraConfigPaths: https://github.com/bendlas/openproject-nix/blob/aa340fca0595cfd5dcac40dd0a1fe7ff634cbd80/ruby/openproject.nix#L38-L44