about summary refs log tree commit diff
path: root/pkgs/applications/misc/rtfm
diff options
context:
space:
mode:
authorsunder <evenquantity@gmail.com>2023-07-25 21:05:24 +0300
committersunder <evenquantity@gmail.com>2023-07-25 21:05:24 +0300
commitb90555efe6e509b5e0589a8d50716916e34a1afd (patch)
tree1e430be8faad48aa7ea9d1d28e0e6576ed3691c2 /pkgs/applications/misc/rtfm
parent8613c713110a1e4ecc3265c0557a0db5e08d9b27 (diff)
rtfm: init at 0.2.2
Diffstat (limited to 'pkgs/applications/misc/rtfm')
-rw-r--r--pkgs/applications/misc/rtfm/default.nix91
-rw-r--r--pkgs/applications/misc/rtfm/patches/enable-write-permissions.patch10
-rw-r--r--pkgs/applications/misc/rtfm/patches/friendly-docs-path.patch11
-rw-r--r--pkgs/applications/misc/rtfm/patches/make.patch30
-rw-r--r--pkgs/applications/misc/rtfm/shards.nix42
5 files changed, 184 insertions, 0 deletions
diff --git a/pkgs/applications/misc/rtfm/default.nix b/pkgs/applications/misc/rtfm/default.nix
new file mode 100644
index 0000000000000..99f9a465e13de
--- /dev/null
+++ b/pkgs/applications/misc/rtfm/default.nix
@@ -0,0 +1,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.2";
+
+  src = fetchFromGitHub {
+    owner = "hugopl";
+    repo = "rtfm";
+    rev = "v${version}";
+    name = "rtfm";
+    hash = "sha256-SmQq3hG94oV346dHtqTHC0xE4cWB3rspD3XXu+mSI8Q=";
+  };
+
+  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 ];
+  };
+}
diff --git a/pkgs/applications/misc/rtfm/patches/enable-write-permissions.patch b/pkgs/applications/misc/rtfm/patches/enable-write-permissions.patch
new file mode 100644
index 0000000000000..efdabce083519
--- /dev/null
+++ b/pkgs/applications/misc/rtfm/patches/enable-write-permissions.patch
@@ -0,0 +1,10 @@
+--- a/src/doc2dash/doc_set_builder.cr	2023-07-19 14:00:06.864770147 +0300
++++ b/src/doc2dash/doc_set_builder.cr	2023-07-19 13:59:35.440707740 +0300
+@@ -44,6 +44,7 @@
+       real_dest = @html_dest.join(dest || source)
+       Dir.mkdir_p(Path.new(real_dest).dirname)
+       File.copy(original, real_dest)
++      File.chmod(real_dest, 0o600)
+       dest || source
+     end
+ 
diff --git a/pkgs/applications/misc/rtfm/patches/friendly-docs-path.patch b/pkgs/applications/misc/rtfm/patches/friendly-docs-path.patch
new file mode 100644
index 0000000000000..cecbeb750b300
--- /dev/null
+++ b/pkgs/applications/misc/rtfm/patches/friendly-docs-path.patch
@@ -0,0 +1,11 @@
+--- a/src/create_gtk_docset.cr	2023-07-17 14:28:04.882620660 +0300
++++ b/src/create_gtk_docset.cr	2023-07-17 14:27:09.660643747 +0300
+@@ -136,7 +136,7 @@
+ end
+ 
+ def find_modules : Array(Path)
+-  basedir = Path.new("/usr/share/doc")
++  basedir = Path.new(ARGV[0]? || "gtk-docs")
+   MODULES.compact_map do |mod|
+     print "#{mod.ljust(20, '.')}"
+     mod_dir = basedir.join(mod)
diff --git a/pkgs/applications/misc/rtfm/patches/make.patch b/pkgs/applications/misc/rtfm/patches/make.patch
new file mode 100644
index 0000000000000..503faf5245beb
--- /dev/null
+++ b/pkgs/applications/misc/rtfm/patches/make.patch
@@ -0,0 +1,30 @@
+--- a/Makefile	2023-07-17 17:18:28.000000000 +0300
++++ b/Makefile	2023-07-19 12:13:44.627168135 +0300
+@@ -4,8 +4,7 @@
+ all: configure .WAIT rtfm docsets
+ 
+ configure:
+-	shards install
+-	./bin/gi-crystal
++	gi-crystal
+ 
+ rtfm:
+ 	shards build --release -s rtfm
+@@ -29,13 +28,15 @@
+ 	install -D -m644 data/io.github.hugopl.rtfm.gschema.xml $(DESTDIR)$(PREFIX)/share/glib-2.0/schemas/io.github.hugopl.rtfm.gschema.xml
+ 	# docsets
+ 	mkdir -p $(DESTDIR)$(PREFIX)/share/rtfm/docsets/
+-	cp -rv data/Crystal.docset $(DESTDIR)$(PREFIX)/share/rtfm/docsets/
+-	cp -rv data/Gtk4.docset $(DESTDIR)$(PREFIX)/share/rtfm/docsets/
++	cp -r data/Crystal.docset $(DESTDIR)$(PREFIX)/share/rtfm/docsets/
++	cp -r data/Gtk4.docset $(DESTDIR)$(PREFIX)/share/rtfm/docsets/
+ 	# License
+ 	install -D -m0644 LICENSE $(DESTDIR)$(PREFIX)/share/licenses/rtfm/LICENSE
+ 	# Changelog
+ 	install -D -m0644 CHANGELOG.md $(DESTDIR)$(PREFIX)/share/doc/rtfm/CHANGELOG.md
+ 	gzip -9fn $(DESTDIR)$(PREFIX)/share/doc/rtfm/CHANGELOG.md
++	gtk4-update-icon-cache --ignore-theme-index $(PREFIX)/share/icons/hicolor
++	glib-compile-schemas $(DESTDIR)$(PREFIX)/share/glib-2.0/schemas
+ 
+ uninstall:
+ 	rm -f $(DESTDIR)$(PREFIX)/bin/rtfm
\ No newline at end of file
diff --git a/pkgs/applications/misc/rtfm/shards.nix b/pkgs/applications/misc/rtfm/shards.nix
new file mode 100644
index 0000000000000..f6882397d83f1
--- /dev/null
+++ b/pkgs/applications/misc/rtfm/shards.nix
@@ -0,0 +1,42 @@
+{
+  db = {
+    url = "https://github.com/crystal-lang/crystal-db.git";
+    rev = "v0.12.0";
+    sha256 = "1in8w2dz7nlhqgc9l6b3pi6f944m29nhbg3p5j40qzvsrr8lqaj7";
+  };
+  fzy = {
+    url = "https://github.com/hugopl/fzy.git";
+    rev = "v0.5.5";
+    sha256 = "1zk95m43ymx9ilwr6iw9l44nkmp4sas28ib0dkr07hkhgrkw68sv";
+  };
+  gio = {
+    url = "https://github.com/hugopl/gio.cr.git";
+    rev = "v0.1.0";
+    sha256 = "0vj35bi64d4hni18nrl8fmms306a0gl4zlxpf3aq08lh0sbwzhd8";
+  };
+  gtk4 = {
+    url = "https://github.com/hugopl/gtk4.cr.git";
+    rev = "v0.15.0";
+    sha256 = "100j5k4sfc2dpj3nplzjcaxw1bwy3hsy5cw93asg00kda9h8dbb1";
+  };
+  harfbuzz = {
+    url = "https://github.com/hugopl/harfbuzz.cr.git";
+    rev = "v0.2.0";
+    sha256 = "06wgqxwyib5416yp53j2iwcbr3bl4jjxb1flm7z103l365par694";
+  };
+  libadwaita = {
+    url = "https://github.com/geopjr/libadwaita.cr.git";
+    rev = "23ce21d6400af7563ede0b53deea6d1f77436985";
+    sha256 = "09jz6r0yp4qsm47qcknzgkjxavr5j3dkxf2yjbw0jkaz1an58pfw";
+  };
+  pango = {
+    url = "https://github.com/hugopl/pango.cr.git";
+    rev = "v0.2.0";
+    sha256 = "0dl3qrhi2ybylmvzx1x5gsznp2pcdkc50waxrljxwnf5avn8ixsf";
+  };
+  sqlite3 = {
+    url = "https://github.com/crystal-lang/crystal-sqlite3.git";
+    rev = "v0.20.0";
+    sha256 = "0mqy6rc26i0sf2fdllbbzdhbd1d35npmpqqjz0b1n1vrzrm6fg05";
+  };
+}