at 23.05-pre 91 lines 3.6 kB view raw
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-bcLyf/sIaFoS1xS4RLPPC9lVFa94IfQlWeXhyXUTsd0=" 11 else if (stdenv.isDarwin && stdenv.isAarch64) then "sha256-2UACjUtyQ611iXmwyiWrGwRVA0FT1cLLMKnY0y4SgoQ=" 12 else if (stdenv.isLinux && stdenv.isx86_64) then "sha256-5AZGwxpEqn3X20rCxPcvuqcQib689ui+e0jvri92EdA=" 13 else if (stdenv.isLinux && stdenv.isAarch64) then "sha256-90Sz32hm+EcK3nFJOGGCSqIEtW7w48G8mizXvcLb8WU=" 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.4"; 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 strictDeps = true; 32 buildInputs = [ less ] ++ libraries; 33 nativeBuildInputs = [ makeWrapper ] 34 ++ lib.optional stdenv.isLinux autoPatchelfHook; 35 36 installPhase = 37 let 38 ext = stdenv.hostPlatform.extensions.sharedLibrary; 39 in '' 40 pslibs=$out/share/powershell 41 mkdir -p $pslibs 42 43 cp -r * $pslibs 44 45 rm -f $pslibs/libcrypto${ext}.1.0.0 46 rm -f $pslibs/libssl${ext}.1.0.0 47 48 # At least the 7.1.4-osx package does not have the executable bit set. 49 chmod a+x $pslibs/pwsh 50 51 ls $pslibs 52 '' + lib.optionalString (!stdenv.isDarwin && !stdenv.isAarch64) '' 53 patchelf --replace-needed libcrypto${ext}.1.0.0 libcrypto${ext}.1.1 $pslibs/libmi.so 54 patchelf --replace-needed libssl${ext}.1.0.0 libssl${ext}.1.1 $pslibs/libmi.so 55 '' + lib.optionalString (!stdenv.isDarwin) '' 56 patchelf --replace-needed liblttng-ust${ext}.0 liblttng-ust${ext}.1 $pslibs/libcoreclrtraceptprovider.so 57 '' + '' 58 59 mkdir -p $out/bin 60 61 makeWrapper $pslibs/pwsh $out/bin/pwsh \ 62 --prefix ${platformLdLibraryPath} : "${lib.makeLibraryPath libraries}" \ 63 --set TERM xterm --set POWERSHELL_TELEMETRY_OPTOUT 1 --set DOTNET_CLI_TELEMETRY_OPTOUT 1 64 ''; 65 66 dontStrip = true; 67 68 doInstallCheck = true; 69 installCheckPhase = '' 70 # May need a writable home, seen on Darwin. 71 HOME=$TMP $out/bin/pwsh --help > /dev/null 72 ''; 73 74 meta = with lib; { 75 description = "Powerful cross-platform (Windows, Linux, and macOS) shell and scripting language based on .NET"; 76 homepage = "https://github.com/PowerShell/PowerShell"; 77 sourceProvenance = with sourceTypes; [ 78 binaryBytecode 79 binaryNativeCode 80 ]; 81 maintainers = with maintainers; [ yrashk srgom p3psi ]; 82 mainProgram = "pwsh"; 83 platforms = [ "x86_64-darwin" "x86_64-linux" "aarch64-linux" "aarch64-darwin" ]; 84 license = with licenses; [ mit ]; 85 }; 86 87 passthru = { 88 shellPath = "/bin/pwsh"; 89 }; 90 91}