nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchurl,
5 makeWrapper,
6 fetchFromGitHub,
7 dpkg,
8 glib,
9 gnutar,
10 gtk3-x11,
11 luajit,
12 sdcv,
13 SDL2,
14 openssl,
15 writeScript,
16}:
17let
18 luajit_lua52 = luajit.override { enable52Compat = true; };
19
20 version = "2025.10";
21
22 src_repo = fetchFromGitHub {
23 repo = "koreader";
24 owner = "koreader";
25 tag = "v${version}";
26 fetchSubmodules = true;
27 hash = "sha256-uYKN5fgIdCVH+pXU2lmsGu7HxZbDld5EJVO9o7Tk8BA=";
28 };
29in
30stdenv.mkDerivation {
31 pname = "koreader";
32 inherit version;
33
34 src =
35 let
36 selectSystem =
37 attrs:
38 attrs.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
39 arch = selectSystem {
40 aarch64-linux = "arm64";
41 armv7l-linux = "armhf";
42 x86_64-linux = "amd64";
43 };
44 in
45 fetchurl {
46 url = "https://github.com/koreader/koreader/releases/download/v${version}/koreader-${version}-${arch}.deb";
47 hash = selectSystem {
48 aarch64-linux = "sha256-z92sguFe5qcPmHk+Orm8vHJycVeZY3cYGByU6xIcrkA=";
49 armv7l-linux = "sha256-kVO+eUwGMULJZwbxZwbeooqRDF8oZPiuo47a7lNsl3I=";
50 x86_64-linux = "sha256-OYzMOUFzUzkYvcjjMX0FZBkZs//9ie3025lhhFOrt9M=";
51 };
52 };
53
54 nativeBuildInputs = [
55 makeWrapper
56 dpkg
57 ];
58 buildInputs = [
59 glib
60 gnutar
61 gtk3-x11
62 luajit_lua52
63 sdcv
64 SDL2
65 openssl
66 ];
67
68 installPhase = ''
69 runHook preInstall
70
71 cp --recursive usr $out
72 ''
73 # Link required binaries
74 + ''
75 ln -sf ${luajit_lua52}/bin/luajit $out/lib/koreader/luajit
76 ln -sf ${sdcv}/bin/sdcv $out/lib/koreader/sdcv
77 ln -sf ${gnutar}/bin/tar $out/lib/koreader/tar
78 ''
79 # Link SSL/network libraries
80 + ''
81 ln -sf ${openssl.out}/lib/libcrypto.so.3 $out/lib/koreader/libs/libcrypto.so.1.1
82 ln -sf ${openssl.out}/lib/libssl.so.3 $out/lib/koreader/libs/libssl.so.1.1
83 ''
84 # Copy fonts
85 + ''
86 find ${src_repo}/resources/fonts -type d -execdir cp -r '{}' $out/lib/koreader/fonts \;
87 ''
88 # Remove broken symlinks
89 + ''
90 find $out -xtype l -print -delete
91 ''
92 + ''
93 wrapProgram $out/bin/koreader --prefix LD_LIBRARY_PATH : $out/lib/koreader/libs:${
94 lib.makeLibraryPath [
95 gtk3-x11
96 SDL2
97 glib
98 stdenv.cc.cc
99 openssl.out
100 ]
101 }
102
103 runHook postInstall
104 '';
105
106 passthru = {
107 inherit src_repo;
108 updateScript = writeScript "update-koreader" ''
109 #!/usr/bin/env nix-shell
110 #!nix-shell -i bash -p nix curl jq nix-update common-updater-scripts
111 set -eou pipefail
112 version=$(nix eval --raw --file . koreader.version)
113 nix-update koreader
114 latestVersion=$(nix eval --raw --file . koreader.version)
115 if [[ "$latestVersion" == "$version" ]]; then
116 exit 0
117 fi
118 update-source-version koreader $latestVersion --source-key=src_repo --ignore-same-version
119 systems=$(nix eval --json -f . koreader.meta.platforms | jq --raw-output '.[]')
120 for system in $systems; do
121 hash=$(nix --extra-experimental-features nix-command hash convert --to sri --hash-algo sha256 $(nix-prefetch-url $(nix eval --raw -f . koreader.src.url --system "$system")))
122 update-source-version koreader $latestVersion $hash --system=$system --ignore-same-version --ignore-same-hash
123 done
124 '';
125 };
126
127 meta = {
128 homepage = "https://github.com/koreader/koreader";
129 changelog = "https://github.com/koreader/koreader/releases/tag/v${version}";
130 description = "Ebook reader application supporting PDF, DjVu, EPUB, FB2 and many more formats, running on Cervantes, Kindle, Kobo, PocketBook and Android devices";
131 mainProgram = "koreader";
132 sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
133 platforms = [
134 "aarch64-linux"
135 "armv7l-linux"
136 "x86_64-linux"
137 ];
138 license = lib.licenses.agpl3Only;
139 maintainers = with lib.maintainers; [
140 contrun
141 liberodark
142 ];
143 };
144}