summaryrefslogtreecommitdiff
path: root/pkgs/development/tools/misc/chruby/default.nix
blob: 98bfab55f6b9b63742e3327b38c4e50ad3b353d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{
  stdenv,
  lib,
  fetchFromGitHub,
  runCommand,
  rubies ? null,
}:

let
  rubiesEnv = runCommand "chruby-env" { preferLocalBuild = true; } ''
    mkdir $out
    ${lib.concatStrings (lib.mapAttrsToList (name: path: "ln -s ${path} $out/${name}\n") rubies)}
  '';

in
stdenv.mkDerivation rec {
  pname = "chruby";

  version = "0.3.9";

  src = fetchFromGitHub {
    owner = "postmodern";
    repo = "chruby";
    rev = "v${version}";
    sha256 = "1894g6fymr8kra9vwhbmnrcr58l022mcd7g9ans4zd3izla2j3gx";
  };

  patches = lib.optionalString (rubies != null) [
    ./env.patch
  ];

  postPatch = lib.optionalString (rubies != null) ''
    substituteInPlace share/chruby/chruby.sh --replace "@rubiesEnv@" ${rubiesEnv}
  '';

  installPhase = ''
    mkdir $out
    cp -r bin $out
    cp -r share $out
  '';

  meta = {
    description = "Changes the current Ruby";
    homepage = "https://github.com/postmodern/chruby";
    license = lib.licenses.mit;
    maintainers = [ ];
    mainProgram = "chruby-exec";
    platforms = lib.platforms.unix;
  };
}