Skip to content

Commit 8d02c56

Browse files
authored
dotnet: improve buildDotnetGlobalTool (#361464)
2 parents 9a78c7a + 8e497c4 commit 8d02c56

File tree

8 files changed

+129
-110
lines changed

8 files changed

+129
-110
lines changed
Lines changed: 79 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,79 @@
1-
{ buildDotnetModule, emptyDirectory, fetchNupkg, dotnet-sdk }:
2-
3-
{ pname
4-
, version
5-
# Name of the nuget package to install, if different from pname
6-
, nugetName ? pname
7-
# Hash of the nuget package to install, will be given on first build
8-
# nugetHash uses SRI hash and should be preferred
9-
, nugetHash ? ""
10-
, nugetSha256 ? ""
11-
# Additional nuget deps needed by the tool package
12-
, nugetDeps ? (_: [])
13-
# Executables to wrap into `$out/bin`, same as in `buildDotnetModule`, but with
14-
# a default of `pname` instead of null, to avoid auto-wrapping everything
15-
, executables ? pname
16-
# The dotnet runtime to use, dotnet tools need a full SDK to function
17-
, dotnet-runtime ? dotnet-sdk
18-
, ...
19-
} @ args:
20-
21-
buildDotnetModule (args // {
22-
inherit pname version dotnet-runtime executables;
23-
24-
src = emptyDirectory;
25-
26-
buildInputs = [
27-
(fetchNupkg {
28-
pname = nugetName;
29-
inherit version;
30-
sha256 = nugetSha256;
31-
hash = nugetHash;
32-
installable = true;
33-
})
34-
];
35-
36-
dotnetGlobalTool = true;
37-
38-
useDotnetFromEnv = true;
39-
40-
dontBuild = true;
41-
42-
installPhase = ''
43-
runHook preInstall
44-
45-
dotnet tool install --tool-path $out/lib/${pname} ${nugetName}
46-
47-
# remove files that contain nix store paths to temp nuget sources we made
48-
find $out -name 'project.assets.json' -delete
49-
find $out -name '.nupkg.metadata' -delete
50-
51-
runHook postInstall
52-
'';
53-
})
1+
{
2+
buildDotnetModule,
3+
emptyDirectory,
4+
fetchNupkg,
5+
dotnet-sdk,
6+
lib,
7+
}:
8+
9+
fnOrAttrs:
10+
11+
buildDotnetModule (
12+
finalAttrs:
13+
(
14+
{
15+
pname,
16+
version,
17+
# Name of the nuget package to install, if different from pname
18+
nugetName ? pname,
19+
# Hash of the nuget package to install, will be given on first build
20+
# nugetHash uses SRI hash and should be preferred
21+
nugetHash ? "",
22+
nugetSha256 ? "",
23+
# Additional nuget deps needed by the tool package
24+
nugetDeps ? (_: [ ]),
25+
# Executables to wrap into `$out/bin`, same as in `buildDotnetModule`, but with
26+
# a default of `pname` instead of null, to avoid auto-wrapping everything
27+
executables ? pname,
28+
# The dotnet runtime to use, dotnet tools need a full SDK to function
29+
dotnet-runtime ? dotnet-sdk,
30+
...
31+
}@args:
32+
let
33+
nupkg = fetchNupkg {
34+
pname = nugetName;
35+
inherit version;
36+
sha256 = nugetSha256;
37+
hash = nugetHash;
38+
installable = true;
39+
};
40+
in
41+
args
42+
// {
43+
inherit
44+
pname
45+
version
46+
dotnet-runtime
47+
executables
48+
;
49+
50+
src = emptyDirectory;
51+
52+
buildInputs = [ nupkg ];
53+
54+
dotnetGlobalTool = true;
55+
56+
useDotnetFromEnv = true;
57+
58+
dontBuild = true;
59+
60+
installPhase = ''
61+
runHook preInstall
62+
63+
dotnet tool install --tool-path $out/lib/${pname} ${nugetName}
64+
65+
# remove files that contain nix store paths to temp nuget sources we made
66+
find $out -name 'project.assets.json' -delete
67+
find $out -name '.nupkg.metadata' -delete
68+
69+
runHook postInstall
70+
'';
71+
72+
passthru = {
73+
updateScript = ./update.sh;
74+
nupkg = nupkg;
75+
} // args.passthru or {};
76+
}
77+
)
78+
(if lib.isFunction fnOrAttrs then fnOrAttrs finalAttrs else fnOrAttrs)
79+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env nix-shell
2+
#!nix-shell -I nixpkgs=./. -i bash -p curl jq nix common-updater-scripts
3+
# shellcheck shell=bash
4+
5+
set -euo pipefail
6+
7+
attr=$UPDATE_NIX_ATTR_PATH
8+
9+
nixeval() {
10+
nix --extra-experimental-features nix-command eval --json --impure -f . "$1" | jq -r .
11+
}
12+
13+
nugetName=$(nixeval "$attr.nupkg.pname")
14+
15+
# always skip prerelease versions for now
16+
version=$(curl -fsSL "https://api.nuget.org/v3-flatcontainer/$nugetName/index.json" |
17+
jq -er '.versions | last(.[] | select(match("^[0-9]+\\.[0-9]+\\.[0-9]+$")))')
18+
19+
if [[ $version == $(nixeval "$attr.version") ]]; then
20+
echo "$attr" is already version "$version"
21+
exit 0
22+
fi
23+
24+
update-source-version "$attr" "$version" --source-key=nupkg.src

