1{ stdenv, lib, autoPatchelfHook, fetchzip, libunwind, libuuid, icu, curl
2, darwin, makeWrapper, less, openssl_1_1, pam, lttng-ust }:
3
4let platformString = if stdenv.isDarwin then "osx"
5 else if stdenv.isLinux then "linux"
6 else throw "unsupported platform";
7 platformSha = if stdenv.isDarwin then "0c71w6z6sc86si07i6vy4w3069jal7476wyiizyr7qjm9m22963f"
8 else if stdenv.isLinux then "14d6nhv525pa8pi4p1r2mn180isfzgshqrbmql3qd55aksjpq1v0"
9 else throw "unsupported platform";
10 platformLdLibraryPath = if stdenv.isDarwin then "DYLD_FALLBACK_LIBRARY_PATH"
11 else if stdenv.isLinux then "LD_LIBRARY_PATH"
12 else throw "unsupported platform";
13 libraries = [ libunwind libuuid icu curl openssl_1_1 ] ++
14 (if stdenv.isLinux then [ pam lttng-ust ] else [ darwin.Libsystem ]);
15in
16stdenv.mkDerivation rec {
17 pname = "powershell";
18 version = "7.0.1";
19
20 src = fetchzip {
21 url = "https://github.com/PowerShell/PowerShell/releases/download/v${version}/powershell-${version}-${platformString}-x64.tar.gz";
22 sha256 = platformSha;
23 stripRoot = false;
24 };
25
26 buildInputs = [ less ] ++ libraries;
27 nativeBuildInputs = [ autoPatchelfHook makeWrapper ];
28
29 installPhase =
30 let
31 ext = stdenv.hostPlatform.extensions.sharedLibrary;
32 in ''
33 pslibs=$out/share/powershell
34 mkdir -p $pslibs
35
36 cp -r * $pslibs
37
38 rm -f $pslibs/libcrypto${ext}.1.0.0
39 rm -f $pslibs/libssl${ext}.1.0.0
40
41 ls $pslibs
42 '' + lib.optionalString (!stdenv.isDarwin) ''
43 patchelf --replace-needed libcrypto${ext}.1.0.0 libcrypto${ext}.1.1 $pslibs/libmi.so
44 patchelf --replace-needed libssl${ext}.1.0.0 libssl${ext}.1.1 $pslibs/libmi.so
45 '' + ''
46
47 mkdir -p $out/bin
48
49 makeWrapper $pslibs/pwsh $out/bin/pwsh \
50 --prefix ${platformLdLibraryPath} : "${stdenv.lib.makeLibraryPath libraries}" \
51 --set TERM xterm --set POWERSHELL_TELEMETRY_OPTOUT 1 --set DOTNET_CLI_TELEMETRY_OPTOUT 1
52 '';
53
54 dontStrip = true;
55
56 doInstallCheck = true;
57 installCheckPhase = ''
58 $out/bin/pwsh --help > /dev/null
59 '';
60
61 meta = with lib; {
62 description = "Powerful cross-platform (Windows, Linux, and macOS) shell and scripting language based on .NET";
63 homepage = "https://github.com/PowerShell/PowerShell";
64 maintainers = with maintainers; [ yrashk srgom ];
65 platforms = [ "x86_64-darwin" "x86_64-linux" ];
66 license = with licenses; [ mit ];
67 };
68
69 passthru = {
70 shellPath = "/bin/pwsh";
71 };
72
73}