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

olympus: update version, src; add updateScript #1

Merged
merged 7 commits into from
Nov 23, 2024
6 changes: 6 additions & 0 deletions pkgs/by-name/ol/olympus-with-steam-run/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
steam-run,
callPackage,
}:

callPackage ../olympus/package.nix { celesteWrapper = steam-run; }
22 changes: 11 additions & 11 deletions pkgs/by-name/ol/olympus/deps.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

205 changes: 102 additions & 103 deletions pkgs/by-name/ol/olympus/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,163 +2,162 @@
lib,
fetchFromGitHub,
fetchzip,
buildFHSEnv,
buildDotnetModule,
mono4,
love,
lua51Packages,
msbuild,
luajitPackages,
sqlite,
curl,
libarchive,
buildFHSEnv,
curl,
mono,
love,
xdg-utils,
# Some examples for celesteWrapper:
# - null or "": Do not use wrapper.
# - steam-run: Use steam-run.
# - "steam-run": Use steam-run command available from PATH.
# - buildFHSEnv { ... }: Use a custom FHS env.
# - writeShellScriptBin { ... }: Use a custom script.
# - ./my-wrapper.sh: Use a custom script.
# In any case, it can be overridden at runtime by OLYMPUS_CELESTE_WRAPPER.
celesteWrapper ? null,
}:
# WONTFIX: On NixOS, cannot launch Steam installations of Everest / Celeste from Olympus.
# The way it launches Celeste is by directly executing steamapps/common/Celeste/Celeste,
# and it does not work on NixOS (even with steam-run).
# This should be considered a bug of Steam on NixOS (and is probably very hard to fix).
# https://github.com/EverestAPI/Olympus/issues/94 could be a temporary fix

# FIXME: olympus checks if xdg-mime x-scheme-handler/everest for a popup. If it's not set it complains about it.
# I'm pretty sure thats by user so end user needs to do it

let
lua-subprocess = lua51Packages.buildLuarocksPackage {
pname = "subprocess";
version = "bfa8e9";
src = fetchFromGitHub {
owner = "0x0ade"; # a developer of Everest
repo = "lua-subprocess";
rev = "bfa8e97da774141f301cfd1106dca53a30a4de54";
hash = "sha256-4LiYWB3PAQ/s33Yj/gwC+Ef1vGe5FedWexeCBVSDIV0=";
};
rockspecFilename = "subprocess-scm-1.rockspec";
};
lua_cpath =
with luajitPackages;
lib.concatMapStringsSep ";" getLuaCPath [
(buildLuarocksPackage {
pname = "subprocess";
version = "bfa8e9";
src = fetchFromGitHub {
owner = "0x0ade"; # a developer of Everest
repo = "lua-subprocess";
rev = "bfa8e97da774141f301cfd1106dca53a30a4de54";
hash = "sha256-4LiYWB3PAQ/s33Yj/gwC+Ef1vGe5FedWexeCBVSDIV0=";
};
rockspecFilename = "subprocess-scm-1.rockspec";
})

(buildLuarocksPackage {
pname = "lsqlite3";
version = "0.9.6-1";
src = fetchzip {
url = "http://lua.sqlite.org/index.cgi/zip/lsqlite3_v096.zip";
hash = "sha256-Mq409A3X9/OS7IPI/KlULR6ZihqnYKk/mS/W/2yrGBg=";
};
buildInputs = [ sqlite.dev ];
})

nfd
];

