From 1b366cb92b2640816c54df8af17c8d3914f088dd Mon Sep 17 00:00:00 2001 From: IvarWithoutBones Date: Sun, 21 Nov 2021 22:47:53 +0100 Subject: [PATCH 1/2] buildDotnetModule: support setting projectFile as an array && properly interpret disabledTests --- doc/languages-frameworks/dotnet.section.md | 2 +- .../build-dotnet-module/default.nix | 82 ++++++++++--------- 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/doc/languages-frameworks/dotnet.section.md b/doc/languages-frameworks/dotnet.section.md index f2a5efd05db6..f3d9fb875734 100644 --- a/doc/languages-frameworks/dotnet.section.md +++ b/doc/languages-frameworks/dotnet.section.md @@ -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. diff --git a/pkgs/build-support/build-dotnet-module/default.nix b/pkgs/build-support/build-dotnet-module/default.nix index 6a7b70e070b0..5178e08a9c73 100644 --- a/pkgs/build-support/build-dotnet-module/default.nix +++ b/pkgs/build-support/build-dotnet-module/default.nix @@ -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" \ - ${lib.optionalString (!enableParallelBuilding) "--disable-parallel"} \ - -p:ContinuousIntegrationBuild=true \ - -p:Deterministic=true \ - --source "${nuget-source}/lib" \ - "''${dotnetRestoreFlags[@]}" \ - "''${dotnetFlags[@]}" + 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,16 +118,18 @@ let buildPhase = args.buildPhase or '' runHook preBuild - dotnet build "$projectFile" \ - -maxcpucount:${if enableParallelBuilding then "$NIX_BUILD_CORES" else "1"} \ - -p:BuildInParallel=${if enableParallelBuilding then "true" else "false"} \ - -p:ContinuousIntegrationBuild=true \ - -p:Deterministic=true \ - -p:Version=${args.version} \ - --configuration "$buildType" \ - --no-restore \ - "''${dotnetBuildFlags[@]}" \ - "''${dotnetFlags[@]}" + 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 \ + -p:Deterministic=true \ + -p:Version=${args.version} \ + --configuration "$buildType" \ + --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" \ - -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}\""} \ - "''${dotnetTestFlags[@]}" \ - "''${dotnetFlags[@]}" + 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}\""} \ + "''${dotnetTestFlags[@]}" \ + "''${dotnetFlags[@]}" + done runHook postCheck ''; @@ -150,15 +156,17 @@ let installPhase = args.installPhase or '' runHook preInstall - dotnet publish "$projectFile" \ - -p:ContinuousIntegrationBuild=true \ - -p:Deterministic=true \ - --output $out/lib/${args.pname} \ - --configuration "$buildType" \ - --no-build \ - --no-self-contained \ - "''${dotnetInstallFlags[@]}" \ - "''${dotnetFlags[@]}" + for project in ''${projectFile[@]}; do + dotnet publish "$project" \ + -p:ContinuousIntegrationBuild=true \ + -p:Deterministic=true \ + --output $out/lib/${args.pname} \ + --configuration "$buildType" \ + --no-build \ + --no-self-contained \ + "''${dotnetInstallFlags[@]}" \ + "''${dotnetFlags[@]}" + done '' + (if executables != null then '' for executable in $executables; do execPath="$out/lib/${args.pname}/$executable" From 9a0d636d7d220e084c14f32b0d3a0aa16abdc9c1 Mon Sep 17 00:00:00 2001 From: IvarWithoutBones Date: Sun, 21 Nov 2021 22:49:07 +0100 Subject: [PATCH 2/2] opentabletdriver: use buildDotnetModule --- pkgs/tools/X11/opentabletdriver/default.nix | 117 ++++---------------- pkgs/tools/X11/opentabletdriver/shell.nix | 13 --- pkgs/tools/X11/opentabletdriver/update.sh | 38 ++----- 3 files changed, 34 insertions(+), 134 deletions(-) delete mode 100644 pkgs/tools/X11/opentabletdriver/shell.nix diff --git a/pkgs/tools/X11/opentabletdriver/default.nix b/pkgs/tools/X11/opentabletdriver/default.nix index b205f959ee35..de3b983c91da 100644 --- a/pkgs/tools/X11/opentabletdriver/default.nix +++ b/pkgs/tools/X11/opentabletdriver/default.nix @@ -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; diff --git a/pkgs/tools/X11/opentabletdriver/shell.nix b/pkgs/tools/X11/opentabletdriver/shell.nix deleted file mode 100644 index bb60dfd50397..000000000000 --- a/pkgs/tools/X11/opentabletdriver/shell.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ pkgs ? import ../../../../. { } }: - -with pkgs; - -mkShell { - packages = [ - common-updater-scripts - nuget-to-nix - curl - dotnetCorePackages.sdk_5_0 - jq - ]; -} diff --git a/pkgs/tools/X11/opentabletdriver/update.sh b/pkgs/tools/X11/opentabletdriver/update.sh index b73a5a4b7ca9..b18bddd75aa9 100755 --- a/pkgs/tools/X11/opentabletdriver/update.sh +++ b/pkgs/tools/X11/opentabletdriver/update.sh @@ -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 - +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"