From 07a92bc00666ed8c9aaecaf2a50907d7ebbcbf01 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 2 Dec 2024 21:27:55 -0400 Subject: [PATCH] buildDotnetGlobalTools: add finalAttrs support --- .../build-dotnet-global-tool/default.nix | 102 +++++++++--------- 1 file changed, 54 insertions(+), 48 deletions(-) diff --git a/pkgs/build-support/dotnet/build-dotnet-global-tool/default.nix b/pkgs/build-support/dotnet/build-dotnet-global-tool/default.nix index 9d199a6d0a4e..4b8ad583d82d 100644 --- a/pkgs/build-support/dotnet/build-dotnet-global-tool/default.nix +++ b/pkgs/build-support/dotnet/build-dotnet-global-tool/default.nix @@ -3,65 +3,71 @@ emptyDirectory, fetchNupkg, dotnet-sdk, + lib, }: -{ - pname, - version, - # Name of the nuget package to install, if different from pname - nugetName ? pname, - # Hash of the nuget package to install, will be given on first build - # nugetHash uses SRI hash and should be preferred - nugetHash ? "", - nugetSha256 ? "", - # Additional nuget deps needed by the tool package - nugetDeps ? (_: [ ]), - # Executables to wrap into `$out/bin`, same as in `buildDotnetModule`, but with - # a default of `pname` instead of null, to avoid auto-wrapping everything - executables ? pname, - # The dotnet runtime to use, dotnet tools need a full SDK to function - dotnet-runtime ? dotnet-sdk, - ... -}@args: +fnOrAttrs: buildDotnetModule ( - args - // { - inherit - pname - version - dotnet-runtime - executables - ; + finalAttrs: + ( + { + pname, + version, + # Name of the nuget package to install, if different from pname + nugetName ? pname, + # Hash of the nuget package to install, will be given on first build + # nugetHash uses SRI hash and should be preferred + nugetHash ? "", + nugetSha256 ? "", + # Additional nuget deps needed by the tool package + nugetDeps ? (_: [ ]), + # Executables to wrap into `$out/bin`, same as in `buildDotnetModule`, but with + # a default of `pname` instead of null, to avoid auto-wrapping everything + executables ? pname, + # The dotnet runtime to use, dotnet tools need a full SDK to function + dotnet-runtime ? dotnet-sdk, + ... + }@args: + args + // { + inherit + pname + version + dotnet-runtime + executables + ; - src = emptyDirectory; + src = emptyDirectory; - buildInputs = [ - (fetchNupkg { - pname = nugetName; - inherit version; - sha256 = nugetSha256; - hash = nugetHash; - installable = true; - }) - ]; + buildInputs = [ + (fetchNupkg { + pname = nugetName; + inherit version; + sha256 = nugetSha256; + hash = nugetHash; + installable = true; + }) + ]; - dotnetGlobalTool = true; + dotnetGlobalTool = true; - useDotnetFromEnv = true; + useDotnetFromEnv = true; - dontBuild = true; + dontBuild = true; - installPhase = '' - runHook preInstall + installPhase = '' + runHook preInstall - dotnet tool install --tool-path $out/lib/${pname} ${nugetName} + dotnet tool install --tool-path $out/lib/${pname} ${nugetName} - # remove files that contain nix store paths to temp nuget sources we made - find $out -name 'project.assets.json' -delete - find $out -name '.nupkg.metadata' -delete + # remove files that contain nix store paths to temp nuget sources we made + find $out -name 'project.assets.json' -delete + find $out -name '.nupkg.metadata' -delete - runHook postInstall - ''; - } + runHook postInstall + ''; + } + ) + (if lib.isFunction fnOrAttrs then fnOrAttrs finalAttrs else fnOrAttrs) )