Hi Daniel,

I replaced rvm on guix with direnv and guix manifests.  Most for the
projects I work on are on different versions of ruby and some which are
not packaged for guix.  The way I do this is as follows.

First I create a .guix.scm file in the root of my project as follows:

  (use-modules (gnu packages)
               (gnu packages ruby)
               (guix packages)
               (guix utils))

  (let* ((ruby-version "3.3.0")
         (ruby (package
                 (inherit ruby-3.2)
                 (version ruby-version)
                 (source
                  (origin
                    (inherit (package-source ruby-3.2))
                    (uri (string-append "http://cache.ruby-lang.org/pub/ruby/";
                                        (version-major+minor ruby-version)
                                        "/ruby-" ruby-version ".tar.xz"))
                    (sha256
                     (base32
                      
"0nwpgf27i43yd8ccsk838n86n9xki68hayxmhbwr0zk3dsinasv7")))))))

         (concatenate-manifests
          (list
           (packages->manifest (list ruby))

           ;; base for building extensions
           (package->development-manifest ruby))))

And run:

  guix package -p .guix -m .guix.scm

This creates a profile containing ruby-3.3.0 in the .guix directory
(with is actually a link the a version of that profile) which includes
enough to build basic gems with native code (the development manifest
for ruby itself) kinda like installing debians build-essentials.  If you
need any libraries to compile some gem add them here too.

Now create a .envrc file as follows:

  GUIX_PROFILE="$(expand_path .guix)"
  [ -f "$GUIX_PROFILE/etc/profile" ] ||
      guix package -p "$GUIX_PROFILE" -m .guix.scm
  source "$GUIX_PROFILE/etc/profile"

  export GEM_HOME="$(expand_path .gems)"
  export GEM_PATH="$GEM_HOME"
  PATH_add $GEM_HOME/bin

This makes sure the profile gets automatically loaded when you "enter"
the project and sets up GEM_HOME so all gems installed for this project
are kept in the local .gems.  Read the direnv documentation to figure
out how to set that up to make "entering" the project work for your dev
environment.  I use the envrc emacs package which work very well for me.

I use the about method for other kinds of projects too.

Cheers,
Remco

Reply via email to