diff options
Diffstat (limited to 'nixpkgs/doc/languages-frameworks/ruby.section.md')
-rw-r--r-- | nixpkgs/doc/languages-frameworks/ruby.section.md | 88 |
1 files changed, 6 insertions, 82 deletions
diff --git a/nixpkgs/doc/languages-frameworks/ruby.section.md b/nixpkgs/doc/languages-frameworks/ruby.section.md index f58ada029dce..e4c4ffce0432 100644 --- a/nixpkgs/doc/languages-frameworks/ruby.section.md +++ b/nixpkgs/doc/languages-frameworks/ruby.section.md @@ -37,89 +37,13 @@ Ruby in your environment will be able to find the gem and it can be used in your Ruby code (for example via `ruby` or `irb` executables) via `require "nokogiri"` as usual. -#### Installing Ruby and gems - -The Nix and NixOS manuals explain how packages are generally installed. In the -case of Ruby and Nix, it is important to make a distinction between whether the -package is considered an application or a library. - -Applications on Nix are typically installed into your user -profile imperatively using `nix-env -iA`, and on NixOS declaratively by adding the -package name to `environment.systemPackages` in `/etc/nixos/configuration.nix`. -Dependencies such as libraries are automatically installed and should not be -installed explicitly. - -The same goes for Ruby applications and libraries. Ruby applications can be -installed in your profile. But Ruby libraries you would like to use for -development cannot be installed, at least not individually, because they won't -be able to find each other resulting in load errors. Instead, it is possible to -create an environment with `bundlerEnv` or `ruby.withPackages` where the -interpreter and other executables are able to find each other and all of the -gems. - -In the following examples we create an environment with Ruby 2.5, `nokogiri` and -`pry`. There is one limitation here, and that's that you can install only one -environment at a time, otherwise you'll encounter collisions. - -##### Environment defined in separate `.nix` file - -Create a file, e.g. `build.nix`, with the following expression: - -```nix -with import <nixpkgs> {}; -ruby_2_5.withPackages (ps: with ps; [ nokogiri pry ]) -``` - -and install it in your profile with: - -```shell -nix-env -if build.nix -``` - -Now you can use the Ruby interpreter, as well as the extra packages (`pry`, -`nokogiri`) that you added to the environment. - -##### Environment defined in ~/.config/nixpkgs/config.nix` - -If you prefer to, you could also add the environment as a package override to -the nixpkgs set like this: - -```nix -{ # ... - packageOverrides = pkgs: - with pkgs; { - myRubyEnv = ruby.withPackages (ps: with ps; [ nokogiri pry ]); - }; -} -``` - -and install it in your profile path with: - -```shell -nix-env -iA nixpkgs.myRubyEnv -``` - -The environment is installed by referring to the attribute, and considering the -`nixpkgs` channel was used. - -##### Environment defined in `/etc/nixos/configuration.nix` - -For the sake of completeness, here's another example of how to install the -environment system-wide. - -```nix -{ # ... - environment.systemPackages = with pkgs; - [ (ruby.withPackages (ps: with ps; [ nokogiri pry ])) ]; -} -``` - #### Temporary Ruby environment with `nix-shell` -The examples in the previous section showed how to install a Ruby environment -into a profile. For development you may need to use multiple environments. -`nix-shell` gives you the possibility to temporarily load another environment -akin to a combined `chruby` or `rvm` and `bundle exec`. +Rather than having a single Ruby environment shared by all Ruby +development projects on a system, Nix allows you to create separate +environments per project. `nix-shell` gives you the possibility to +temporarily load another environment akin to a combined `chruby` or +`rvm` and `bundle exec`. There are two methods for loading a shell with Ruby packages. The first and recommended method is to create an environment with `ruby.withPackages` and load @@ -225,7 +149,7 @@ bundix If you already have a `Gemfile.lock`, you can simply run `bundix` and it will work the same. -To update the gmes in your `Gemfile.lock`, you may use the `bundix -l` flag, +To update the gems in your `Gemfile.lock`, you may use the `bundix -l` flag, which will create a new `Gemfile.lock` in case the `Gemfile` has a more recent time of modification. |