Unverified Commit 8d02c567 authored by Austin Horstman's avatar Austin Horstman Committed by GitHub
Browse files

dotnet: improve buildDotnetGlobalTool (#361464)

parents 9a78c7a9 8e497c42
Loading
Loading
Loading
Loading
+79 −53
Original line number Diff line number Diff line
{ buildDotnetModule, emptyDirectory, fetchNupkg, dotnet-sdk }:
{
  buildDotnetModule,
  emptyDirectory,
  fetchNupkg,
  dotnet-sdk,
  lib,
}:

{ pname
, version
fnOrAttrs:

buildDotnetModule (
  finalAttrs:
  (
    {
      pname,
      version,
      # Name of the nuget package to install, if different from pname
, nugetName ? 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 ? ""
      nugetHash ? "",
      nugetSha256 ? "",
      # Additional nuget deps needed by the tool package
, nugetDeps ? (_: [])
      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
      executables ? pname,
      # The dotnet runtime to use, dotnet tools need a full SDK to function
, dotnet-runtime ? dotnet-sdk
, ...
      dotnet-runtime ? dotnet-sdk,
      ...
    }@args:

buildDotnetModule (args // {
  inherit pname version dotnet-runtime executables;

  src = emptyDirectory;

  buildInputs = [
    (fetchNupkg {
    let
      nupkg = fetchNupkg {
        pname = nugetName;
        inherit version;
        sha256 = nugetSha256;
        hash = nugetHash;
        installable = true;
    })
  ];
      };
    in
    args
    // {
      inherit
        pname
        version
        dotnet-runtime
        executables
        ;

      src = emptyDirectory;

      buildInputs = [ nupkg ];

      dotnetGlobalTool = true;

@@ -50,4 +68,12 @@ buildDotnetModule (args // {

        runHook postInstall
      '';
})

      passthru = {
        updateScript = ./update.sh;
        nupkg = nupkg;
      } // args.passthru or {};
    }
  )
    (if lib.isFunction fnOrAttrs then fnOrAttrs finalAttrs else fnOrAttrs)
)
+24 −0
Original line number Diff line number Diff line
#!/usr/bin/env nix-shell
#!nix-shell -I nixpkgs=./. -i bash -p curl jq nix common-updater-scripts
# shellcheck shell=bash

set -euo pipefail

attr=$UPDATE_NIX_ATTR_PATH

nixeval() {
    nix --extra-experimental-features nix-command eval --json --impure -f . "$1" | jq -r .
}

nugetName=$(nixeval "$attr.nupkg.pname")

# always skip prerelease versions for now
version=$(curl -fsSL "https://api.nuget.org/v3-flatcontainer/$nugetName/index.json" |
    jq -er '.versions | last(.[] | select(match("^[0-9]+\\.[0-9]+\\.[0-9]+$")))')

if [[ $version == $(nixeval "$attr.version") ]]; then
    echo "$attr" is already version "$version"
    exit 0
fi

update-source-version "$attr" "$version" --source-key=nupkg.src
+0 −5
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@
  lib,
  buildDotnetGlobalTool,
  dotnetCorePackages,
  nix-update-script,
}:
let
  inherit (dotnetCorePackages) sdk_8_0;
@@ -17,10 +16,6 @@ buildDotnetGlobalTool rec {
  dotnet-sdk = sdk_8_0;
  dotnet-runtime = sdk_8_0;

  passthru = {
    updateScript = nix-update-script { };
  };

  meta = {
    description = "Roslyn-based LSP language server for C#";
    mainProgram = "csharp-ls";
+2 −2
Original line number Diff line number Diff line
@@ -2,10 +2,10 @@

buildDotnetGlobalTool {
  pname = "csharpier";
  version = "0.29.1";
  version = "0.30.2";
  executables = "dotnet-csharpier";

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

  meta = with lib; {
    description = "Opinionated code formatter for C#";
+2 −2
Original line number Diff line number Diff line
@@ -2,9 +2,9 @@

buildDotnetGlobalTool {
  pname = "pbm";
  version = "1.3.2";
  version = "1.4.3";

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

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