# NOTE: on installation olympus uses MiniInstallerLinux which is dynamically linked, this makes it run fine
fhs-env = buildFHSEnv {
name = "olympus-fhs";
# When installing Everest, Olympus uses MiniInstaller, which is dynamically linked.
miniinstaller-fhs = buildFHSEnv {
name = "olympus-miniinstaller-fhs";
targetPkgs =
pkgs:
(with pkgs; [
icu
stdenv.cc.cc
libgcc.lib
openssl
dotnet-runtime # Without this, MiniInstaller will install dotnet itself.
]);
runScript = "bash";
};
miniinstaller-wrapper = "${miniinstaller-fhs}/bin/${miniinstaller-fhs.name}";

lsqlite3 = lua51Packages.buildLuarocksPackage {
pname = "lsqlite3";
version = "0.9.6-1";
src = fetchzip {
url = "http://lua.sqlite.org/index.cgi/zip/lsqlite3_v096.zip";
hash = "sha256-Mq409A3X9/OS7IPI/KlULR6ZihqnYKk/mS/W/2yrGBg=";
};
buildInputs = [ sqlite.dev ];
};
celeste-wrapper =
if lib.isDerivation celesteWrapper then
lib.getExe celesteWrapper
else if celesteWrapper == null then
""
else
celesteWrapper;

dotnet-out = "sharp/bin/Release/net452";
pname = "olympus";
phome = "$out/lib/${pname}";
nfd = lua51Packages.nfd;
# The following variables are to be updated by the update script.
version = "24.11.23.01";
buildId = "4418"; # IMPORTANT: This line is matched with regex in update.sh.
rev = "d05f50fae23d741c9b6f72ba8fd951dca1a6e0f0";
in
buildDotnetModule rec {
inherit pname;

# FIXME: I made up this version number.
version = "24.07.06.02";
buildDotnetModule {
inherit pname version;

src = fetchFromGitHub {
inherit rev;
owner = "EverestAPI";
repo = "Olympus";
rev = "5f3e40687eb825c57021f52d83a3bc9a82c04bdb";
fetchSubmodules = true; # Required. See upstream's README.
hash = "sha256-rNh6sH51poahiV0Mb61lHfzqOkPF2pW2wr7MOrfVSVs=";
hash = "sha256-SjSdcYAO6Do+OkHPMut+V7VwqBBFIkeHl8gjDIwocc0=";
};

executables = [ ];

nativeBuildInputs = [
msbuild
libarchive # To create the .love file (zip format)
];

buildInputs = [
love
mono4
nfd
lua-subprocess
lsqlite3
];

runtimeInputs = [
xdg-utils
libarchive # To create the .love file (zip format).
];

nugetDeps = ./deps.nix;
projectFile = "sharp/Olympus.Sharp.csproj";
executables = [ ];

projectFile = "sharp/Olympus.Sharp.sln";

postConfigure = ''
echo '${version}-nixos' > src/version.txt
'';

# TODO: the override is needed for it to run. Should be found out why
# Copied from `olympus` in AUR.
buildPhase = ''
runHook preBuild
FrameworkPathOverride=${mono4.out}/lib/mono/4.5 msbuild ${projectFile} /p:Configuration=Release
runHook postBuild
# See the 'Dist: Update src/version.txt' step in azure-pipelines.yml from upstream.
preConfigure = ''
echo ${version}-nixos-${buildId}-${builtins.substring 0 5 rev} > src/version.txt
'';

# Hack Olympus.Sharp.bin.{x86,x86_64} to use system mono.
# This was proposed by @0x0ade on discord.gg/celeste:
# This was proposed by @0x0ade on discord.gg/celeste.
# https://discord.com/channels/403698615446536203/514006912115802113/827507533962149900
#
# I assume --fused is so saves are properly made (https://love2d.org/wiki/love.filesystem)
postBuild = ''
makeWrapper ${mono4.out}/bin/mono ${dotnet-out}/Olympus.Sharp.bin.x86 \
dotnet_out=sharp/bin/Release/net452
dotnet_out=$dotnet_out/$(ls $dotnet_out)
makeWrapper ${lib.getExe mono} $dotnet_out/Olympus.Sharp.bin.x86 \
--add-flags ${phome}/sharp/Olympus.Sharp.exe
cp ${dotnet-out}/Olympus.Sharp.bin.x86 ${dotnet-out}/Olympus.Sharp.bin.x86_64
cp $dotnet_out/Olympus.Sharp.bin.x86 $dotnet_out/Olympus.Sharp.bin.x86_64
'';

# The script find-love is hacked to use love from nixpkgs.
# It is used to launch Loenn from Olympus.
installPhase =
let
subprocess-cpath = "${lua-subprocess.out}/lib/lua/5.1/?.so";
nfd-cpath = "${nfd.out}/lib/lua/5.1/?.so";
lsqlite3-cpath = "${lsqlite3.out}/lib/lua/5.1/?.so";
in
''
runHook preInstall
mkdir -p $out/bin
makeWrapper ${love.out}/bin/love ${phome}/find-love \
--add-flags "--fused"
makeWrapper ${phome}/find-love $out/bin/olympus \
--prefix LUA_CPATH : "${nfd-cpath};${subprocess-cpath};${lsqlite3-cpath}" \
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ curl ]} \
--add-flags "${phome}/olympus.love"
mkdir -p ${phome}
bsdtar --format zip --strip-components 1 -cf ${phome}/olympus.love src
install -Dm755 ${dotnet-out}/* -t ${phome}/sharp
runHook postInstall
'';

# we need to force olympus to use the fhs-env
# I assume --fused is so saves are properly made (https://love2d.org/wiki/love.filesystem).
preInstall = ''
mkdir -p ${phome}
makeWrapper ${lib.getExe love} ${phome}/find-love \
--add-flags "--fused"
'';

installPhase = ''
runHook preInstall

mkdir -p $out/bin
makeWrapper ${phome}/find-love $out/bin/olympus \
--prefix LUA_CPATH ";" "${lua_cpath}" \
--prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath [ curl ]}" \
--suffix PATH : "${lib.makeBinPath [ xdg-utils ]}" \
--set-default OLYMPUS_MINIINSTALLER_WRAPPER "${miniinstaller-wrapper}" \
--set-default OLYMPUS_CELESTE_WRAPPER "${celeste-wrapper}" \
--add-flags ${phome}/olympus.love
bsdtar --format zip --strip-components 1 -cf ${phome}/olympus.love src

dotnet_out=sharp/bin/Release/net452
dotnet_out=$dotnet_out/$(ls $dotnet_out)
install -Dm755 $dotnet_out/* -t ${phome}/sharp

runHook postInstall
'';

postInstall = ''
sed -i 's|^exec|& ${fhs-env}/bin/olympus-fhs|' $out/bin/olympus
install -Dm644 lib-linux/olympus.desktop $out/share/applications/olympus.desktop
install -Dm644 src/data/icon.png $out/share/icons/hicolor/128x128/apps/olympus.png
install -Dm644 LICENSE $out/share/licenses/${pname}/LICENSE
'';

passthru.updateScript = ./update.sh;

meta = {
description = "Cross-platform GUI Everest installer and Celeste mod manager";
homepage = "https://github.com/EverestAPI/Olympus";
changelog = "https://github.com/EverestAPI/Olympus/blob/main/changelog.txt";
downloadPage = "https://everestapi.github.io/#olympus";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [
ulysseszhan
Expand Down
33 changes: 33 additions & 0 deletions pkgs/by-name/ol/olympus/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl jq common-updater-scripts nixfmt-rfc-style

set -eu -o pipefail

attr=olympus
nix_file=$(nix-instantiate --eval --strict -A "$attr.meta.position" | sed -re 's/^"(.*):[0-9]+"$/\1/')

api() {
curl -s "https://dev.azure.com/EverestAPI/Olympus/_apis/$1?api-version=7.1"
}

pipeline_id=$(api pipelines | jq -r '
.value
| map(select(.name == "EverestAPI.Olympus"))
| .[0].id
')

run_id=$(api pipelines/$pipeline_id/runs | jq -r '
.value
| map(select(.result == "succeeded"))
| max_by(.finishedDate)
| .id
')
sed -i 's|buildId\s*=\s*".*";|buildId = "'$run_id'";|' $nix_file

run=$(api pipelines/$pipeline_id/runs/$run_id)
commit=$(echo "$run" | jq -r '.resources.repositories.self.version')
version=$(echo "$run" | jq -r '.name')
update-source-version $attr $version --rev=$commit

"$(nix-build --attr $attr.fetch-deps --no-out-link)"
nixfmt $(dirname $nix_file)/deps.nix # NixOS/nixpkgs#358025
Loading