about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/misc/rtfm/default.nix
blob: e965c6810af5655082da63c8a4842a20b57c62c2 (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
{ stdenv
, lib
, fetchFromGitHub
, crystal
, wrapGAppsHook4
, gobject-introspection
, desktopToDarwinBundle
, webkitgtk_6_0
, sqlite
, gi-crystal
, libadwaita
, gtk4
, pango
}:
let
  gtk4' = gtk4.override { x11Support = true; };
  pango' = pango.override { withIntrospection = true; };
in
crystal.buildCrystalPackage rec {
  pname = "rtfm";
  version = "0.2.3";

  src = fetchFromGitHub {
    owner = "hugopl";
    repo = "rtfm";
    rev = "v${version}";
    name = "rtfm";
    hash = "sha256-ulv5US5EBBb0rK/Qaw8ZpHI4QwEQGlzscmAoe17946k=";
  };

  patches = [
    # 1) fixed gi-crystal binding generator command
    # 2) removed `-v` arg to `cp` command to prevent build failure due to stdout buffer overflow
    # 3) added commands to build gschemas and update icon-cache
    ./patches/make.patch

    # fixed docset path and gi libs directory names
    ./patches/friendly-docs-path.patch

    # added chmod +w for copied docs to prevent error:
    # `Error opening file with mode 'wb': '.../style.css': Permission denied`
    ./patches/enable-write-permissions.patch
  ];

  postPatch = ''
    substituteInPlace Makefile \
      --replace "crystal run src/create_crystal_docset.cr" "crystal src/create_crystal_docset.cr ${crystal}/share/doc/crystal/api/" \
      --replace "crystal run src/create_gtk_docset.cr" "crystal src/create_gtk_docset.cr gtk-doc/"
  '';

  shardsFile = ./shards.nix;

  nativeBuildInputs = [
    wrapGAppsHook4
    gobject-introspection
    gi-crystal
  ] ++ lib.optionals stdenv.isDarwin [ desktopToDarwinBundle ];

  buildInputs = [
    webkitgtk_6_0
    sqlite
    libadwaita
    gtk4'
    pango'
  ];

  buildTargets = [ "configure" "rtfm" "docsets" ];

  preBuild = ''
    mkdir gtk-doc/

    for file in "${gtk4'.devdoc}"/share/doc/*; do
      ln -s "$file" "gtk-doc/$(basename "$file")"
    done

    for file in "${pango'.devdoc}"/share/doc/*; do
      ln -s "$file" "gtk-doc/$(basename "$file")"
    done

    for file in "${libadwaita.devdoc}"/share/doc/*; do
      ln -s "$file" "gtk-doc/$(basename "$file")"
    done
  '';

  meta = with lib; {
    description = "Dash/docset reader with built in documentation for Crystal and GTK APIs";
    homepage = "https://github.com/hugopl/rtfm/";
    license = licenses.mit;
    maintainers = with maintainers; [ sund3RRR ];
  };
}