summary refs log tree commit diff
path: root/pkgs/applications/office/zim/default.nix
blob: 658f460793f16f17d61644ff57306e7520b75cf6 (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
{ stdenv, lib, fetchurl, buildPythonPackage, pythonPackages, pygtk, pygobject, python }:

#
# TODO: Declare configuration options for the following optional dependencies:
#  -  File stores: hg, git, bzr
#  -  Included plugins depenencies: dot, ditaa, dia, any other?
#  -  pyxdg: Need to make it work first (see setupPyInstallFlags).
#

buildPythonPackage rec {
  name = "zim-${version}";
  version = "0.60";
  namePrefix = "";
  
  src = fetchurl {
    url = "http://zim-wiki.org/downloads/zim-0.61.tar.gz";
    sha256 = "0jncxkf83bwra3022jbvjfwhk5w8az0jlwr8nsvm7wa1zfrajhsq";
  };

  propagatedBuildInputs = [ pythonPackages.sqlite3 pygtk /*pythonPackages.pyxdg*/ pygobject ];

  preBuild = ''
    mkdir -p /tmp/home
    export HOME="/tmp/home"
  '';
  
  setupPyInstallFlags = ["--skip-xdg-cmd"];
  
  #
  # Exactly identical to buildPythonPackage's version but for the
  # `--old-and-unmanagable`, which I removed. This was removed because
  # this is a setuptools specific flag and as zim is overriding 
  # the install step, setuptools could not perform its monkey
  # patching trick for the command. Alternate solutions were to
  #
  #  -  Remove the custom install step (tested as working but
  #	also remove the possibility of performing the xdg-cmd
  #     stuff).
  #  -  Explicitly replace distutils import(s) by their setuptools
  #	equivalent (untested). 
  #
  # Both solutions were judged unsatisfactory as altering the code
  # would be required.
  #
  # Note that a improved solution would be to expose the use of 
  # the `--old-and-unmanagable` flag as an option of passed to the
  # buildPythonPackage function.
  #
  # Also note that I stripped all comments.
  #
  installPhase = ''
    runHook preInstall

    mkdir -p "$out/lib/${python.libPrefix}/site-packages"

    export PYTHONPATH="$out/lib/${python.libPrefix}/site-packages:$PYTHONPATH"

    ${python}/bin/${python.executable} setup.py install \
      --install-lib=$out/lib/${python.libPrefix}/site-packages \
      --prefix="$out" ${lib.concatStringsSep " " setupPyInstallFlags}

    eapth="$out/lib/${python.libPrefix}"/site-packages/easy-install.pth
    if [ -e "$eapth" ]; then
	# move colliding easy_install.pth to specifically named one
	mv "$eapth" $(dirname "$eapth")/${name}.pth
    fi

    rm -f "$out/lib/${python.libPrefix}"/site-packages/site.py*

    runHook postInstall
  '';

  # FIXME: this is quick and dirty hack, because zim expects the
  # path to the executable in argv[0] therefore the wrapper is
  # modified accordingly.
  postFixup = ''
    wrapPythonPrograms

    sed -i "s#sys\.argv\[0\] = 'zim'#sys.argv[0] = '$out/bin/zim'#g" \
      $out/bin/.zim-wrapped

    if test -e $out/nix-support/propagated-build-inputs; then
        ln -s $out/nix-support/propagated-build-inputs $out/nix-support/propagated-user-env-packages
    fi

    createBuildInputsPth build-inputs "$buildInputStrings"
    for inputsfile in propagated-build-inputs propagated-native-build-inputs; do
      if test -e $out/nix-support/$inputsfile; then
          createBuildInputsPth $inputsfile "$(cat $out/nix-support/$inputsfile)"
      fi
    done
  '';
  
  # Testing fails.
  doCheck = false;

  meta = {
      description = "A desktop wiki";
      homepage = http://zim-wiki.org;
      license = stdenv.lib.licenses.gpl2Plus;
  };
}