Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at 22.05 87 lines 3.5 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-VF8C9JXVureJnMTyQD4SDeq/whyQOpk1dFtu6cJQRO8=" 11 else if (stdenv.isDarwin && stdenv.isAarch64) then "sha256-WqQQFdFTgIGi0fEtHjHf2rtP2l5YqdMQZH09O+34JTo=" 12 else if (stdenv.isLinux && stdenv.isx86_64) then "sha256-oKlX6NfTOxrxMkH+vWGMMTyVJqD2F2CB5qx+8EvNBE8=" 13 else if (stdenv.isLinux && stdenv.isAarch64) then "sha256-sWOmylDyy6n8SbnVDY5+wSJ2PPEd+vuoxbMU2iECyxY=" 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.3"; 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 maintainers = with maintainers; [ yrashk srgom p3psi ]; 78 mainProgram = "pwsh"; 79 platforms = [ "x86_64-darwin" "x86_64-linux" "aarch64-linux" "aarch64-darwin" ]; 80 license = with licenses; [ mit ]; 81 }; 82 83 passthru = { 84 shellPath = "/bin/pwsh"; 85 }; 86 87}