pkgs/by-name/cs/csharp-ls/package.nix

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
lib,
33
buildDotnetGlobalTool,
44
dotnetCorePackages,
5-
nix-update-script,
65
}:
76
let
87
inherit (dotnetCorePackages) sdk_8_0;
@@ -17,10 +16,6 @@ buildDotnetGlobalTool rec {
1716
dotnet-sdk = sdk_8_0;
1817
dotnet-runtime = sdk_8_0;
1918

20-
passthru = {
21-
updateScript = nix-update-script { };
22-
};
23-
2419
meta = {
2520
description = "Roslyn-based LSP language server for C#";
2621
mainProgram = "csharp-ls";

pkgs/by-name/cs/csharpier/package.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
buildDotnetGlobalTool {
44
pname = "csharpier";
5-
version = "0.29.1";
5+
version = "0.30.2";
66
executables = "dotnet-csharpier";
77

8-
nugetHash = "sha256-VW9QzbQfbY3Tz+Gz3hQ7VC4wOtwfIYV1Yq2WJz6bL04=";
8+
nugetHash = "sha256-MrpsVlIYyrlu3VvEPcLQRgD2lhfu8ZTN3pUZrZ9nQcA=";
99

1010
meta = with lib; {
1111
description = "Opinionated code formatter for C#";

pkgs/by-name/pb/pbm/package.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
buildDotnetGlobalTool {
44
pname = "pbm";
5-
version = "1.3.2";
5+
version = "1.4.3";
66

7-
nugetHash = "sha256-xu3g8NFLZYnHzBuoIhIiAzaPJqY0xhLWLYi+ORRADH8=";
7+
nugetHash = "sha256-R6dmF3HPI2BAcNGLCm6WwBlk4ev6T6jaiJUAWYKf2S4=";
88

99
meta = with lib; {
1010
description = "CLI for managing Akka.NET applications and Akka.NET Clusters";

pkgs/by-name/up/upgrade-assistant/package.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{ lib, buildDotnetGlobalTool }:
22
buildDotnetGlobalTool {
33
pname = "upgrade-assistant";
4-
version = "0.5.820";
4+
version = "0.5.829";
55

6-
nugetHash = "sha256-GB+q5aZRkBTeXUbIPjkPsll6pSI/H6Iyh5mY53uT284=";
6+
nugetHash = "sha256-N0xEmPQ88jfirGPLJykeAJQYGwELFzKwUWdFxIgiwhY=";
77

88
meta = {
99
homepage = "https://github.com/dotnet/upgrade-assistant";
Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
{ buildDotnetGlobalTool, lib }:
1+
{
2+
buildDotnetGlobalTool,
3+
lib,
4+
testers,
5+
}:
26

3-
buildDotnetGlobalTool {
7+
buildDotnetGlobalTool (finalAttrs: {
48
pname = "fable";
5-
version = "4.20.0";
9+
version = "4.24.0";
610

7-
nugetHash = "sha256-K3908gEbl9crT4wmZfBtvag5Z6qYABfalBfLZlqZuDk=";
8-
passthru.updateScript = ./update.sh;
11+
nugetHash = "sha256-ERewWqfEyyZKpHFFALpMGJT0fDWywBYY5buU/wTZZTg=";
12+
13+
passthru.tests = testers.testVersion {
14+
package = finalAttrs.finalPackage;
15+
# the version is written with an escape sequence for colour, and I couldn't
16+
# find a way to disable it
17+
version = "[37m${finalAttrs.version}";
18+
};
919

1020
meta = with lib; {
1121
description = "Fable is an F# to JavaScript compiler";
@@ -14,6 +24,9 @@ buildDotnetGlobalTool {
1424
changelog = "https://github.com/fable-compiler/fable/releases/tag/v${version}";
1525
license = licenses.mit;
1626
platforms = platforms.linux;
17-
maintainers = with maintainers; [ anpin mdarocha ];
27+
maintainers = with maintainers; [
28+
anpin
29+
mdarocha
30+
];
1831
};
19-
}
32+
})

pkgs/development/tools/fable/update.sh

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)