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