Creating a nix derivation for an AppImage

Hello, I want to package the game PokeWilds into a nix package. The release for this game is a zip file that contains the app image.

I can run the program just fine using appimage-run, but i really wanted to try packaging it.

This is the derivation i came up with:

 pkgs ? import <nixpkgs> {} }:

pkgs.stdenv.mkDerivation rec {
    pname = "PokeWilds";
    version = "0.8.10";

    src = pkgs.fetchurl {
        url = "https://github.com/SheerSt/pokewilds/releases/download/v${version}/pokewilds-linux64.zip";
        sha256 = "sha256-5/bMH+4XQC6zkF0EwXLjctS3u73AUAMzcNUAKhracRE=";
    };

    nativeBuildInputs = [ pkgs.unzip ];
    buildInputs = [ pkgs.unzip ];

    installPhase = ''
        mkdir -p $out/bin
        mv * $out/bin/

        mkdir -p $out/share/applications
        echo "[Desktop Entry]
Version=1.0
Icon=pokemon
Exec=$out/bin/PokeWilds-x64
Terminal=false
Type=Application
Categories=Game;
Name=PokeWilds
Comment=Openworld Pokemon game" > $out/share/application/PokeWilds.desktop
    '';

    #appimageTools.wrapType2 {
    #    name = "PokeWilds";
    #   src = fetchurl {
    #        url = "https://github.com/SheerSt/pokewilds/releases/download/v${version}/pokewilds-linux64.zip";
    #         sha256 = "sha256-5/bMH+4XQC6zkF0EwXLjctS3u73AUAMzcNUAKhracRE=";
    #};

    meta = with pkgs.lib; {
        homepage = "https://github.com/SheerSt/pokewilds";
        description = "A description of your application";
        platforms = platforms.linux;
    };
}

In this derivation i unzip the downloaded file, move the contens to the $out folder and create a .desktop file.

How can i proceed from here ?

Thank you for all the help.

1 Like

Hi :smiley: !

I see you tried to use appimageTools.wrapType2 but maybe gave up? almost there!
I don’t think you need stdenv.mkDerivation for this one.

The thing with appimageTools.wrapTypeX is that the src argument must be the AppImage itself, so the zip file (with an AppImage inside) will not work.

I think all you need here is:

  1. Extract the zip file, fetchzip can do that!
  2. Relative to the extracted zip file, find the AppImage file.
  3. Pass the AppImage to the wrap function.
let
  extracted-zip = fetchzip {
    src = "https://........";
    sha256 = ".........";
  }; # 1
  appimage-file = "${extracted-zip}/PokeWilds-x64"; # 2
in
appimageTools.wrapType2 {
  name = "PokeWilds";
  version = "0.8.10";
  src = appimage-file; # 3
  /* Desktop file and meta configuration go here */
};
2 Likes

First of all thank you @lelgenio for such a fast and amazing answer.

Second, how would i do the desktop file and meta configuration?, should i copy those parts i was trying before or is there an entirely different way that I’m not finding?
(should i create a new topic for these questions ?)

1 Like

Meta looks fine. If you plan on submitting to nixpkgs, then you will need to add the license and yourself as a maintainer.

If you add copyDesktopItems to nativeBuildInputs, desktop items can be constructed like this:

But really, the way you did it is actually more stable(?) since you are hard-coding the desktop item to point to $out, and some packages do it like you did:

2 Likes

Thank you so much!!!

1 Like