about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/backup/discordchatexporter-cli/default.nix
blob: 9cf489c4db5d2cc8fa0c2f26abad116263da1822 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{ lib, stdenv, fetchFromGitHub, fetchurl, linkFarmFromDrvs, makeWrapper, autoPatchelfHook
, dotnet-sdk_5, dotnetPackages, dotnetCorePackages, cacert
}:

let
  projectFile = "DiscordChatExporter.Cli/DiscordChatExporter.Cli.csproj";
in
stdenv.mkDerivation rec {
  pname = "discordchatexporter-cli";
  version = "2.30";

  src = fetchFromGitHub {
    owner = "tyrrrz";
    repo = "discordchatexporter";
    rev = version;
    sha256 = "uTOeRsEab4vaAwtfysUTM3xFP5UMxpUQnuuU8hv3nk8=";
  };

  nativeBuildInputs = [ dotnet-sdk_5 dotnetPackages.Nuget cacert makeWrapper autoPatchelfHook ];
  buildInputs = [ stdenv.cc.cc.lib ];

  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;
    };
  });

  configurePhase = ''
    runHook preConfigure

    export HOME=$(mktemp -d)
    export DOTNET_CLI_TELEMETRY_OPTOUT=1
    export DOTNET_NOLOGO=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

    dotnet restore --source "$PWD/nixos" ${projectFile}

    runHook postConfigure
  '';

  buildPhase = ''
    runHook preBuild

    dotnet build ${projectFile} \
      --no-restore \
      --configuration Release \
      -p:Version=${version}

    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall

    dotnet publish ${projectFile} \
      --no-build \
      --configuration Release \
      --no-self-contained \
      --output $out/lib/${pname}
    shopt -s extglob

    makeWrapper $out/lib/${pname}/DiscordChatExporter.Cli $out/bin/discordchatexporter-cli \
      --set DOTNET_ROOT "${dotnetCorePackages.sdk_3_1}"

    runHook postInstall
  '';

  # Strip breaks the executable.
  dontStrip = true;

  meta = with lib; {
    description = "A tool to export Discord chat logs to a file";
    homepage = "https://github.com/Tyrrrz/DiscordChatExporter";
    license = licenses.gpl3Plus;
    maintainers = [ maintainers.ivar ];
    platforms = [ "x86_64-linux" ];
  };
  passthru.updateScript = ./updater.sh;
}