Skip to content

Instantly share code, notes, and snippets.

@jjwatt
Last active February 24, 2024 12:38
Show Gist options
  • Save jjwatt/c83c02e6903c8ffaf546fe5eb27e7d25 to your computer and use it in GitHub Desktop.
Save jjwatt/c83c02e6903c8ffaf546fe5eb27e7d25 to your computer and use it in GitHub Desktop.
tic-80 building on nix
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
# inputsFrom = with pkgs; [ pkgconfig autoconf automake gnumake ];
buildInputs = with pkgs; [
gcc
pkgconfig
autoconf
automake
libtool
pcre
gnumake
SDL2
SDL2_gfx
SDL_image
SDL2_ttf
SDL2_mixer
harfbuzz
curl
gtk3
gtk3-x11
cmake
cmakeCurses
elementary-cmake-modules
extra-cmake-modules
libglvnd
mesa_glu
mesa_glu
freeglut
alsaLib
];
}
@jjwatt
Copy link
Author

jjwatt commented Jan 27, 2020

Use:
git clone --recursive https://github.com/nesbox/TIC-80.git
Put this into the TIC-80 dir, run nix-shell ./shell.nix
Then, cd build && cmake ..
Then, grab some coffee.
Come back, and make -j4
Then, run you some ./bin/tic80 from that dir.

@jjwatt
Copy link
Author

jjwatt commented Jan 27, 2020

Note: I probably don't need all those buildInputs because it looks like TIC-80's cmake builds a lot of them, but the resulting binary probably doesn't use the ones it builds. So, this isn't perfect yet. It's just getting it working for me. I'll do a proper package at some point that will probably need to hack up the TIC-80 build to be a good Nix citizen.
Edit: I just did this on my desktop, and it looks like maybe TIC-80 statically compiles, so it may actually use the ones in its tree. That probably explains why the binary works w/o me having to run patchelf on it, too. Usually, with Nix, if something is using shared libs it needs to be built with the Nix paths to shared libs (which are inside /nix/store and/or its own drv) or you have to hack the binary with patchelf to point to the shared libs instead of the FSHy /usr/lib/whatever that is often hardcoded in the ELF.
Edit #2: ohhh. It doesn't statically compile, so I was just getting lucky w/ defining all the right buildInputs and their closures happen to include the right stuff, and so my resulting binary is built the proper Nix way. That's probably good as it means it should be easier to get this into a proper Nix package.

@jjwatt
Copy link
Author

jjwatt commented Jan 27, 2020

Eh. I've got to add some updates to this based on building on my desktop where I use wayland, alsa, pulseaudio, etc. It did fine with these settings on my laptop under X, though. Having some issues with the sound right now on the desktop, and I'm not sure the root cause yet, so I don't want to post a bad shell.nix until I figure it out. My setup on my desktop is weird to say the least: coreboot/libreboot, sometimes IOMMU, sometimes not, pulseaudio, alsa and jack for ieee 1394 audio gear and sound cards. So, it could be related to any of the above :)

@Kozova1
Copy link

Kozova1 commented May 15, 2020

I've made an overlay for this, just create ~/.config/nixpkgs/overlays/tic80.nix and put this inside:

self: super:
let
  tic80-pkg = with import <nixpkgs> {}; stdenv.mkDerivation rec {
    name = "tic80";
    src = fetchgit {
      fetchSubmodules = true;
      url = "https://github.com/nesbox/TIC-80";
      rev = "0feb848378fc40d16aaa609ed7a2148d7a064ac4";
      sha256 = "12fl9wfc1577rmzcll50r3hq582010bpwd3yi15ji2vadc2q1w9l";
    };
    buildInputs = with pkgs; [
      gcc
      pkgconfig
      autoconf
      automake
      libtool
      pcre
      gnumake
      SDL2
      SDL2_gfx
      SDL_image
      SDL2_ttf
      SDL2_mixer
      harfbuzz
      curl
      gtk3
      gtk3-x11
      cmake
      cmakeCurses
      elementary-cmake-modules
      extra-cmake-modules
      libglvnd
      mesa_glu
      mesa_glu
      freeglut
      alsaLib
    ];

    configurePhase = ''
      echo [DIRECTORY] $(pwd)
      sed  -i 's/BUILD_PRO "Build PRO version" FALSE/BUILD_PRO "Build PRO version" TRUE/' CMakeLists.txt
      cd build/
      cmake ..
    '';

    buildPhase = ''
      make -j4
    '';

    installPhase = ''
      mkdir -p $out/bin
      chmod a+x bin/tic80
      cp -v bin/tic80 $out/bin
    '';

    tic80Item = makeDesktopItem {
      name = "TIC-80";
      exec = "tic80";
      comment = "Tiny Computer";
      categories = "Development;Game";
      desktopName = "TIC-80";
    };
  };
