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.3.9";
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 && stdenv.isx86_64) ''
74 patchelf --replace-needed libcrypto${ext}.1.0.0 libcrypto${ext} $out/share/powershell/libmi.so
75 patchelf --replace-needed libssl${ext}.1.0.0 libssl${ext} $out/share/powershell/libmi.so
76
77 '' + lib.optionalString stdenv.isLinux ''
78 patchelf --replace-needed liblttng-ust${ext}.0 liblttng-ust${ext}.1 $out/share/powershell/libcoreclrtraceptprovider.so
79
80 '' + ''
81 runHook postInstall
82 '';
83
84 dontStrip = true;
85
86 passthru = {
87 shellPath = "/bin/pwsh";
88 sources = {
89 aarch64-darwin = fetchurl {
90 url = "https://github.com/PowerShell/PowerShell/releases/download/v${version}/powershell-${version}-osx-arm64.tar.gz";
91 hash = "sha256-g63hMkJUIYFpSl9NylCQs0WYdq/8S3UaFVtRjhZOs+s=";
92 };
93 aarch64-linux = fetchurl {
94 url = "https://github.com/PowerShell/PowerShell/releases/download/v${version}/powershell-${version}-linux-arm64.tar.gz";
95 hash = "sha256-zy6VZyXj9TV5QlVFnCgiB6XfIOyS79kPOFhvMRpOrP4=";
96 };
97 x86_64-darwin = fetchurl {
98 url = "https://github.com/PowerShell/PowerShell/releases/download/v${version}/powershell-${version}-osx-x64.tar.gz";
99 hash = "sha256-DI+m3Ik1Zw293H6VR19DNAECBApqdIENlrK2/D/3vNc=";
100 };
101 x86_64-linux = fetchurl {
102 url = "https://github.com/PowerShell/PowerShell/releases/download/v${version}/powershell-${version}-linux-x64.tar.gz";
103 hash = "sha256-eHlh46eV+g3eCiKalVGixwKY9mlk2lXRwUJF6By5lP0=";
104 };
105 };
106 tests.version = testers.testVersion {
107 package = powershell;
108 command = "HOME=$(mktemp -d) pwsh --version";
109 };
110 updateScript = writeShellScript "update-powershell" ''
111 set -o errexit
112 export PATH="${lib.makeBinPath [ common-updater-scripts curl gnused jq ]}"
113 NEW_VERSION=$(curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest | jq .tag_name --raw-output | sed -e 's/v//')
114
115 if [[ "${version}" = "$NEW_VERSION" ]]; then
116 echo "The new version same as the old version."
117 exit 0
118 fi
119
120 for platform in ${lib.escapeShellArgs meta.platforms}; do
121 update-source-version "powershell" "0" "${lib.fakeHash}" --source-key="sources.$platform"
122 update-source-version "powershell" "$NEW_VERSION" --source-key="sources.$platform"
123 done
124 '';
125 };
126
127 meta = with lib; {
128 description = "Powerful cross-platform (Windows, Linux, and macOS) shell and scripting language based on .NET";
129 homepage = "https://microsoft.com/PowerShell";
130 license = licenses.mit;
131 mainProgram = "pwsh";
132 maintainers = with maintainers; [ wegank ];
133 platforms = builtins.attrNames passthru.sources;
134 sourceProvenance = with sourceTypes; [
135 binaryBytecode
136 binaryNativeCode
137 ];
138 };
139}