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