Skip to content

Commit

Permalink
fetchTorGit: init; add a package as fetchTorGit example
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroHLC committed Oct 13, 2024
1 parent 96e971d commit ec6b449
Show file tree
Hide file tree
Showing 4 changed files with 252 additions and 0 deletions.
7 changes: 7 additions & 0 deletions overlays/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ in

extra-cmake-modules_git = callOverride ../pkgs/extra-cmake-modules-git/latest.nix { };

fetchTorGit = callOverride ../pkgs/fetchtorgit { };

firedragon-unwrapped = final.callPackage ../pkgs/firedragon { };

firedragon = final.wrapFirefox final.firedragon-unwrapped {
Expand Down Expand Up @@ -271,6 +273,11 @@ in
telegram-desktop_git = callOverride ../pkgs/telegram-desktop-git { };
tg-owt_git = callOverride ../pkgs/tg-owt-git { };

torzu_git = final.kdePackages.callPackage ../pkgs/torzu-git {
current = importJSON ../pkgs/torzu-git/version.json;
inherit (final) fetchTorGit;
};

vulkanPackages_latest = callOverride ../pkgs/vulkan-versioned
{ vulkanVersions = importJSON ../pkgs/vulkan-versioned/latest.json; };

Expand Down
30 changes: 30 additions & 0 deletions pkgs/fetchtorgit/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{ final, prev, ... }:
prev.fetchgit.override {
git = with final; writeShellScriptBin "git" ''
set -eu
_TOR_PORT=$(($(($$ % 64511)) + 1024))
_TOR_LOG=/build/tor.log
${tor}/bin/tor --SocksPort $_TOR_PORT 2>&1 >"$_TOR_LOG" &
_TOR_PID=$!
echo "Waiting bootstrap"
_START_TIME=$(date +%s)
_TIMEOUT_TIME=$(($_START_TIME + 60))
while true; do
grep -q 'Bootstrapped 100% (done): Done' "$_TOR_LOG" && break
if [ "$(date +%s)" -ge "$_TIMEOUT_TIME" ]; then
echo "Bootstrap took too long."
exit 69
fi
sleep 2
done
echo "Bootstrap done"
_GIT_STATUS=0
'${git}/bin/git' -c http.proxy=socks5h://127.0.0.1:$_TOR_PORT "$@" || _GIT_STATUS=$?
kill $_TOR_PID || true
exit ''$_GIT_STATUS
'';
}
201 changes: 201 additions & 0 deletions pkgs/torzu-git/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
{ current

, lib
, stdenv
, wrapQtAppsHook
, alsa-lib
, boost
, catch2_3
, cmake
, cpp-jwt
, cubeb
, discord-rpc
, doxygen
, enet
, fetchTorGit
, fetchurl
, fetchzip
, ffmpeg
, fmt
, glslang
, httplib
, inih
, libjack2
, libopus
, libpulseaudio
, libusb1
, libva
, libzip
, lz4
, nlohmann_json
, perl
, pkg-config
, python3
, qtbase
, qtmultimedia
, qttools
, qtwayland
, qtwebengine
, rapidjson
, SDL2
, sndio
, speexdsp
, udev
, vulkan-loader
, zlib
, zstd
}:

let
compat-list = with current.compatList; fetchurl {
name = "yuzu-compat-list";
url = "https://raw.githubusercontent.com/flathub/org.yuzu_emu.yuzu/${rev}/compatibility_list.json";
inherit hash;
};
branch = "early-access";

tzinfo = with current.tzinfo; fetchzip {
url = "https://github.com/lat9nq/tzdb_to_nx/releases/download/${version}/${version}.zip";
stripRoot = false;
inherit hash;
};
in
stdenv.mkDerivation {
pname = "torzu";

inherit (current) version;

src = fetchTorGit {
url = "http://vub63vv26q6v27xzv2dtcd25xumubshogm67yrpaz2rculqxs7jlfqad.onion/torzu-emu/torzu.git";
fetchSubmodules = true;
inherit (current) rev hash;
};

nativeBuildInputs = [
cmake
doxygen
perl
pkg-config
python3
wrapQtAppsHook
];

buildInputs = [
alsa-lib
boost
catch2_3
cpp-jwt
cubeb
discord-rpc
# intentionally omitted: dynarmic - prefer vendored version for compatibility
enet
ffmpeg
fmt
glslang
httplib
inih
libjack2
libopus
libpulseaudio
libusb1
libva
libzip
# intentionally omitted: LLVM - heavy, only used for stack traces in the debugger
lz4
nlohmann_json
qtbase
qtmultimedia
qttools
qtwayland
qtwebengine
rapidjson
SDL2
sndio
speexdsp
udev
# intentionally omitted: xbyak - prefer vendored version for compatibility
zlib
zstd
];

# This changes `ir/opt` to `ir/var/empty` in `externals/dynarmic/src/dynarmic/CMakeLists.txt`
# making the build fail, as that path does not exist
dontFixCmake = true;

cmakeFlags = [
# actually has a noticeable performance impact
"-DYUZU_ENABLE_LTO=ON"

# build with qt6
"-DENABLE_QT6=ON"
"-DENABLE_QT_TRANSLATION=ON"

# use system libraries
"-DYUZU_USE_EXTERNAL_SDL2=OFF"

# don't check for missing submodules
"-DYUZU_CHECK_SUBMODULES=OFF"

# enable some optional features
"-DYUZU_USE_QT_WEB_ENGINE=ON"
"-DYUZU_USE_QT_MULTIMEDIA=ON"
"-DUSE_DISCORD_PRESENCE=ON"

# We dont want to bother upstream with potentially outdated compat reports
"-DYUZU_ENABLE_COMPATIBILITY_REPORTING=OFF"
"-DENABLE_COMPATIBILITY_LIST_DOWNLOAD=OFF" # We provide this deterministically
];

# Fixes vulkan detection.
# FIXME: patchelf --add-rpath corrupts the binary for some reason, investigate
qtWrapperArgs = [
"--prefix LD_LIBRARY_PATH : ${vulkan-loader}/lib"
];

preConfigure = ''
# see https://github.com/NixOS/nixpkgs/issues/114044, setting this through cmakeFlags does not work.
cmakeFlagsArray+=(
"-DTITLE_BAR_FORMAT_IDLE=torzu | git ${current.version} (chaotic-nyx) {}"
"-DTITLE_BAR_FORMAT_RUNNING=torzu | git ${current.version} (chaotic-nyx) | {}"
)
# provide pre-downloaded tz data
mkdir -p build/externals/nx_tzdb
ln -sf ${tzinfo} build/externals/nx_tzdb/nx_tzdb
'';

# This must be done after cmake finishes as it overwrites the file
postConfigure = ''
ln -sf ${compat-list} ./dist/compatibility_list/compatibility_list.json
'';

doCheck = false;

env.SOURCE_DATE_EPOCH = current.lastModified;

meta = with lib; {
homepage = "http://vub63vv26q6v27xzv2dtcd25xumubshogm67yrpaz2rculqxs7jlfqad.onion/torzu-emu/torzu";
description = "The TOR branch of an experimental Nintendo Switch emulator written in C++";
longDescription = ''
An experimental Nintendo Switch emulator written in C++.
Using the mainline branch is recommended for general usage.
Using the early-access branch is recommended if you would like to try out experimental features, with a cost of stability.
'';
mainProgram = "yuzu";
platforms = [ "x86_64-linux" ];
license = with licenses; [
gpl3Plus
# Icons
asl20
mit
cc0
];
maintainers = with maintainers; [
ashley
ivar
joshuafern
sbruder
k900
];
};
}
14 changes: 14 additions & 0 deletions pkgs/torzu-git/version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "unstable-20241010-a9b7cae",
"lastModified": "1728545832",
"rev": "a9b7cae66757513b13a97d60f86fcc604ccbe3ed",
"hash": "sha256-dminZLKXBNDbnYa54Kvb339f85lnam5/o4A3nk2T8aI=",
"compatList": {
"rev": "fc974b6e78105774dae5f68e712a6beb51b9db1e",
"hash": "sha256:1hdsza3wf9a0yvj6h55gsl7xqvhafvbz1i8paz9kg7l49b0gnlh1"
},
"tzinfo": {
"version": "221202",
"hash": "sha256-YOIElcKTiclem05trZsA3YJReozu/ex7jJAKD6nAMwc="
}
}

1 comment on commit ec6b449

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All packages were built and cached successfully! (361 not suitable for building)

Please sign in to comment.