Skip to content

Commit

Permalink
rquickshare: build from source
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesGitH committed Nov 20, 2024
1 parent 6d2d99e commit 39dde3b
Showing 1 changed file with 80 additions and 16 deletions.
96 changes: 80 additions & 16 deletions pkgs/by-name/rq/rquickshare/package.nix
Original file line number Diff line number Diff line change
@@ -1,33 +1,97 @@
{
appimageTools,
lib,
fetchurl,
cargo-tauri,
nodejs,
pnpm,
rustPlatform,
moreutils,
protobuf,
jq,
yq,
stdenv,
fetchFromGitHub,
zsh,
}:
let
pname = "rquickshare";
version = "0.11.2";
src = fetchurl {
url = "https://github.com/Martichou/rquickshare/releases/download/v${version}/r-quick-share-main_v${version}_glibc-2.39_amd64.AppImage";
hash = "sha256-7w1zybCPRg4RK5bKHoHLDUDXVDQL23ox/6wh8H9vTPg=";
src = fetchFromGitHub {
owner = "martichou";
repo = "rquickshare";
rev = "v${version}";
sha256 = "sha256-MYhM6FB3zfvMFnLMecbn4Ismvk8AAykIvhPBnFcNjdI=";
};
appimageContents = appimageTools.extractType2 { inherit pname version src; };
tauri = cargo-tauri;
in
appimageTools.wrapType2 {
inherit pname version src;
extraInstallCommands = ''
install -Dm444 ${appimageContents}/rquickshare.desktop -t $out/share/applications
substituteInPlace $out/share/applications/rquickshare.desktop \
--replace-fail 'Exec=rquickshare' 'Exec=rquickshare %u'
cp -r ${appimageContents}/usr/share/icons $out/share
# we could use rustPlatform.buildRustPackage, but there cargoDeps doesn't work
stdenv.mkDerivation rec {
inherit version src pname;
name = pname;
sourceRoot = "source/app/main";
corelibSourceRoot = "source/core_lib";
cargoRoot = "src-tauri";
corelibPath = "rqs_lib";
nativeBuildInputs = [
tauri.hook
pnpm.configHook
nodejs
moreutils
protobuf
jq
yq
rustPlatform.cargoSetupHook
];
# seemingly the fetcher ignores cargoRoot (contrary to the docs)
cargoDeps = rustPlatform.fetchCargoVendor {
inherit src;
pname = name + "-cargo-deps";
hash = cargoHash;
sourceRoot = "${sourceRoot}/${cargoRoot}";
};
cargoHash = "sha256-5vGXMHar9E25jVseXR2uI82DtZXyPaHgDD8QkqoRhhY=";
pnpmDeps = pnpm.fetchDeps {
inherit src sourceRoot;
pname = name + "-pnpm-deps";
hash = "sha256-VPb2idEiBruVCwz5lDojFmD2C5CfXYSe5mPWBwCGeJs=";
};
postUnpack =
let
fullCorePath = "${sourceRoot}/${cargoRoot}/${corelibPath}";
in
''
cp -r ${corelibSourceRoot} ${fullCorePath} && chmod -R +w ${fullCorePath}
'';
# remove macOS signing and relative links
postConfigure = ''
jq 'del(.bundle.macOS.signingIdentity, .bundle.macOS.hardenedRuntime)' src-tauri/tauri.conf.json | sponge src-tauri/tauri.conf.json
yq -iy '.importers.".".dependencies."@martichou/core_lib".specifier = "link:${corelibPath}" | .importers.".".dependencies."@martichou/core_lib".version = "link:${corelibPath}"' pnpm-lock.yaml
jq '.dependencies."@martichou/core_lib" = "link:${corelibPath}"' package.json | sponge package.json
sed -i 's|path = "../../../core_lib"|path = "${corelibPath}"|' ${cargoRoot}/Cargo.toml
'';

checkPhase = "true"; # idk why checks fail, todo
installPhase =
let
path = "${cargoRoot}/target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/bundle";
in
if stdenv.isDarwin then
''
mkdir -p $out/bin
mv ${path}/macos $out/Applications
echo "#!${lib.getExe zsh}" >> $out/bin/${name}
echo "open -a $out/Applications/${name}.app" >> $out/bin/${name}
chmod +x $out/bin/${name}
''
else
''
mv ${path}/deb/*/data/usr $out
'';
meta = {
description = "Rust implementation of NearbyShare/QuickShare from Android for Linux";
homepage = "https://github.com/Martichou/rquickshare";
changelog = "https://github.com/Martichou/rquickshare/blob/v${version}/CHANGELOG.md";
license = lib.licenses.gpl3Plus;
maintainers = [ lib.maintainers.luftmensch-luftmensch ];
platforms = [ "x86_64-linux" ];
maintainers = with lib.maintainers; [ hannesgith ];
platforms = with lib.platforms; linux ++ darwin;
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
mainProgram = "rquickshare";
};
Expand Down

0 comments on commit 39dde3b

Please sign in to comment.