Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NixOS Support #164

Open
wants to merge 3 commits into
base: slippi
Choose a base branch
from

Conversation

djanatyn
Copy link

NixOS isn't able to run the AppImages built from CI:

$ appimage-run Slippi_Online-x86_64.AppImage
Slippi_Online-x86_64.AppImage installed in /home/djanatyn/.cache/appimage-run/06490e83172589ae3b35f9fdc6d9951e6cadc700d30bf8415458566ef27234ad
./AppRun: error while loading shared libraries: libgmp.so.10: cannot open shared object file: No such file or directory

This PR provides a workaround, which can be used either from checking out the repository:

$ nix-build -A netplay                   
unpacking 'https://github.com/NixOS/nixpkgs-channels/archive/b8c367a7bd05e3a514c2b057c09223c74804a21b.tar.gz'...
warning: dumping very large path (> 256 MiB); this may run out of memory                             
these derivations will be built:                                                                                     
  /nix/store/kn81zijpwgbki47gvjbw8r1nwk4igk0c-slippi-ishiiruka-2.2.1-netplay.drv                   
these paths will be fetched (15.29 MiB download, 58.41 MiB unpacked):                        
  /nix/store/5ndchrs9mcvpvvcl9mjphdq5jsg5ynpl-ffmpeg-4.3.1-bin               
  /nix/store/6f0hq61lvysiv1gi92587pz5prchn2pa-wxwidgets-3.1.3                     
  /nix/store/6zzsgr439ngdaq487xv1p0ry0ryz0l9s-ffmpeg-4.3.1                      
  /nix/store/d1b7kg8z3jdv82j4bw1p2g6ijzwaa6gi-ffmpeg-4.3.1-dev                         
...
shrinking RPATHs of ELF executables and libraries in /nix/store/bv0aivrjr4y6l6yka1g4czbrfd44knxn-slippi-ishiiruka-2.2
.1-netplay                                                                                                           
shrinking /nix/store/bv0aivrjr4y6l6yka1g4czbrfd44knxn-slippi-ishiiruka-2.2.1-netplay/traversal_server                
shrinking /nix/store/bv0aivrjr4y6l6yka1g4czbrfd44knxn-slippi-ishiiruka-2.2.1-netplay/dolphin-emu                     
rewriting symlink /nix/store/bv0aivrjr4y6l6yka1g4czbrfd44knxn-slippi-ishiiruka-2.2.1-netplay/bin/slippi-netplay to be
 relative to /nix/store/bv0aivrjr4y6l6yka1g4czbrfd44knxn-slippi-ishiiruka-2.2.1-netplay                              
strip is /nix/store/h4v5qdxlmnh7xfpl7pwzrs8js7220bz2-binutils-2.31.1/bin/strip                                       
stripping (with command strip and flags -S) in /nix/store/bv0aivrjr4y6l6yka1g4czbrfd44knxn-slippi-ishiiruka-2.2.1-net
play/bin                                                                                                             
patching script interpreter paths in /nix/store/bv0aivrjr4y6l6yka1g4czbrfd44knxn-slippi-ishiiruka-2.2.1-netplay      
checking for references to /build/ in /nix/store/bv0aivrjr4y6l6yka1g4czbrfd44knxn-slippi-ishiiruka-2.2.1-netplay...  
/nix/store/bv0aivrjr4y6l6yka1g4czbrfd44knxn-slippi-ishiiruka-2.2.1-netplay   
$ ./result/dolphin-emu --help   
Usage: dolphin-emu [-h] [-d] [-l] [-e <str>] [-b] [-c <str>] [-v <str>] [-i <str>] [-a <str>] [-hs] [-m <str>] [-u <str>]
  -h, --help                    Show this help message
  -d, --debugger                Opens the debugger
  -l, --logger                  Opens the logger
  -e, --exec=<str>              Loads the specified file (ELF, DOL, GCM, ISO, TGC, WBFS, CISO, GCZ, WAD)
  -b, --batch                   Exit Dolphin with emulator
  -c, --confirm=<str>           Set Confirm on Stop
  -v, --video_backend=<str>     Specify a video backend
  -i, --slippi-input=<str>      Path to Slippi replay config file (default: Slippi/playback.txt)
  -a, --audio_emulation=<str>   Low level (LLE) or high level (HLE) audio
  -hs, --hide-seekbar           Hide seekbar during playback
  -m, --movie=<str>             Play a movie file
  -u, --user=<str>              User folder path

or from including a reference to a commit in a NixOS system configuration file:

let slippi = (import (builtins.fetchGit {
  url = "https://github.com/project-slippi/Ishiiruka";
  rev = "<commit-id>";
  ref = "<branch>";
})) { };
in {
  environment.systemPackages = [
    slippi.netplay
    slippi.playback
  ];
}

The upstream dependencies are vendored using niv, so every user running nix-build will download the same set of upstream dependency packages. There are instructions in USAGE.md for updating the vendored upstream dependencies.

Because NixOS packages are installed to read-only filesystems, you need to use a user config directory to persist any configuration changes:

$ mkdir ~/.slippi-config
$ slippi-netplay -u ~/.slippi-config

