nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 zip,
6 copyDesktopItems,
7 libpng,
8 SDL2,
9 SDL2_image,
10
11 # Optionally bundle a ROM file
12 rom ? null,
13}:
14
15stdenv.mkDerivation (finalAttrs: {
16 pname = "tamatool";
17 version = "0.1";
18
19 src = fetchFromGitHub {
20 owner = "jcrona";
21 repo = "tamatool";
22 tag = "v${finalAttrs.version}";
23 hash = "sha256-VDmpIBuMWg3TwfCf9J6/bi/DaWip6ESAQWvGh2SH+A8=";
24 fetchSubmodules = true;
25 };
26
27 # * Point to the installed rom and res directory
28 # * Tell the user to use --rom instead of telling them to place the rom in the
29 # program directory (it's immutable!)
30 postPatch = ''
31 substituteInPlace src/tamatool.c \
32 --replace '#define RES_PATH' "#define RES_PATH \"$out/share/tamatool/res\" //" \
33 --replace '#define ROM_PATH' "#define ROM_PATH \"$out/share/tamatool/rom.bin\" //" \
34 --replace '#define ROM_NOT_FOUND_MSG' '#define ROM_NOT_FOUND_MSG "You need to use the --rom option!" //'
35 '';
36
37 nativeBuildInputs = [
38 zip
39 copyDesktopItems
40 ];
41
42 buildInputs = [
43 libpng
44 SDL2
45 SDL2_image
46 ];
47
48 makeFlags = [
49 "-Clinux"
50 "VERSION=${finalAttrs.version}"
51 "CFLAGS+=-I${lib.getInclude SDL2}/include/SDL2"
52 "CFLAGS+=-I${SDL2_image}/include/SDL2"
53 "DIST_PATH=$(out)"
54 "CC=${stdenv.cc.targetPrefix}cc"
55 ];
56
57 env = lib.optionalAttrs stdenv.hostPlatform.isDarwin {
58 NIX_LDFLAGS = "-framework CoreFoundation";
59 };
60
61 desktopItems = [ "linux/tamatool.desktop" ];
62
63 installPhase = ''
64 runHook preInstall
65 install -Dm755 linux/tamatool $out/bin/tamatool
66 mkdir -p $out/share/tamatool
67 cp -r res $out/share/tamatool/res
68 install -Dm644 linux/tamatool.png $out/share/icons/hicolor/128x126/apps/tamatool.png
69 ${lib.optionalString (rom != null) "install -Dm677 ${rom} $out/share/tamatool/rom.bin"}
70 runHook postInstall
71 '';
72
73 meta = {
74 description = "Cross-platform Tamagotchi P1 explorer";
75 homepage = "https://github.com/jcrona/tamatool";
76 license = lib.licenses.gpl2Only;
77 maintainers = with lib.maintainers; [ fgaz ];
78 platforms = lib.platforms.all;
79 mainProgram = "tamatool";
80 };
81})