Ensure Ruby version in Nix Dev Environment when using latest version

删除回忆录丶 提交于 2019-12-10 22:22:06

问题


Currently, the default and latest Ruby in Nix is 2.2.2-p0. When I run nix-env -qaP ruby it returns a list, which says that this ruby version is accessed via nixpkgs.ruby. I expect that this Ruby link will change to stay up-to-date with the latest supported ruby version. There is no optional nixpkgs.ruby_2_2_2 for me to use to ensure my ruby version.

Looking at the .nix definition file at https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/interpreters/ruby/ruby-2.2.2.nix, however, I see that they specify the revision in that script.

So I'm wondering, is there some way for me to specify the revision of the Nix package that I want when I'm listing it in the buildInputs of my Nix expression for creating the development environment (which will be accessed via nix-shell .)? Or is there something else that I might do that would enable me to ensure that ruby 2.2.2-p0 is used for the installation, and not just the latest Ruby, which might change?

Current script:

  let
    pkgs = import <nixpkgs> {};
  in with pkgs; {
    rubyEnv = stdenv.mkDerivation rec {
      name = "ruby-env";
      version = "0.1";
      src = ./.;
      buildInputs = [
        stdenv
        ruby
        bundler_HEAD
      ];
    };
  }

I didn't see this covered in the documentation at http://nixos.org/nix/manual/#chap-writing-nix-expressions


回答1:


There is no optional nixpkgs.ruby_2_2_2 for me to use to ensure my ruby version.

Actually there is a ruby_2_2_2 in nixpkgs:

$ nix-env -qaP ruby
nixos.ruby_1_8      ruby-1.8.7-p374
nixos.ruby_1_9      ruby-1.9.3-p551
nixos.ruby_2_0      ruby-2.0.0-p645
nixos.ruby_2_1_0    ruby-2.1.0-p0
nixos.ruby_2_1_1    ruby-2.1.1-p0
nixos.ruby_2_1_2    ruby-2.1.2-p353
nixos.ruby_2_1_3    ruby-2.1.3-p0
nixos.ruby_2_1      ruby-2.1.6-p0
nixos.ruby_2_2_0    ruby-2.2.0-p0
nixos.ruby          ruby-2.2.2-p0
nixos.bundler_HEAD  ruby-2.2.2-p0-bundler-2015-01-11

By looking at the definition of ruby package in the index, you can see that the current default ruby is just an alias to ruby 2.2:

ruby = ruby_2_2;

that is in turn an alias to ruby 2.2.2:

ruby_2_2 = ruby_2_2_2; 

To override the ruby package to a specific ruby version in a nix expression, overridePackages can be used:

let
  nixpkgs = import <nixpkgs> {};
  pkgs = nixpkgs.overridePackages (self: super: {
    ruby = nixpkgs.ruby_2_2_2;
  });
in with pkgs; 
{
  rubyEnv = stdenv.mkDerivation rec {
    name = "ruby-env";
    version = "0.1";
    src = ./.;
    buildInputs = [
      stdenv
      ruby
      bundler
    ];
  };
}


来源:https://stackoverflow.com/questions/32847962/ensure-ruby-version-in-nix-dev-environment-when-using-latest-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!