1{
2 lib,
3 stdenv,
4 python3,
5 fetchPypi,
6 src,
7 version,
8}:
9
10let
11 buildAzureCliPackage = with py.pkgs; buildPythonPackage;
12
13 overrideAzureMgmtPackage =
14 package: version: extension: hash:
15 package.overridePythonAttrs (oldAttrs: {
16 inherit version;
17
18 src = fetchPypi {
19 inherit (oldAttrs) pname;
20 inherit version hash extension;
21 };
22 });
23
24 py = python3.override {
25 self = py;
26 packageOverrides = self: super: {
27 inherit buildAzureCliPackage;
28
29 # core and the actual application are highly coupled
30 azure-cli-core = buildAzureCliPackage {
31 pname = "azure-cli-core";
32 format = "setuptools";
33 inherit version src;
34
35 sourceRoot = "${src.name}/src/azure-cli-core";
36
37 patches = [
38 # Adding the possibility to configure an immutable configuration dir via `AZURE_IMMUTABLE_DIR`.
39 # This enables us to place configuration files that alter the behavior of the CLI in the Nix store.
40 #
41 # This is a downstream patch without an commit or PR upstream.
42 # There is an issue to discuss possible solutions upstream:
43 # https://github.com/Azure/azure-cli/issues/28093
44 ./0001-optional-immutable-configuration-dir.patch
45 ];
46
47 propagatedBuildInputs =
48 with self;
49 [
50 argcomplete
51 azure-cli-telemetry
52 azure-common
53 azure-mgmt-core
54 cryptography
55 distro
56 humanfriendly
57 jmespath
58 knack
59 microsoft-security-utilities-secret-masker
60 msal-extensions
61 msal
62 msrestazure
63 packaging
64 paramiko
65 pkginfo
66 psutil
67 py-deviceid
68 pyjwt
69 pyopenssl
70 requests
71 ]
72 ++ requests.optional-dependencies.socks;
73
74 nativeCheckInputs = with self; [ pytest ];
75
76 doCheck = stdenv.hostPlatform.isLinux;
77
78 # ignore tests that does network call, or assume powershell
79 checkPhase = ''
80 python -c 'import azure.common; print(azure.common)'
81
82 PYTHONPATH=$PWD:${src}/src/azure-cli-testsdk:$PYTHONPATH HOME=$TMPDIR pytest \
83 azure/cli/core/tests \
84 --ignore=azure/cli/core/tests/test_profile.py \
85 --ignore=azure/cli/core/tests/test_generic_update.py \
86 --ignore=azure/cli/core/tests/test_cloud.py \
87 --ignore=azure/cli/core/tests/test_extension.py \
88 --ignore=azure/cli/core/tests/test_util.py \
89 --ignore=azure/cli/core/tests/test_argcomplete.py \
90 -k 'not metadata_url and not test_send_raw_requests and not test_format_styled_text_legacy_powershell'
91 '';
92
93 pythonImportsCheck = [
94 "azure.cli.telemetry"
95 "azure.cli.core"
96 ];
97
98 meta.downloadPage = "https://github.com/Azure/azure-cli/tree/azure-cli-${version}/src/azure-cli-core/";
99 };
100
101 azure-cli-telemetry = buildAzureCliPackage {
102 pname = "azure-cli-telemetry";
103 version = "1.1.0";
104 format = "setuptools";
105 inherit src;
106
107 sourceRoot = "${src.name}/src/azure-cli-telemetry";
108
109 propagatedBuildInputs = with self; [
110 applicationinsights
111 portalocker
112 ];
113
114 nativeCheckInputs = with self; [ pytest ];
115 # ignore flaky test
116 checkPhase = ''
117 cd azure
118 HOME=$TMPDIR pytest -k 'not test_create_telemetry_note_file_from_scratch'
119 '';
120
121 meta.downloadPage = "https://github.com/Azure/azure-cli/blob/azure-cli-${version}/src/azure-cli-telemetry/";
122 };
123
124 # Error loading command module 'batch': No module named 'azure.batch._model_base'
125 azure-batch = super.azure-batch.overridePythonAttrs (attrs: rec {
126 version = "15.0.0b1";
127 src = fetchPypi {
128 pname = "azure_batch"; # Different from src.pname in the original package.
129 inherit version;
130 hash = "sha256-373dFY/63lIZPj5NhsmW6nI2/9JpWkNzT65eBal04u0=";
131 };
132 });
133
134 azure-mgmt-billing =
135 (overrideAzureMgmtPackage super.azure-mgmt-billing "6.0.0" "zip"
136 "sha256-1PXFpBiKRW/h6zK2xF9VyiBpx0vkHrdpIYQLOfL1wH8="
137 ).overridePythonAttrs
138 (attrs: {
139 propagatedBuildInputs = attrs.propagatedBuildInputs or [ ] ++ [
140 self.msrest
141 self.msrestazure
142 ];
143 });
144
145 # AttributeError: type object 'CustomDomainsOperations' has no attribute 'disable_custom_https'
146 azure-mgmt-cdn =
147 overrideAzureMgmtPackage super.azure-mgmt-cdn "12.0.0" "zip"
148 "sha256-t8PuIYkjS0r1Gs4pJJJ8X9cz8950imQtbVBABnyMnd0=";
149
150 # ImportError: cannot import name 'ConfigMap' from 'azure.mgmt.containerinstance.models'
151 azure-mgmt-containerinstance = super.azure-mgmt-containerinstance.overridePythonAttrs (attrs: rec {
152 version = "10.2.0b1";
153 src = fetchPypi {
154 pname = "azure_mgmt_containerinstance"; # Different from src.pname in the original package.
155 inherit version;
156 hash = "sha256-v0u3e9ZoEnDdCnM6o6fD7N+suo5hbTqMO5jM6cSMx8A=";
157 };
158 });
159
160 # ImportError: cannot import name 'ResourceSku' from 'azure.mgmt.eventgrid.models'
161 azure-mgmt-eventgrid =
162 overrideAzureMgmtPackage super.azure-mgmt-eventgrid "10.2.0b2" "zip"
163 "sha256-QcHY1wCwQyVOEdUi06/wEa4dqJH5Ccd33gJ1Sju0qZA=";
164
165 # ValueError: The operation 'azure.mgmt.hdinsight.operations#ExtensionsOperations.get_azure_monitor_agent_status' is invalid.
166 azure-mgmt-hdinsight =
167 overrideAzureMgmtPackage super.azure-mgmt-hdinsight "9.0.0b3" "tar.gz"
168 "sha256-clSeCP8+7T1uI4Nec+zhzDK980C9+JGeeJFsNSwgD2Q=";
169
170 # ValueError: The operation 'azure.mgmt.media.operations#MediaservicesOperations.create_or_update' is invalid.
171 azure-mgmt-media =
172 overrideAzureMgmtPackage super.azure-mgmt-media "9.0.0" "zip"
173 "sha256-TI7l8sSQ2QUgPqiE3Cu/F67Wna+KHbQS3fuIjOb95ZM=";
174
175 # ModuleNotFoundError: No module named 'azure.mgmt.monitor.operations'
176 azure-mgmt-monitor = super.azure-mgmt-monitor.overridePythonAttrs (attrs: rec {
177 version = "7.0.0b1";
178 src = fetchPypi {
179 pname = "azure_mgmt_monitor"; # Different from src.pname in the original package.
180 inherit version;
181 hash = "sha256-WR4YZMw4njklpARkujsRnd6nwTZ8M5vXFcy9AfL9oj4=";
182 };
183 });
184
185 # AttributeError: module 'azure.mgmt.rdbms.postgresql_flexibleservers.operations' has no attribute 'BackupsOperations'
186 azure-mgmt-rdbms =
187 overrideAzureMgmtPackage super.azure-mgmt-rdbms "10.2.0b17" "tar.gz"
188 "sha256-1nnRkyr4Im79B7DDqGz/FOrPAToFaGhE+a7r5bZMuOQ=";
189
190 # ModuleNotFoundError: No module named 'azure.mgmt.redhatopenshift.v2023_11_22'
191 azure-mgmt-redhatopenshift =
192 overrideAzureMgmtPackage super.azure-mgmt-redhatopenshift "1.5.0" "tar.gz"
193 "sha256-Uft0KcOciKzJ+ic9n4nxkwNSBmKZam19jhEiqY9fJSc=";
194
195 # azure.mgmt.resource will shadow the other azure.mgmt.resource.* packages unless we merge them together
196 azure-mgmt-resource-all = py.pkgs.buildPythonPackage {
197 pname = "azure-mgmt-resource-all";
198 inherit version;
199
200 format = "other"; # we're not building from sdist/wheel
201
202 src = py.pkgs.azure-mgmt-resource.src;
203
204 # No real build, just symlink all site-packages into one dir
205 installPhase = ''
206 runHook preInstall
207
208 mkdir -p $out/${py.sitePackages}
209 for pkg in ${
210 lib.concatStringsSep " " (
211 map (p: "${p}") [
212 py.pkgs.azure-mgmt-resource
213 py.pkgs.azure-mgmt-resource-deployments
214 py.pkgs.azure-mgmt-resource-deploymentscripts
215 py.pkgs.azure-mgmt-resource-deploymentstacks
216 py.pkgs.azure-mgmt-resource-templatespecs
217 ]
218 )
219 }; do
220 # Copy recursively, keep symlinks, skip duplicates silently
221 cp -rs --no-preserve=mode "$pkg/${py.sitePackages}/." "$out/${py.sitePackages}/" || true
222 done
223
224 runHook postInstall
225 '';
226
227 doCheck = false;
228 };
229
230 # ImportError: cannot import name 'IPRule' from 'azure.mgmt.signalr.models'
231 azure-mgmt-signalr =
232 overrideAzureMgmtPackage super.azure-mgmt-signalr "2.0.0b2" "tar.gz"
233 "sha256-05PUV8ouAKq/xhGxVEWIzDop0a7WDTV5mGVSC4sv9P4=";
234
235 # ImportError: cannot import name 'AdvancedThreatProtectionName' from 'azure.mgmt.sql.models'
236 azure-mgmt-sql = super.azure-mgmt-sql.overridePythonAttrs (attrs: rec {
237 version = "4.0.0b20";
238 src = fetchPypi {
239 pname = "azure_mgmt_sql"; # Different from src.pname in the original package.
240 inherit version;
241 hash = "sha256-mphqHUet4AhmL8aUoRbrGOjbookCHR3Ex+unpOq7aQM=";
242 };
243 });
244
245 # ValueError: The operation 'azure.mgmt.sqlvirtualmachine.operations#SqlVirtualMachinesOperations.begin_create_or_update' is invalid.
246 azure-mgmt-sqlvirtualmachine =
247 overrideAzureMgmtPackage super.azure-mgmt-sqlvirtualmachine "1.0.0b5" "zip"
248 "sha256-ZFgJflgynRSxo+B+Vso4eX1JheWlDQjfJ9QmupXypMc=";
249
250 # ModuleNotFoundError: No module named 'azure.mgmt.synapse.operations._kusto_pool_attached_database_configurations_operations'
251 azure-mgmt-synapse =
252 overrideAzureMgmtPackage super.azure-mgmt-synapse "2.1.0b5" "zip"
253 "sha256-5E6Yf1GgNyNVjd+SeFDbhDxnOA6fOAG6oojxtCP4m+k=";
254
255 # Observed error during runtime:
256 # AttributeError: Can't get attribute 'NormalizedResponse' on <module 'msal.throttled_http_client' from
257 # '/nix/store/xxx-python3.12-msal-1.32.0/lib/python3.12/site-packages/msal/throttled_http_client.py'>.
258 # Did you mean: '_msal_public_app_kwargs'?
259 msal =
260 overrideAzureMgmtPackage super.msal "1.32.3" "tar.gz"
261 "sha256-XuoDhonHilpwyo7L4SRUWLVahXvQlu+2mJxpuhWYXTU=";
262 };
263 };
264in
265py