bobvanderlinden / nixpkgs-ruby

A Nix repository with all Ruby versions being kept up-to-date automatically

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example doesn't work in `nix-shell`

shepting opened this issue · comments

The current Readme in this repo suggests an example Nix file as follows:

{ pkgs, stdenv, fetchFromGitHub }:
let
  nixpkgsRubySource = fetchFromGitHub {
    owner = "bobvanderlinden";
    repo = "nixpkgs-ruby";
    rev = "aaf2d46c7e166fd4cd52cc71720b72eef2486f18";
    sha256 = "10rbw0kmbgq3jc2gngxqkdb6x4dkrh4fyrfqn6bx864vd4cszh5z";
  };
in
rec {
  nixpkgsRuby = import nixpkgsRubySource { inherit pkgs; };
  rubyVersion = nixpkgsRuby.getVersion;

  # Make your own easy-to-access attributes for the versions you use:
  ruby_2_5_1 = rubyVersion ["2" "5" "1"];
  ruby_2_4_4 = rubyVersion ["2" "4" "4"];

  # ... or use it directly as buildInput in your derivation:
  example = stdenv.mkDerivation {
    name = "example";
    buildInputs = [ (rubyVersion ["2" "5" "1"]) ];
    installPhase = ''
      ruby --version > $out
    '';
  };
}

If you run it directly you get:

$ nix-shell nix-pkgs-ruby.nix 
error: cannot auto-call a function that has an argument without a default value ('pkgs')

If you update the file to use a new SHA and slightly different imports:

# Modified version of https://github.com/bobvanderlinden/nixpkgs-ruby README

with import <nixpkgs> {};

# # To get SHA for something like this, run 
# #   nix-prefetch-url --unpack https://github.com/<owner>/<repo>/archive/<rev>.tar.gz
# # In our case the values are:
# #   bobvanderlinden/nixpkgs-ruby  and  66c1a71a657ed98103e883a7fa26da71c697cd94
# # so the command looks like:
# #   nix-prefetch-url --unpack https://github.com/bobvanderlinden/nixpkgs-ruby/archive/66c1a71a657ed98103e883a7fa26da71c697cd94.tar.gz

let
  nixpkgsRubySource = fetchFromGitHub {
    owner = "bobvanderlinden";
    repo = "nixpkgs-ruby";
    rev = "66c1a71a657ed98103e883a7fa26da71c697cd94";
    sha256 = "13vswrvv744av86ixlvypgnq2wsmjm5ba41qg15yg6y60xfqd4lq";
  };

in

stdenv.mkDerivation rec {
  nixpkgsRuby = import nixpkgsRubySource { inherit pkgs; };
  rubyVersion = nixpkgsRuby.getVersion;

  # Make your own easy-to-access attributes for the versions you use:
  ruby_2_5_1 = rubyVersion ["2" "5" "1"];
  ruby_2_4_4 = rubyVersion ["2" "4" "4"];

  name = "airbnb-mobile";
  version = "0.1.0";
  buildInputs = [ ruby_2_4_4 ];
}

You get an error like this:

error: attribute 'getVersion' missing, at /Users/steven_hepting/workspace/apps/custom_ruby.nix:28:17

I'm fairly new to Nix, but would love to try out this repo to get a custom version of Ruby to smooth our transition away from manually-managed dependencies for iOS engineers at Airbnb.

@bobvanderlinden Any suggestions on next steps for me to get this working?

@shepting The code was changed so you can use the example, but replace getVersion with mkDerivationForRubyVersion

See 1521425#diff-5712e736e0de6ba170577f8472c398e9L3

The readme has been updated by @cgraham-zmtp in #2. Does that resolve your issue?

The repo has gone through a number of changes. This issue seems outdated.