1{
2 lib,
3 stdenv,
4 fetchurl,
5 desktop-file-utils,
6 gtk3,
7 libX11,
8 cmake,
9 imagemagick,
10 pkg-config,
11 perl,
12 wrapGAppsHook3,
13 nixosTests,
14 writeScript,
15 halibut,
16 isMobile ? false,
17}:
18
19stdenv.mkDerivation rec {
20 pname = "sgt-puzzles";
21 version = "20250722.dbe6378";
22
23 src = fetchurl {
24 url = "http://www.chiark.greenend.org.uk/~sgtatham/puzzles/puzzles-${version}.tar.gz";
25 hash = "sha256-ayNBRAAIForVZgHQJ1fr3m1aZ3bG9YNQxHTeO0YcwTA=";
26 };
27
28 sgt-puzzles-menu = fetchurl {
29 url = "https://raw.githubusercontent.com/gentoo/gentoo/720e614d0107e86fc1e520bac17726578186843d/games-puzzle/sgt-puzzles/files/sgt-puzzles.menu";
30 sha256 = "088w0x9g3j8pn725ix8ny8knhdsfgjr3hpswsh9fvfkz5vlg2xkm";
31 };
32
33 nativeBuildInputs = [
34 cmake
35 desktop-file-utils
36 imagemagick
37 perl
38 pkg-config
39 wrapGAppsHook3
40 halibut # For help pages
41 ];
42
43 env.NIX_CFLAGS_COMPILE = lib.optionalString isMobile "-DSTYLUS_BASED";
44
45 buildInputs = [
46 gtk3
47 libX11
48 ];
49
50 postInstall = ''
51 for i in $(basename -s $out/bin/*); do
52
53 ln -s $out/bin/$i $out/bin/sgt-puzzle-$i
54 install -Dm644 icons/$i-96d24.png -t $out/share/icons/hicolor/96x96/apps/
55
56 # Generate/validate/install .desktop files.
57 echo "[Desktop Entry]" > $i.desktop
58 desktop-file-install --dir $out/share/applications \
59 --set-key Type --set-value Application \
60 --set-key Exec --set-value $i \
61 --set-key Name --set-value $i \
62 --set-key Comment --set-value "${meta.description}" \
63 --set-key Categories --set-value "Game;LogicGame;X-sgt-puzzles;" \
64 --set-key Icon --set-value $out/share/icons/hicolor/96x96/apps/$i-96d24.png \
65 $i.desktop
66 done
67
68 echo "[Desktop Entry]" > sgt-puzzles.directory
69 desktop-file-install --dir $out/share/desktop-directories \
70 --set-key Type --set-value Directory \
71 --set-key Name --set-value Puzzles \
72 --set-key Icon --set-value $out/share/icons/hicolor/48x48/apps/sgt-puzzles_map \
73 sgt-puzzles.directory
74
75 install -Dm644 ${sgt-puzzles-menu} -t $out/etc/xdg/menus/applications-merged/
76 '';
77
78 passthru = {
79 tests.sgt-puzzles = nixosTests.sgt-puzzles;
80 updateScript = writeScript "update-sgt-puzzles" ''
81 #!/usr/bin/env nix-shell
82 #!nix-shell -i bash -p curl pcre common-updater-scripts
83
84 set -eu -o pipefail
85
86 version="$(curl -sI 'https://www.chiark.greenend.org.uk/~sgtatham/puzzles/puzzles.tar.gz' | grep -Fi Location: | pcregrep -o1 'puzzles-([0-9a-f.]*).tar.gz')"
87 update-source-version sgt-puzzles "$version"
88 '';
89 };
90
91 meta = with lib; {
92 description = "Simon Tatham's portable puzzle collection";
93 license = licenses.mit;
94 maintainers = with maintainers; [
95 raskin
96 tomfitzhenry
97 ];
98 platforms = platforms.linux;
99 homepage = "https://www.chiark.greenend.org.uk/~sgtatham/puzzles/";
100 };
101}