Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using local gems #84

Open
b12f opened this issue Jun 9, 2021 · 2 comments
Open

Using local gems #84

b12f opened this issue Jun 9, 2021 · 2 comments

Comments

@b12f
Copy link

b12f commented Jun 9, 2021

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
  '';
}
@b12f
Copy link
Author

b12f commented Jun 9, 2021

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?

@bendlas
Copy link

bendlas commented Aug 18, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants