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

View File

@ -1,11 +1,8 @@
{ stdenv { lib
, lib , buildDotnetModule
, fetchFromGitHub , fetchFromGitHub
, fetchurl , fetchurl
, linkFarmFromDrvs
, dotnetCorePackages , dotnetCorePackages
, dotnetPackages
, dpkg
, gtk3 , gtk3
, libX11 , libX11
, libXrandr , libXrandr
@ -15,16 +12,12 @@
, udev , udev
, copyDesktopItems , copyDesktopItems
, makeDesktopItem , makeDesktopItem
, makeWrapper
, nixosTests , nixosTests
, wrapGAppsHook , wrapGAppsHook
, dpkg
}: }:
let buildDotnetModule rec {
dotnet-sdk = dotnetCorePackages.sdk_5_0;
dotnet-runtime = dotnetCorePackages.runtime_5_0;
in
stdenv.mkDerivation rec {
pname = "OpenTabletDriver"; pname = "OpenTabletDriver";
version = "0.5.3.3"; version = "0.5.3.3";
@ -40,22 +33,21 @@ stdenv.mkDerivation rec {
sha256 = "0v03qiiz28k1yzgxf5qc1mdg2n7kjx6h8vpx9dxz342wwbgqg6ic"; sha256 = "0v03qiiz28k1yzgxf5qc1mdg2n7kjx6h8vpx9dxz342wwbgqg6ic";
}; };
nativeBuildInputs = [ dotnet-sdk = dotnetCorePackages.sdk_5_0;
dotnet-sdk dotnet-runtime = dotnetCorePackages.runtime_5_0;
dotnetPackages.Nuget
dpkg
copyDesktopItems
makeWrapper
wrapGAppsHook
];
nugetDeps = linkFarmFromDrvs "${pname}-nuget-deps" (import ./deps.nix { dotnetInstallFlags = [ "--framework=net5" ];
fetchNuGet = { name, version, sha256 }: fetchurl {
name = "nuget-${name}-${version}.nupkg"; projectFile = [ "OpenTabletDriver.Console" "OpenTabletDriver.Daemon" "OpenTabletDriver.UX.Gtk" ];
url = "https://www.nuget.org/api/v2/package/${name}/${version}"; nugetDeps = ./deps.nix;
inherit sha256;
}; executables = [ "OpenTabletDriver.Console" "OpenTabletDriver.Daemon" "OpenTabletDriver.UX.Gtk" ];
});
nativeBuildInputs = [
copyDesktopItems
wrapGAppsHook
dpkg
];
runtimeDeps = [ runtimeDeps = [
gtk3 gtk3
@ -67,80 +59,18 @@ stdenv.mkDerivation rec {
udev udev
]; ];
configurePhase = '' postInstall = ''
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
# Give a more "*nix" name to the binaries # Give a more "*nix" name to the binaries
makeWrapper $out/lib/OpenTabletDriver.Console $out/bin/otd \ mv $out/bin/OpenTabletDriver.Console $out/bin/otd
"''${gappsWrapperArgs[@]}" \ mv $out/bin/OpenTabletDriver.Daemon $out/bin/otd-daemon
--prefix XDG_DATA_DIRS : "${gtk3}/share/gsettings-schemas/${gtk3.name}/" \ mv $out/bin/OpenTabletDriver.UX.Gtk $out/bin/otd-gui
--set DOTNET_ROOT "${dotnet-runtime}" \
--suffix LD_LIBRARY_PATH : "${lib.makeLibraryPath runtimeDeps}"
makeWrapper $out/lib/OpenTabletDriver.Daemon $out/bin/otd-daemon \ cp -r ./OpenTabletDriver/Configurations $out/lib/${pname}
"''${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
install -Dm644 $src/OpenTabletDriver.UX/Assets/otd.png -t $out/share/pixmaps install -Dm644 $src/OpenTabletDriver.UX/Assets/otd.png -t $out/share/pixmaps
# TODO: Ideally this should be build from OpenTabletDriver/OpenTabletDriver-udev instead # 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 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 install -Dm644 ./usr/lib/udev/rules.d/99-opentabletdriver.rules -t $out/lib/udev/rules.d
runHook postInstall
''; '';
desktopItems = [ desktopItems = [
@ -156,7 +86,6 @@ stdenv.mkDerivation rec {
]; ];
dontWrapGApps = true; dontWrapGApps = true;
dontStrip = true;
passthru = { passthru = {
updateScript = ./update.sh; 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 #!/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 set -eo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")" cd "$(dirname "${BASH_SOURCE[0]}")"
deps_file="$(realpath "./deps.nix")" 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)" old_version="$(sed -nE 's/\s*version = "(.*)".*/\1/p' ./default.nix)"
if [[ "$new_version" == "$old_version" ]]; then if [[ "$new_version" == "$old_version" ]]; then
echo "Up to date" echo "Already up to date!"
[[ "${1}" != "--force" ]] && exit 0 [[ "${1}" != "--force" ]] && exit 0
fi fi
@ -22,37 +21,22 @@ newDebSha256=$(nix-prefetch-url "$newDebPkgUrl")
echo "oldDebSha256: $oldDebSha256 newDebSha256: $newDebSha256" echo "oldDebSha256: $oldDebSha256 newDebSha256: $newDebSha256"
sed -i ./default.nix -re "s|\"$oldDebSha256\"|\"$newDebSha256\"|" sed -i ./default.nix -re "s|\"$oldDebSha256\"|\"$newDebSha256\"|"
cd ../../../.. pushd ../../../..
update-source-version opentabletdriver "$new_version" 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)" src="$(mktemp -d /tmp/opentabletdriver-src.XXX)"
echo "Temp src dir: $src"
cp -rT "$store_src" "$src" cp -rT "$store_src" "$src"
chmod -R +w "$src" chmod -R +w "$src"
pushd "$src" pushd "$src"
trap "rm -rf $src" EXIT
# Setup empty nuget package folder to force reinstall. export DOTNET_NOLOGO=1
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_CLI_TELEMETRY_OPTOUT=1 export DOTNET_CLI_TELEMETRY_OPTOUT=1
mkdir ./nuget_pkgs
for project in OpenTabletDriver.{Console,Daemon,UX.Gtk}; do for project in OpenTabletDriver.{Console,Daemon,UX.Gtk}; do
dotnet restore $project --configfile ./nuget_tmp.config dotnet restore $project --packages ./nuget_pkgs
done done
nuget-to-nix ./nuget_tmp.packages > "$deps_file" nuget-to-nix ./nuget_pkgs > "$deps_file"
popd
rm -r "$src"