Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ stdenv, lib, autoPatchelfHook, fetchurl, libunwind, libuuid, icu, curl 2, darwin, makeWrapper, less, openssl, 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 platformHash = { 11 x86_64-darwin = "sha256-FX3OyVzwU+Ms2tgjpZ4dPdjeJx2H5541dQZAjhI3n1U="; 12 aarch64-darwin = "sha256-Dg7FRF5inRnzP6tjDhIgHTJ1J2EQXnegqimZPK574WQ="; 13 x86_64-linux = "sha256-6F1VROE6kk+LLEpdwtQ6vkbkZjP4no0TjTnAqurLmXY="; 14 aarch64-linux = "sha256-NO4E2TOUIYyUFJmi3zKJzOyP0/rTPTZgJZcebVNkSfk="; 15 }.${stdenv.hostPlatform.system} or (throw "unsupported platform"); 16 platformLdLibraryPath = if stdenv.isDarwin then "DYLD_FALLBACK_LIBRARY_PATH" 17 else if stdenv.isLinux then "LD_LIBRARY_PATH" 18 else throw "unsupported platform"; 19 libraries = [ libunwind libuuid icu curl openssl ] ++ 20 (if stdenv.isLinux then [ pam lttng-ust ] else [ darwin.Libsystem ]); 21in 22stdenv.mkDerivation rec { 23 pname = "powershell"; 24 version = "7.3.4"; 25 26 src = fetchurl { 27 url = "https://github.com/PowerShell/PowerShell/releases/download/v${version}/powershell-${version}-${platformString}-${archString}.tar.gz"; 28 hash = platformHash; 29 }; 30 31 sourceRoot = "."; 32 33 strictDeps = true; 34 buildInputs = [ less ] ++ libraries; 35 nativeBuildInputs = [ makeWrapper ] 36 ++ lib.optional stdenv.isLinux autoPatchelfHook; 37 38 installPhase = 39 let 40 ext = stdenv.hostPlatform.extensions.sharedLibrary; 41 in '' 42 pslibs=$out/share/powershell 43 mkdir -p $pslibs 44 45 cp -r * $pslibs 46 47 # At least the 7.1.4-osx package does not have the executable bit set. 48 chmod a+x $pslibs/pwsh 49 50 '' + lib.optionalString (stdenv.isLinux && stdenv.isx86_64) '' 51 patchelf --replace-needed libcrypto${ext}.1.0.0 libcrypto${ext} $pslibs/libmi.so 52 patchelf --replace-needed libssl${ext}.1.0.0 libssl${ext} $pslibs/libmi.so 53 '' + lib.optionalString stdenv.isLinux '' 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 sourceProvenance = with sourceTypes; [ 76 binaryBytecode 77 binaryNativeCode 78 ]; 79 maintainers = with maintainers; [ yrashk srgom p3psi ]; 80 mainProgram = "pwsh"; 81 platforms = [ "x86_64-darwin" "x86_64-linux" "aarch64-linux" "aarch64-darwin" ]; 82 license = with licenses; [ mit ]; 83 }; 84 85 passthru = { 86 shellPath = "/bin/pwsh"; 87 }; 88 89}