in {
  tic80 = tic80-pkg;
}

and then install tic80.

@Kozova1
Copy link

Kozova1 commented May 15, 2020

This automatically builds the pro version

@jjwatt
Copy link
Author

jjwatt commented May 15, 2020

Awesome! Thanks for sharing!

@Kozova1
Copy link

Kozova1 commented May 17, 2020

Also this won't update, you need once in a while to update rev to the latest commit and sha256 to the one provided by nix-prefetch-git --fetch-submodules $url (nix-prefetch-git is not provided by default; install it with the package nix-prefetch-git)

@kirca
Copy link

kirca commented Feb 5, 2023

This doesn't seem to work for v1.0. While the build finishes when running it the UI window doesn't open and it instead shows up in the terminal but it is not responsive. Issue nesbox/TIC-80#1922

@Serif-7
Copy link

Serif-7 commented Jan 25, 2024

I'm trying to build a native TIC-80 package myself. @jjwatt I tried the original shell.nix and it failed for me during the make -j4 step. I'm getting an 'Error 2' which I'm still trying to diagnose, very cryptic. I also tried nix-build with @winny- 's default.nix but that errored out as well. I'm an extreme Nix noob so any help with this is appreciated. I'm on 23.11

@Serif-7
Copy link

Serif-7 commented Jan 25, 2024

The precise error I got was

AR    build/host/lib/libmruby_core.a
ar: creating /home/daniel/src/misc/TIC-80/vendor/mruby/build/host/lib/libmruby_core.a
LD    build/host/bin/mrbc
/nix/store/1fn92b0783crypjcxvdv6ycmvi27by0j-binutils-2.40/bin/ld: /home/daniel/src/misc/TIC-80/vendor/mruby/build/host/lib/libmruby_core.a(codegen.o): undefined reference to symbol '__ctype_tolower_loc@@GLIBC_2.3'
/nix/store/1fn92b0783crypjcxvdv6ycmvi27by0j-binutils-2.40/bin/ld: /nix/store/qn3ggz5sf3hkjs2c797xf7nan3amdxmp-glibc-2.38-27/lib/libc.so.6: error adding symbols: DSO missing from command line
rake aborted!
Command failed with status (1): [ld  -o "/home/daniel/src/misc/TIC-80/vendo...]
/home/daniel/src/misc/TIC-80/vendor/mruby/lib/mruby/build/command.rb:37:in `_run'
/home/daniel/src/misc/TIC-80/vendor/mruby/lib/mruby/build/command.rb:217:in `run'
/home/daniel/src/misc/TIC-80/vendor/mruby/mrbgems/mruby-bin-mrbc/mrbgem.rake:11:in `block (2 levels) in <top (required)>'
Tasks: TOP => all => gensym => /home/daniel/src/misc/TIC-80/vendor/mruby/build/target/presym => /home/daniel/src/misc/TIC-80/vendor/mruby/build/target/mrblib/mrblib.pi => /home/daniel/src/misc/TIC-80/vendor/mruby/build/target/mrblib/mrblib.c => /home/daniel/src/misc/TIC-80/vendor/mruby/build/host/bin/mrbc
(See full trace by running task with --trace)
make[2]: *** [CMakeFiles/mruby_vendor.dir/build.make:86: mruby_vendor-prefix/src/mruby_vendor-stamp/mruby_vendor-build] Error 1
make[1]: *** [CMakeFiles/Makefile2:324: CMakeFiles/mruby_vendor.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

So I think it's linking to the wrong libc, going off the line /nix/store/1fn92b0783crypjcxvdv6ycmvi27by0j-binutils-2.40/bin/ld: /home/daniel/src/misc/TIC-80/vendor/mruby/build/host/lib/libmruby_core.a(codegen.o): undefined reference to symbol '__ctype_tolower_loc@@GLIBC_2.3'.

@winny-
Copy link

winny- commented Jan 26, 2024

Hi there, I just tested my linked TIC-80 derivation using nix-build -E 'with import <nixpkgs> {}; callPackage ./default.nix {}' and it completed successfully. Let's see if we can figure it out! I'm using 23.11 as well. Are you trying to build a local copy? Might be best to take one of the working derivations, then change the src to point to your path. This way it'll build the same way as if pulling from upstream.

@winny-
Copy link

winny- commented Jan 26, 2024

P.S. Feel free to take my work and contribute it to nixpkgs.

@blinry
Copy link

blinry commented Feb 24, 2024

Thanks for preparing the package, @winny-! I made a PR to nixpkgs here: NixOS/nixpkgs#291129

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment