Hi all,
I’m struggling to install SMAPI from source which is a modding API for a game called Stardew Valley using NixOS and Home manager.
The source is a zip file from Release 4.2.1 · Pathoschild/SMAPI · GitHub.
I’m trying to install it using the manual installation steps as I assume that allows the installation to be more declarative compared to running an script? After looking around, it seems like I need to make a derivation which is what I attempted but I don’t quite understand how to move the files from the unzipped Github release to the location of the game in my user’s directory.
According to the README of SMAPI, I need to reproduce the following steps using Nix and Home Manager:
-
Unzip “internal/unix/install.dat”. You can change ‘.dat’ to ‘.zip’, it’s just a normal zip file renamed to prevent
confusion. -
Copy the files from the folder you just unzipped into your game folder. The
StardewModdingAPI.exe
file should be right next to the game’s executable. -
Copy
Stardew Valley.deps.json
in the game folder, and rename the copy to
StardewModdingAPI.deps.json
. -
rename the “StardewValley” file (no extension) to “StardewValley-original”, and
“StardewModdingAPI” (no extension) to “StardewValley”. Now just launch the game as usual to
play with mods.
So far, I’ve got this in my configuration:
# smapi.nix
{ pkgs, stdenv }:
stdenv.mkDerivation rec {
pname = "SMAPI";
version = "4.2.1";
src = pkgs.fetchzip {
url = "https://github.com/Pathoschild/${pname}/releases/download/${version}/${pname}-${version}-installer.zip";
hash = "sha256-8fIwAZI9obCUfQcrGuNlq84st7iIQ/8Hfrgkeqsk/3c=";
};
nativeBuildInputs = with pkgs; [ unzip ];
unpackPhase = ''
runHook preUnpack
mkdir -p $out/bin
cp -r ${src}/* $out/
${pkgs.unzip}/bin/unzip -o ${src}/internal/linux/install.dat -d $out
runHook postUnpack
'';
installPhase =
let
gamePath = "~/.local/share/Steam/steamapps/common/Stardew\\ Valley/";
in
''
runHook preInstall
cp -a $out/. ${gamePath}
cp ${gamePath}/Stardew\\ Valley.deps.json ${gamePath}/StardewModdingAPI.deps.json
mv ${gamePath}/StardewValley ${gamePath}/StardewValley-original
mv ${gamePath}/StardewModdingAPI ${gamePath}/StardewValley
runHook postInstall
'';
}
Obviously this is wrong but I’m not sure how to progress after step 1. I also don’t know how to use the derivation to actually “install” SMAPI.
Any help is appreciated