The user.json file should be installed in this config directory as well. This is not managed by the package.

I've been using and developing this derivation since the initial release of Slippi netplay. Thanks for creating something incredible!

@boogewooge
Copy link

boogewooge commented Dec 8, 2020

First of all, nice to see a fellow smasher+nixOS user! :)

edit: Nevermind, your suggestion does build, I messed up. Nevertheless, I'll leave my solution here for future reference. It uses the appimage and gives it its runtime dependencies through a nix-shell:

# default.nix
{ stdenv, fetchurl, makeDesktopItem, gmpxx, vulkan-loader }:

let

  desktopItem = makeDesktopItem {
    name = "slippi";
    exec = "slippi";
    icon = "";
    comment = "";
    desktopName = "Slippi";
    genericName = "Slippi Netplay";
    startupNotify = "false";
  };

in

stdenv.mkDerivation rec {

  pname = "slippi";
  version = "4.6";

  src = fetchurl {
    url = https://github.com/project-slippi/Ishiiruka/releases/download/v2.2.3/Slippi_Online-x86_64.AppImage;
    sha256 = "1jnkj78l8dfwkx8gxhlxnnli0hvgancxjb60fmgplgk6fpp9jxpg";
  };

  unpackPhase = ''
    mkdir -p $out
  '';

  installPhase = ''
    mkdir -p $out/bin
    cp $src $out/Slippi_Online-x86_64.AppImage
    chmod +x $out/Slippi_Online-x86_64.AppImage
    echo 'with import <nixpkgs> {}; 
    stdenv.mkDerivation { 
      name = "slippi"; 
      nativeBuildInputs = [ pkgconfig ]; 
      buildInputs = [ gmpxx curlpp vulkan-loader ]; 
      LD_LIBRARY_PATH = "${gmpxx.out}/lib:${vulkan-loader}/lib"; 
    }' > $out/shell.nix
    echo '#!/usr/bin/env bash 
    nix-shell '$out'/shell.nix --run "appimage-run '$out/Slippi_Online-x86_64.AppImage'"' > $out/bin/slippi
    chmod +x $out/bin/slippi
    mv * $out
    cp -r ${desktopItem}/* $out
  '';
}

I'm currently using this. It's a little hacky with the nix-shell and it's just the netplay client for now, but it's also got the user config set correctly. It puts slippi on the path.

I didn't want to add an extra PR for this, as it addresses the same problem. But since this is a working, simple solution, It might be worth including as an option.

@djanatyn
Copy link
Author

djanatyn commented Dec 8, 2020

Thanks @boogewooge!

Just for your information, I've started packaging SSBM utilities (gecko, gcmtool, slippi) and some newer versions of Slippi for NixOS under a separate project: https://github.com/djanatyn/ssbm-nix/blob/master/slippi/default.nix

This is an updated derivation for Slippi from 6 days ago when my build on nixos-unstable stopped working: https://github.com/djanatyn/ssbm-nix/blob/9ccbeb2543a19bc8be195b1ad3e7f3489489f1de/slippi/default.nix

There is a broken derivation for some unreleased chat code, which I think needs to integrate with: https://github.com/project-slippi/slippi-ssbm-asm

I haven't ported everything over yet, but I'm hoping to keep ssbm-nix updated. I had some separate goals as well, such as reproducible ISO builds with skin selections. There is a half-working Uncle Punch derivation in there as well.

@r-burns
Copy link

r-burns commented Dec 9, 2020

Btw, with bd7da42 you can do a nonportable install so you can use the ordinary .config path for user.json instead of specifying it manually. I've been using this for my local 2.2.3 slippi derivation and am able to play online.

I'm also working on a devkitPPC derivation based on pkgsCross.powerpc-embedded, so I'm definitely interested in reproducible asm codes. Would love to help out with Nix efforts, and hopefully we can get these upstreamed into nixpkgs so they're in the binary cache.

@r-burns
Copy link

r-burns commented Dec 9, 2020

Oh, and here's a simple AppImage wrapper:

{ stdenv
, appimage-run
, fetchurl
, gmp
, vulkan-loader
, writeScriptBin
}:
let
  src = fetchurl {
    url = "https://github.com/project-slippi/Ishiiruka/releases/download/v2.2.3/Slippi_Online-x86_64.AppImage";
    sha256 = "1jnkj78l8dfwkx8gxhlxnnli0hvgancxjb60fmgplgk6fpp9jxpg";
  };
in
  writeScriptBin "slippi-appimage" ''
    #!/usr/bin/env bash
    export LD_LIBRARY_PATH=${gmp}/lib:${vulkan-loader}/lib
    ${appimage-run}/bin/appimage-run ${src}
  ''

@boogewooge
Copy link

Thanks @boogewooge!

Just for your information, I've started packaging SSBM utilities (gecko, gcmtool, slippi) and some newer versions of Slippi for NixOS under a separate project: https://github.com/djanatyn/ssbm-nix/blob/master/slippi/default.nix

This is an updated derivation for Slippi from 6 days ago when my build on nixos-unstable stopped working: https://github.com/djanatyn/ssbm-nix/blob/9ccbeb2543a19bc8be195b1ad3e7f3489489f1de/slippi/default.nix

There is a broken derivation for some unreleased chat code, which I think needs to integrate with: https://github.com/project-slippi/slippi-ssbm-asm

I haven't ported everything over yet, but I'm hoping to keep ssbm-nix updated. I had some separate goals as well, such as reproducible ISO builds with skin selections. There is a half-working Uncle Punch derivation in there as well.

That's awesome! I'll definitely keep my eyes on this. You've got some cool plans there. I haven't heard of niv before. Maybe I should read up a bit, it seems useful?

Oh, and here's a simple AppImage wrapper:

{ stdenv
, appimage-run
, fetchurl
, gmp
, vulkan-loader
, writeScriptBin
}:
let
  src = fetchurl {
    url = "https://github.com/project-slippi/Ishiiruka/releases/download/v2.2.3/Slippi_Online-x86_64.AppImage";
    sha256 = "1jnkj78l8dfwkx8gxhlxnnli0hvgancxjb60fmgplgk6fpp9jxpg";
  };
in
  writeScriptBin "slippi-appimage" ''
    #!/usr/bin/env bash
    export LD_LIBRARY_PATH=${gmp}/lib:${vulkan-loader}/lib
    ${appimage-run}/bin/appimage-run ${src}
  ''

I didn't know about writeScriptBin, this seems like it could be a very elegant solution! This specific one fails however due to the appimage not being executable. I assume there's no way to get that chmod in there withouth resorting to mkDerivation again, huh?

@r-burns
Copy link

r-burns commented Dec 9, 2020

Hmm, works fine for me. The appimage itself doesn't need to be executable because it's loaded by appimage-run. What error are you getting?

@boogewooge
Copy link

boogewooge commented Dec 9, 2020

Hmm. I'm getting fatal: /nix/store/5jhfb6kms109n5cyqpc8abn3fpgl57rv-Slippi_Online-x86_64.AppImage is not executable.

Edit: Running /nix/store/5505isbian1xa8m12bnxs8hqrm4wm1mh-slippi-appimage/bin/slippi-appimage, that is.

@r-burns
Copy link

r-burns commented Dec 9, 2020

Maybe try pinning to the same nixpkgs as me? See if this will run:

with import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/40a7c98c1c56ff646cc03e938d980423483b2641.tar.gz") {};
callPackage ./slippi-appimage.nix {}

(where slippi-appimage.nix is the snippet I posted before)

Also, fetchurl takes an optional executable arg, so failing that you could modify the src to

  src = fetchurl {
    url = "https://github.com/project-slippi/Ishiiruka/releases/download/v2.2.3/Slippi_Online-x86_64.AppImage";
    sha256 = "14564slvqb6rr2y2vxn8h668bdxhmi6pci0ncibnj6fcdw9pqsay";
    executable = true;
  };

@ursi
Copy link

ursi commented Dec 24, 2020

Hello fellow nixers/smashers! Just though I'd share how I've been running it since the approach hasn't been shown yet.

{ appimageTools }:
  let
    version = "2.2.3";
  in
    appimageTools.wrapType2 {
      name = "slippi-online";
      extraPkgs = pkgs: [ pkgs.gmp ];

      src = builtins.fetchurl {
        url = "https://github.com/project-slippi/Ishiiruka/releases/download/v${version}/Slippi_Online-x86_64.AppImage";
        sha256 = "1jnkj78l8dfwkx8gxhlxnnli0hvgancxjb60fmgplgk6fpp9jxpg";
      };
    }

@blueOkiris
Copy link

blueOkiris commented Jun 24, 2023

I was able to get it working in 2023 for 23.05 by adding to environment.systemPackages:

(let
    app_name = "Slippi_Online-x86_64.AppImage";
    gh_proj = "Ishiiruka";
    gh_user = "project-slippi";
    version = "3.1.0";
    hash = "039qm941xbl97zvvv0q6480fps4w1a0n71sk1wiacs6n4gm2bs6f";
in pkgs.appimageTools.wrapType2 {
    name = "slippi-online";
    extraPkgs = pkgs: [
        pkgs.gmp
        pkgs.mpg123
        pkgs.libmpg123
    ];
    src = builtins.fetchurl {
        url =
            "https://github.com/${gh_user}/${gh_proj}/releases/download/"
                + "v${version}/${app_name}";
        sha256 = "${hash}";
    };
})

Based on the previous comment

I had an issue that appeared with the AppImage related to mpg123, so I added those two

@swagtoy
Copy link

swagtoy commented Oct 17, 2023

This PR seems a bit old and stale but I do want to shout out my #407 which actually adds an "install mode" for global installation (similar to just make install but separates the netplay and playback builds appropriately). Also a script is used to build it seen here, but I didn't bundle this script into Ishiiruka for now. I fondly remember having issues with Gentoo.

This allows for native installation but does not use the native launcher which it seems you want (?). Otherwise it's fine if you still want to play online, but you need the launcher or fixed-up appimage for replays

Obviously allows support for non-AppImage builds because I can't use AppImage either here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants