From 8318df5b630579a910fd2fd3ae46bdfec37d1ef4 Mon Sep 17 00:00:00 2001 From: mdarocha Date: Sat, 30 Sep 2023 13:21:12 +0200 Subject: [PATCH 1/3] buildDotnetModule: fix running fetch-deps with no nugetDeps defined. This eases the initial setup when creating a package --- pkgs/build-support/dotnet/build-dotnet-module/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/dotnet/build-dotnet-module/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/default.nix index 686d89f8c11c..02776d57c91b 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/default.nix +++ b/pkgs/build-support/dotnet/build-dotnet-module/default.nix @@ -172,7 +172,7 @@ stdenvNoCC.mkDerivation (args // { passthru = { inherit nuget-source; - } // lib.optionalAttrs (nugetDepsFile != null) { + } // lib.optionalAttrs (!lib.isDerivation nugetDeps) { fetch-deps = let flags = dotnetFlags ++ dotnetRestoreFlags; From f1cc116e3db5cff8b92ec30ec5283de966e22066 Mon Sep 17 00:00:00 2001 From: mdarocha Date: Sat, 30 Sep 2023 13:21:36 +0200 Subject: [PATCH 2/3] buildDotnetModule: make docs more clear on how to generate nugetDeps for the first time --- doc/languages-frameworks/dotnet.section.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/languages-frameworks/dotnet.section.md b/doc/languages-frameworks/dotnet.section.md index 9ba0fef2a27b..978ec07cb961 100644 --- a/doc/languages-frameworks/dotnet.section.md +++ b/doc/languages-frameworks/dotnet.section.md @@ -138,7 +138,9 @@ in buildDotnetModule rec { src = ./.; projectFile = "src/project.sln"; - nugetDeps = ./deps.nix; # File generated with `nix-build -A package.passthru.fetch-deps`. + # File generated with `nix-build -A package.passthru.fetch-deps`. + # To run fetch-deps when this file does not yet exist, set nugetDeps to null + nugetDeps = ./deps.nix; projectReferences = [ referencedProject ]; # `referencedProject` must contain `nupkg` in the folder structure. From d016404ccd291838794c6e6c1e9ac6779cc5fa9f Mon Sep 17 00:00:00 2001 From: mdarocha Date: Sat, 30 Sep 2023 14:27:05 +0200 Subject: [PATCH 3/3] buildDotnetModule: parse version before passing it to dotnet This avoids problems when the Nix version attribute does not fit the format required by .NET --- .../dotnet/build-dotnet-module/default.nix | 16 ++++++++++++++++ .../hooks/dotnet-build-hook.sh | 9 +++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/dotnet/build-dotnet-module/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/default.nix index 02776d57c91b..f8ed3a38890c 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/default.nix +++ b/pkgs/build-support/dotnet/build-dotnet-module/default.nix @@ -158,6 +158,22 @@ stdenvNoCC.mkDerivation (args // { dotnet-sdk ]; + # Parse the version attr into a format acceptable for the Version msbuild property + # The actual version attr is saved in InformationalVersion, which accepts an arbitrary string + versionForDotnet = if !(lib.hasAttr "version" args) || args.version == null + then null else let + components = lib.pipe args.version [ + lib.splitVersion + (lib.filter (x: (lib.strings.match "[0-9]+" x) != null)) + (lib.filter (x: (lib.toInt x) < 65535)) # one version component in dotnet has to fit in 16 bits + ]; + in if (lib.length components) == 0 + then null + else lib.concatStringsSep "." ((lib.take 4 components) + ++ (if (lib.length components) < 4 + then lib.replicate (4 - (lib.length components)) "0" + else [ ])); + makeWrapperArgs = args.makeWrapperArgs or [ ] ++ [ "--prefix LD_LIBRARY_PATH : ${dotnet-sdk.icu}/lib" ]; diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh index e9567b64cf2c..0acfeced9b16 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh +++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh @@ -24,8 +24,13 @@ dotnetBuildHook() { dotnetBuildFlags+=("-p:UseAppHost=true") fi + local versionFlags=() if [ "${version-}" ]; then - local -r versionFlag="-p:Version=${version-}" + versionFlags+=("-p:InformationalVersion=${version-}") + fi + + if [ "${versionForDotnet-}" ]; then + versionFlags+=("-p:Version=${versionForDotnet-}") fi dotnetBuild() { @@ -43,7 +48,7 @@ dotnetBuildHook() { -p:Deterministic=true \ --configuration "@buildType@" \ --no-restore \ - ${versionFlag-} \ + ${versionFlags[@]} \ ${runtimeIdFlags[@]} \ ${dotnetBuildFlags[@]} \ ${dotnetFlags[@]}