summary refs log tree commit diff
path: root/pkgs/applications/audio/sonic-pi/default.nix
blob: ac72a26b0eecf4609c9bed3e45f9ec6435e33233 (plain) (blame)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
{ mkDerivation
, lib
, qtbase
, fetchFromGitHub
, fftwSinglePrec
, ruby
, libffi
, aubio
, cmake
, pkgconfig
, boost
, bash
, jack2Full
, supercollider
, qscintilla
, qwt
, osmid
}:

let

  supercollider_single_prec = supercollider.override {  fftw = fftwSinglePrec; };

in

mkDerivation rec {
  version = "3.1.0";
  pname = "sonic-pi";

  src = fetchFromGitHub {
    owner = "samaaron";
    repo = "sonic-pi";
    rev = "v${version}";
    sha256 = "0gi4a73szaa8iz5q1gxgpsnyvhhghcfqm6bfwwxbix4m5csbfgh9";
  };

  buildInputs = [
    bash
    cmake
    pkgconfig
    qtbase
    qscintilla
    qwt
    ruby
    libffi
    aubio
    supercollider_single_prec
    boost
  ];

  dontUseCmakeConfigure = true;

  preConfigure = ''
    patchShebangs .
    substituteInPlace app/gui/qt/mainwindow.cpp \
      --subst-var-by ruby "${ruby}/bin/ruby" \
      --subst-var out
  '';

  buildPhase = ''
    export SONIC_PI_HOME=$TMPDIR
    export AUBIO_LIB=${aubio}/lib/libaubio.so
    export OSMID_DIR=app/server/native/osmid

    mkdir -p $OSMID_DIR
    cp ${osmid}/bin/{m2o,o2m} $OSMID_DIR

    pushd app/server/ruby/bin
      ./compile-extensions.rb
      ./i18n-tool.rb -t
    popd

    pushd app/gui/qt
      cp -f ruby_help.tmpl ruby_help.h
      ../../server/ruby/bin/qt-doc.rb -o ruby_help.h

      substituteInPlace SonicPi.pro \
        --replace "LIBS += -lrt -lqt5scintilla2" \
                  "LIBS += -lrt -lqscintilla2 -lqwt"

      lrelease SonicPi.pro
      qmake SonicPi.pro

      make
    popd
  '';

  installPhase = ''
    runHook preInstall
    cp -r . $out
    runHook postInstall
  '';

  # $out/bin/sonic-pi is a shell script, and wrapQtAppsHook doesn't wrap them.
  dontWrapQtApps = true;
  preFixup = ''
    wrapQtApp "$out/bin/sonic-pi" \
      --prefix PATH : ${ruby}/bin:${bash}/bin:${supercollider}/bin:${jack2Full}/bin \
      --set AUBIO_LIB "${aubio}/lib/libaubio.so"
  '';

  meta = {
    homepage = "https://sonic-pi.net/";
    description = "Free live coding synth for everyone originally designed to support computing and music lessons within schools";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [ Phlogistique kamilchm ];
    platforms = lib.platforms.linux;
  };
}