Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions pkgs/applications/misc/rtfm/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{ stdenv
, lib
, fetchFromGitHub
, crystal
, wrapGAppsHook4
, gobject-introspection
, desktopToDarwinBundle
, webkitgtk_6_0
, sqlite
, gi-crystal
, libadwaita
, gtk4
, pango
}:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}:
}:
let
gtk4' = gtk4.override { x11Support = true; };
in

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can fix that upstream.

# 3) added commands to build gschemas and update icon-cache
./patches/make.patch
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually distros run these command for any packages that install files on specific dirs used by these commands.


# 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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain this error? why does it happen? So I can fix it upstream too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It happens because rtfm copies docs from nix derivation, but all files in nix-store are read-only, so at first we need to add write permissions to the copied file. This error is nix-specific, but it cannot break rtfm on other distros i think.

];

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; {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add the platforms attribute with proper values? So we know on which architecture this software is available.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can i set platforms = [ "i686-linux" "x86_64-linux" ];; because i can't test on aarch64 and darwin?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just set the platforms the software you're trying to add supports, then the CI will test on these architectures.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set platforms.linux. Theoretically, it might run on darwin, maybe i'll setup OpenCore later on my PC.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you can ask to the Darwin maintainers team, they are quite reactive. Set it correctly and we'll ask them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. if I understand correctly how to do it

platforms = platforms.linux ++ platforms.darwin;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

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 ];
};
}
10 changes: 10 additions & 0 deletions pkgs/applications/misc/rtfm/patches/enable-write-permissions.patch
Original file line number Diff line number Diff line change
@@ -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

11 changes: 11 additions & 0 deletions pkgs/applications/misc/rtfm/patches/friendly-docs-path.patch
Original file line number Diff line number Diff line change
@@ -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)
30 changes: 30 additions & 0 deletions pkgs/applications/misc/rtfm/patches/make.patch
Original file line number Diff line number Diff line change
@@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you guys don't use the gi-crystal that the project depends on? Do you guys have a gi-crystal nix package? if so, why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I packed gi-crystal in nixpkgs when I packed the collision. You can see these PR's: #243914
#242681
There is an explanation why we decided to do it this way.

Shortly, nix collects crystal dependencies in separated derivations, then creates a symlimks on it in lib/ directory of project. I am creating a patch when packing gi-crystal to make it work with symlinks. The main problem is that all derivations in nix store are read-only and changes in one derivation will change drv hash and all hashes, that depend on it. When we run ./bin/gi-crystal it fails with error Permission denied, because it cannot write to read-only directory.

So, gi-crystal in nixpkgs works differently due to this nix features. All you need to do is add gi-crystal in build inputs, then run gi-crystal. It will scan lib/ directory with all symlinks, then generate all bindings in lib/gi-crystal directory and copy self package to this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shortly, nix collects crystal dependencies in separated derivations, then creates a symlimks on it in lib/ directory of project. I am creating a patch when packing gi-crystal to make it work with symlinks. The main problem is that all derivations in nix store are read-only and changes in one derivation will change drv hash and all hashes, that depend on it. When we run ./bin/gi-crystal it fails with error Permission denied, because it cannot write to read-only directory.

Jumping into the convo here... How about copying the gi-crystal derivation into the current rtfm directory and then use it ? That would fix both issues. You will be re-using the existing gi-cristal and it's directory is writable since you copied it into the rtfm build directory.

WDYT? Is it feasible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about copying the gi-crystal derivation into the current rtfm directory and then use it ?

This is exactly what I did when packing gi-crystal. But I actually automated this action so as not to do it constantly for different packages.

I think that's better, don't you?

https://github.com/NixOS/nixpkgs/pull/243914/files#diff-1a3ec3be7dadadd498d82613b7eaba4d02f11f8470913c5cbdb7d54932c63954R53

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is to copy the output of gi-crystal into rtfm and then use it.
Once the compilation is over, you delete it and only copy the relevant rtfm files in $out.

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is to copy the output of gi-crystal into rtfm and then use it.
Once the compilation is over, you delete it and only copy the relevant rtfm files in $out.

I'm sorry but I don't understand what's the difference. If we want to make it work without patching Makefile, then we need to do several steps:

mkdir lib/gi-crystal
cp -r ${gi-crystal}/* lib/gi-crystal
mkdir bin/
mv lib/gi-crystal/bin/gi-crystal bin/
chmod +w lib/gi-crystal/src/auto

I think it is just unnecessary steps to be done on each package requires gi-crystal.

And even if we do that, we still have to patch this to remove shards install command, because it will crash building due to cannot fetch remote host github.com something like this, I definitely don't remember what that error sounds like.

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the issue to do that all the time. I prefer that than patching the src.

But anyway, I was just passing by here thinking to provides new ideas, but I see that you already studied the question so I won't bother. I never used gi-crystal this is the reason why I might be wrong too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the issue to do that all the time. I prefer that than patching the src.

But anyway, I was just passing by here thinking to provides new ideas, but I see that you already studied the question so I won't bother. I never used gi-crystal this is the reason why I might be wrong too.

Thanks for suggesting solutions to this problem. Patching sources was the reason why I didn't want to pack gi-crystal. My best idea is to make gi-crystal portable, this fits well with the nix ideology, but changes program behaviour.

Speaking of using gi-crystal, I understand the steps involved in implementing your idea. But others may not realize that you need to copy the gi-crystal directory, mv gi-crystal binary and change the write permissions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok... sad but ok.

It's weird that it needs to write in the gi-crystal directory.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you guys are re-doing what shards already does, but at a package level. I mean... if derivations means a packaged code.


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/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this change upstream at hugopl/rtfm@8833114

# 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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't add this upstream or it will break ArchLinux package.


uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/rtfm
42 changes: 42 additions & 0 deletions pkgs/applications/misc/rtfm/shards.nix
Original file line number Diff line number Diff line change
@@ -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";
};
}
2 changes: 2 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34591,6 +34591,8 @@ with pkgs;
rsync = callPackage ../applications/networking/sync/rsync (config.rsync or {});
rrsync = callPackage ../applications/networking/sync/rsync/rrsync.nix { };

rtfm = callPackage ../applications/misc/rtfm { };

rtl_433 = callPackage ../applications/radio/rtl_433 { };

rtl-ais = callPackage ../applications/radio/rtl-ais { };
Expand Down