at 24.11-pre 135 lines 4.0 kB view raw
1{ lib 2, stdenv 3, fetchurl 4, less 5, makeWrapper 6, autoPatchelfHook 7, curl 8, icu 9, libuuid 10, libunwind 11, openssl 12, darwin 13, lttng-ust 14, pam 15, testers 16, powershell 17, writeShellScript 18, common-updater-scripts 19, gnused 20, jq 21}: 22 23let 24 ext = stdenv.hostPlatform.extensions.sharedLibrary; 25 platformLdLibraryPath = { 26 darwin = "DYLD_FALLBACK_LIBRARY_PATH"; 27 linux = "LD_LIBRARY_PATH"; 28 }.${stdenv.hostPlatform.parsed.kernel.name} or (throw "unsupported platform"); 29in 30stdenv.mkDerivation rec { 31 pname = "powershell"; 32 version = "7.4.2"; 33 34 src = passthru.sources.${stdenv.hostPlatform.system} 35 or (throw "Unsupported system: ${stdenv.hostPlatform.system}"); 36 37 sourceRoot = "."; 38 39 strictDeps = true; 40 41 nativeBuildInputs = [ 42 less 43 makeWrapper 44 ] ++ lib.optionals stdenv.isLinux [ 45 autoPatchelfHook 46 ]; 47 48 buildInputs = [ 49 curl 50 icu 51 libuuid 52 libunwind 53 openssl 54 ] ++ lib.optionals stdenv.isDarwin [ 55 darwin.Libsystem 56 ] ++ lib.optionals stdenv.isLinux [ 57 lttng-ust 58 pam 59 ]; 60 61 installPhase = '' 62 runHook preInstall 63 64 mkdir -p $out/{bin,share/powershell} 65 cp -R * $out/share/powershell 66 chmod +x $out/share/powershell/pwsh 67 makeWrapper $out/share/powershell/pwsh $out/bin/pwsh \ 68 --prefix ${platformLdLibraryPath} : "${lib.makeLibraryPath buildInputs}" \ 69 --set TERM xterm \ 70 --set POWERSHELL_TELEMETRY_OPTOUT 1 \ 71 --set DOTNET_CLI_TELEMETRY_OPTOUT 1 72 73 '' + lib.optionalString stdenv.isLinux '' 74 patchelf --replace-needed liblttng-ust${ext}.0 liblttng-ust${ext}.1 $out/share/powershell/libcoreclrtraceptprovider.so 75 76 '' + '' 77 runHook postInstall 78 ''; 79 80 dontStrip = true; 81 82 passthru = { 83 shellPath = "/bin/pwsh"; 84 sources = { 85 aarch64-darwin = fetchurl { 86 url = "https://github.com/PowerShell/PowerShell/releases/download/v${version}/powershell-${version}-osx-arm64.tar.gz"; 87 hash = "sha256-Gg1wXIw/x/s0dgCkycZ4fC4eK+zIoduHr8nHvBOPFm4="; 88 }; 89 aarch64-linux = fetchurl { 90 url = "https://github.com/PowerShell/PowerShell/releases/download/v${version}/powershell-${version}-linux-arm64.tar.gz"; 91 hash = "sha256-AGAhaUqeDOliRX0jGJ48uIrgMIY7IhkH+PuJHflJeus="; 92 }; 93 x86_64-darwin = fetchurl { 94 url = "https://github.com/PowerShell/PowerShell/releases/download/v${version}/powershell-${version}-osx-x64.tar.gz"; 95 hash = "sha256-jH4XY/XjYljkVV4DlOq+f8lwWDcFGA7yaVFKgGUVz+I="; 96 }; 97 x86_64-linux = fetchurl { 98 url = "https://github.com/PowerShell/PowerShell/releases/download/v${version}/powershell-${version}-linux-x64.tar.gz"; 99 hash = "sha256-NmBdw3l53lry4QeDv3DArYFQUh6B5tfJMiA267iX5/4="; 100 }; 101 }; 102 tests.version = testers.testVersion { 103 package = powershell; 104 command = "HOME=$(mktemp -d) pwsh --version"; 105 }; 106 updateScript = writeShellScript "update-powershell" '' 107 set -o errexit 108 export PATH="${lib.makeBinPath [ common-updater-scripts curl gnused jq ]}" 109 NEW_VERSION=$(curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest | jq .tag_name --raw-output | sed -e 's/v//') 110 111 if [[ "${version}" = "$NEW_VERSION" ]]; then 112 echo "The new version same as the old version." 113 exit 0 114 fi 115 116 for platform in ${lib.escapeShellArgs meta.platforms}; do 117 update-source-version "powershell" "0" "${lib.fakeHash}" --source-key="sources.$platform" 118 update-source-version "powershell" "$NEW_VERSION" --source-key="sources.$platform" 119 done 120 ''; 121 }; 122 123 meta = with lib; { 124 description = "Powerful cross-platform (Windows, Linux, and macOS) shell and scripting language based on .NET"; 125 homepage = "https://microsoft.com/PowerShell"; 126 license = licenses.mit; 127 mainProgram = "pwsh"; 128 maintainers = with maintainers; [ wegank ]; 129 platforms = builtins.attrNames passthru.sources; 130 sourceProvenance = with sourceTypes; [ 131 binaryBytecode 132 binaryNativeCode 133 ]; 134 }; 135}