about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/editors/jupyter-kernels/clojupyter/default.nix
blob: c71b14f174228b641fd6bb605237031dcecfb4c2 (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
{ pkgs
, stdenv
, lib
, jre
, fetchFromGitHub
, writeShellScript
, runCommand
, imagemagick
}:

# To test:
# $(nix-build --no-out-link -E 'with import <nixpkgs> {}; jupyter.override { definitions = { clojure = clojupyter.definition; }; }')/bin/jupyter-notebook

let
  cljdeps = import ./deps.nix { inherit pkgs; };
  classp  = cljdeps.makeClasspaths {};

  shellScript = writeShellScript "clojupyter" ''
    ${jre}/bin/java -cp ${classp} clojupyter.kernel.core "$@"
  '';

  pname = "clojupyter";
  version = "0.3.2";

  meta = with lib; {
    description = "A Jupyter kernel for Clojure";
    homepage = "https://github.com/clojupyter/clojupyter";
    license = licenses.mit;
    maintainers = with maintainers; [ thomasjm ];
    platforms = jre.meta.platforms;
  };

  sizedLogo = size: stdenv.mkDerivation {
    name = "clojupyter-logo-${size}x${size}.png";

    src = fetchFromGitHub {
      owner = "clojupyter";
      repo = "clojupyter";
      rev = "0.3.2";
      sha256 = "1wphc7h74qlm9bcv5f95qhq1rq9gmcm5hvjblb01vffx996vr6jz";
    };

    buildInputs = [ imagemagick ];

    dontConfigure = true;
    dontInstall = true;

    buildPhase = ''
      convert ./resources/clojupyter/assets/logo-64x64.png -resize ${size}x${size} $out
    '';

    inherit meta;
  };

in

rec {
  launcher = runCommand "clojupyter" { inherit pname version meta shellScript; } ''
    mkdir -p $out/bin
    ln -s $shellScript $out/bin/clojupyter
  '';

  definition = {
    displayName = "Clojure";
    argv = [
      "${launcher}/bin/clojupyter"
      "{connection_file}"
    ];
    language = "clojure";
    logo32 = sizedLogo "32";
    logo64 = sizedLogo "64";
  };
}