opentabletdriver: use buildDotnetModule

This commit is contained in:
IvarWithoutBones 2021-11-21 22:49:07 +01:00
parent 1b366cb92b
commit 9a0d636d7d
3 changed files with 34 additions and 134 deletions

View File

@ -1,11 +1,8 @@
{ stdenv
, lib
{ lib
, buildDotnetModule
, fetchFromGitHub
, fetchurl
, linkFarmFromDrvs
, dotnetCorePackages
, dotnetPackages
, dpkg
, gtk3
, libX11
, libXrandr
@ -15,16 +12,12 @@
, udev
, copyDesktopItems
, makeDesktopItem
, makeWrapper
, nixosTests
, wrapGAppsHook
, dpkg
}:
let
dotnet-sdk = dotnetCorePackages.sdk_5_0;
dotnet-runtime = dotnetCorePackages.runtime_5_0;
in
stdenv.mkDerivation rec {
buildDotnetModule rec {
pname = "OpenTabletDriver";
version = "0.5.3.3";
@ -40,22 +33,21 @@ stdenv.mkDerivation rec {
sha256 = "0v03qiiz28k1yzgxf5qc1mdg2n7kjx6h8vpx9dxz342wwbgqg6ic";
};
nativeBuildInputs = [
dotnet-sdk
dotnetPackages.Nuget
dpkg
copyDesktopItems
makeWrapper
wrapGAppsHook
];
dotnet-sdk = dotnetCorePackages.sdk_5_0;
dotnet-runtime = dotnetCorePackages.runtime_5_0;
nugetDeps = linkFarmFromDrvs "${pname}-nuget-deps" (import ./deps.nix {
fetchNuGet = { name, version, sha256 }: fetchurl {
name = "nuget-${name}-${version}.nupkg";
url = "https://www.nuget.org/api/v2/package/${name}/${version}";
inherit sha256;
};
});
dotnetInstallFlags = [ "--framework=net5" ];
projectFile = [ "OpenTabletDriver.Console" "OpenTabletDriver.Daemon" "OpenTabletDriver.UX.Gtk" ];
nugetDeps = ./deps.nix;
executables = [ "OpenTabletDriver.Console" "OpenTabletDriver.Daemon" "OpenTabletDriver.UX.Gtk" ];
nativeBuildInputs = [
copyDesktopItems
wrapGAppsHook
dpkg
];
runtimeDeps = [
gtk3
@ -67,80 +59,18 @@ stdenv.mkDerivation rec {
udev
];
configurePhase = ''
runHook preConfigure
export HOME=$(mktemp -d)
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
nuget sources Add -Name nixos -Source "$PWD/nixos"
nuget init "$nugetDeps" "$PWD/nixos"
# FIXME: https://github.com/NuGet/Home/issues/4413
mkdir -p $HOME/.nuget/NuGet
cp $HOME/.config/NuGet/NuGet.Config $HOME/.nuget/NuGet
for project in OpenTabletDriver.{Console,Daemon,UX.Gtk}; do
dotnet restore --source "$PWD/nixos" $project
done
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
for project in OpenTabletDriver.{Console,Daemon,UX.Gtk}; do
dotnet build $project \
--no-restore \
--configuration Release \
--framework net5
done
runHook postBuild
'';
installPhase = ''
runHook preInstall
for project in OpenTabletDriver.{Console,Daemon,UX.Gtk}; do
dotnet publish $project \
--no-build \
--no-self-contained \
--configuration Release \
--framework net5 \
--output $out/lib
done
postInstall = ''
# Give a more "*nix" name to the binaries
makeWrapper $out/lib/OpenTabletDriver.Console $out/bin/otd \
"''${gappsWrapperArgs[@]}" \
--prefix XDG_DATA_DIRS : "${gtk3}/share/gsettings-schemas/${gtk3.name}/" \
--set DOTNET_ROOT "${dotnet-runtime}" \
--suffix LD_LIBRARY_PATH : "${lib.makeLibraryPath runtimeDeps}"
mv $out/bin/OpenTabletDriver.Console $out/bin/otd
mv $out/bin/OpenTabletDriver.Daemon $out/bin/otd-daemon
mv $out/bin/OpenTabletDriver.UX.Gtk $out/bin/otd-gui
makeWrapper $out/lib/OpenTabletDriver.Daemon $out/bin/otd-daemon \
"''${gappsWrapperArgs[@]}" \
--prefix XDG_DATA_DIRS : "${gtk3}/share/gsettings-schemas/${gtk3.name}/" \
--set DOTNET_ROOT "${dotnet-runtime}" \
--suffix LD_LIBRARY_PATH : "${lib.makeLibraryPath runtimeDeps}"
makeWrapper $out/lib/OpenTabletDriver.UX.Gtk $out/bin/otd-gui \
"''${gappsWrapperArgs[@]}" \
--prefix XDG_DATA_DIRS : "${gtk3}/share/gsettings-schemas/${gtk3.name}/" \
--set DOTNET_ROOT "${dotnet-runtime}" \
--suffix LD_LIBRARY_PATH : "${lib.makeLibraryPath runtimeDeps}"
mkdir -p $out/lib/OpenTabletDriver
cp -rv ./OpenTabletDriver/Configurations $out/lib/OpenTabletDriver
cp -r ./OpenTabletDriver/Configurations $out/lib/${pname}
install -Dm644 $src/OpenTabletDriver.UX/Assets/otd.png -t $out/share/pixmaps
# TODO: Ideally this should be build from OpenTabletDriver/OpenTabletDriver-udev instead
dpkg-deb --fsys-tarfile ${debPkg} | tar xf - ./usr/lib/udev/rules.d/99-opentabletdriver.rules
install -Dm644 ./usr/lib/udev/rules.d/99-opentabletdriver.rules -t $out/lib/udev/rules.d
runHook postInstall
'';
desktopItems = [
@ -156,7 +86,6 @@ stdenv.mkDerivation rec {
];
dontWrapGApps = true;
dontStrip = true;
passthru = {
updateScript = ./update.sh;

View File

@ -1,13 +0,0 @@
{ pkgs ? import ../../../../. { } }:
with pkgs;
mkShell {
packages = [
common-updater-scripts
nuget-to-nix
curl
dotnetCorePackages.sdk_5_0
jq
];
}

View File

@ -1,16 +1,15 @@
#!/usr/bin/env nix-shell
#!nix-shell shell.nix -i bash
#!nix-shell -i bash -p curl gnused jq common-updater-scripts nuget-to-nix dotnet-sdk_5
set -eo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
deps_file="$(realpath "./deps.nix")"
new_version="$(curl -s "https://api.github.com/repos/OpenTabletDriver/OpenTabletDriver/releases" | jq -r '.[0].tag_name' | sed 's|[^0-9.]||g')"
new_version="$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} -s "https://api.github.com/repos/OpenTabletDriver/OpenTabletDriver/releases" | jq -r 'map(select(.prerelease == false)) | .[0].tag_name' | cut -c2-)"
old_version="$(sed -nE 's/\s*version = "(.*)".*/\1/p' ./default.nix)"
if [[ "$new_version" == "$old_version" ]]; then
echo "Up to date"
echo "Already up to date!"
[[ "${1}" != "--force" ]] && exit 0
fi
@ -22,37 +21,22 @@ newDebSha256=$(nix-prefetch-url "$newDebPkgUrl")
echo "oldDebSha256: $oldDebSha256 newDebSha256: $newDebSha256"
sed -i ./default.nix -re "s|\"$oldDebSha256\"|\"$newDebSha256\"|"
cd ../../../..
pushd ../../../..
update-source-version opentabletdriver "$new_version"
store_src="$(nix-build . -A opentabletdriver.src --no-out-link)"
store_src="$(nix-build -A opentabletdriver.src --no-out-link)"
src="$(mktemp -d /tmp/opentabletdriver-src.XXX)"
echo "Temp src dir: $src"
cp -rT "$store_src" "$src"
chmod -R +w "$src"
pushd "$src"
trap "rm -rf $src" EXIT
# Setup empty nuget package folder to force reinstall.
mkdir ./nuget_tmp.packages
cat >./nuget_tmp.config <<EOF
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<config>
<add key="globalPackagesFolder" value="$(realpath ./nuget_tmp.packages)" />
</config>
</configuration>
EOF
export DOTNET_NOLOGO=1
export DOTNET_CLI_TELEMETRY_OPTOUT=1
mkdir ./nuget_pkgs
for project in OpenTabletDriver.{Console,Daemon,UX.Gtk}; do
dotnet restore $project --configfile ./nuget_tmp.config
dotnet restore $project --packages ./nuget_pkgs
done
nuget-to-nix ./nuget_tmp.packages > "$deps_file"
popd
rm -r "$src"
nuget-to-nix ./nuget_pkgs > "$deps_file"