Merge pull request #146935 from IvarWithoutBones/dotnetModule/otd

opentabletdriver: use buildDotnetModule
This commit is contained in:
Pavol Rusnak 2021-11-22 10:21:13 +01:00 committed by GitHub
commit e81ffdc5af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 80 additions and 172 deletions

View File

@ -71,7 +71,7 @@ The `dotnetCorePackages.sdk` contains both a runtime and the full sdk of a given
To package Dotnet applications, you can use `buildDotnetModule`. This has similar arguments to `stdenv.mkDerivation`, with the following additions:
* `projectFile` has to be used for specifying the dotnet project file relative to the source root. These usually have `.sln` or `.csproj` file extensions.
* `projectFile` has to be used for specifying the dotnet project file relative to the source root. These usually have `.sln` or `.csproj` file extensions. This can be an array of multiple projects as well.
* `nugetDeps` has to be used to specify the NuGet dependency file. Unfortunately, these cannot be deterministically fetched without a lockfile. This file should be generated using `nuget-to-nix` tool, which is available in nixpkgs.
* `executables` is used to specify which executables get wrapped to `$out/bin`, relative to `$out/lib/$pname`. If this is unset, all executables generated will get installed. If you do not want to install any, set this to `[]`.
* `runtimeDeps` is used to wrap libraries into `LD_LIBRARY_PATH`. This is how dotnet usually handles runtime dependencies.

View File

@ -21,7 +21,7 @@
# Unfortunately, dotnet has no method for doing this automatically.
# If unset, all executables in the projects root will get installed. This may cause bloat!
, executables ? null
# The packages project file, which contains instructions on how to compile it.
# The packages project file, which contains instructions on how to compile it. This can be an array of multiple project files as well.
, projectFile ? null
# The NuGet dependency file. This locks all NuGet dependency versions, as otherwise they cannot be deterministically fetched.
# This can be generated using the `nuget-to-nix` tool.
@ -102,13 +102,15 @@ let
export HOME=$(mktemp -d)
dotnet restore "$projectFile" \
for project in ''${projectFile[@]}; do
dotnet restore "$project" \
${lib.optionalString (!enableParallelBuilding) "--disable-parallel"} \
-p:ContinuousIntegrationBuild=true \
-p:Deterministic=true \
--source "${nuget-source}/lib" \
"''${dotnetRestoreFlags[@]}" \
"''${dotnetFlags[@]}"
done
runHook postConfigure
'';
@ -116,7 +118,8 @@ let
buildPhase = args.buildPhase or ''
runHook preBuild
dotnet build "$projectFile" \
for project in ''${projectFile[@]}; do
dotnet build "$project" \
-maxcpucount:${if enableParallelBuilding then "$NIX_BUILD_CORES" else "1"} \
-p:BuildInParallel=${if enableParallelBuilding then "true" else "false"} \
-p:ContinuousIntegrationBuild=true \
@ -126,6 +129,7 @@ let
--no-restore \
"''${dotnetBuildFlags[@]}" \
"''${dotnetFlags[@]}"
done
runHook postBuild
'';
@ -133,16 +137,18 @@ let
checkPhase = args.checkPhase or ''
runHook preCheck
${lib.getBin dotnet-test-sdk}/bin/dotnet test "$testProjectFile" \
for project in ''${testProjectFile[@]}; do
${lib.getBin dotnet-test-sdk}/bin/dotnet test "$project" \
-maxcpucount:${if enableParallelBuilding then "$NIX_BUILD_CORES" else "1"} \
-p:ContinuousIntegrationBuild=true \
-p:Deterministic=true \
--configuration "$buildType" \
--no-build \
--logger "console;verbosity=normal" \
${lib.optionalString (disabledTests != []) "--filter \"FullyQualifiedName!=${lib.concatStringsSep "|FullyQualifiedName!=" disabledTests}\""} \
${lib.optionalString (disabledTests != []) "--filter \"FullyQualifiedName!=${lib.concatStringsSep "&FullyQualifiedName!=" disabledTests}\""} \
"''${dotnetTestFlags[@]}" \
"''${dotnetFlags[@]}"
done
runHook postCheck
'';
@ -150,7 +156,8 @@ let
installPhase = args.installPhase or ''
runHook preInstall
dotnet publish "$projectFile" \
for project in ''${projectFile[@]}; do
dotnet publish "$project" \
-p:ContinuousIntegrationBuild=true \
-p:Deterministic=true \
--output $out/lib/${args.pname} \
@ -159,6 +166,7 @@ let
--no-self-contained \
"''${dotnetInstallFlags[@]}" \
"''${dotnetFlags[@]}"
done
'' + (if executables != null then ''
for executable in $executables; do
execPath="$out/lib/${args.pname}/$executable"

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"