at 24.11-pre 381 lines 10 kB view raw
1{ lib 2, callPackage 3, callPackages 4, stdenvNoCC 5, fetchurl 6, fetchFromGitHub 7, installShellFiles 8, python3 9 10 # Whether to include patches that enable placing certain behavior-defining 11 # configuration files in the Nix store. 12, withImmutableConfig ? true 13 14 # List of extensions/plugins to include. 15, withExtensions ? [ ] 16 17, azure-cli 18}: 19 20let 21 version = "2.60.0"; 22 23 src = fetchFromGitHub { 24 name = "azure-cli-${version}-src"; 25 owner = "Azure"; 26 repo = "azure-cli"; 27 rev = "azure-cli-${version}"; 28 hash = "sha256-rQwjcp6MsqhP+o+Hpvt4CFC4ygqsIaRIQOxWKca5Hq8="; 29 }; 30 31 # put packages that needs to be overridden in the py package scope 32 py = callPackage ./python-packages.nix { inherit src version; }; 33 34 # Builder for Azure CLI extensions. Extensions are Python wheels that 35 # outside of nix would be fetched by the CLI itself from various sources. 36 mkAzExtension = 37 { pname 38 , version 39 , url 40 , sha256 41 , description 42 , ... 43 }@args: python3.pkgs.buildPythonPackage ({ 44 format = "wheel"; 45 src = fetchurl { inherit url sha256; }; 46 meta = with lib; { 47 inherit description; 48 inherit (azure-cli.meta) platforms maintainers; 49 homepage = "https://github.com/Azure/azure-cli-extensions"; 50 changelog = "https://github.com/Azure/azure-cli-extensions/blob/main/src/${pname}/HISTORY.rst"; 51 license = lib.licenses.mit; 52 sourceProvenance = [ sourceTypes.fromSource ]; 53 }; 54 } // (removeAttrs args [ "url" "sha256" "description" ])); 55 56 extensions = 57 callPackages ./extensions-generated.nix { inherit mkAzExtension; } 58 // callPackages ./extensions-manual.nix { inherit mkAzExtension; }; 59 60 extensionDir = stdenvNoCC.mkDerivation { 61 name = "azure-cli-extensions"; 62 dontUnpack = true; 63 installPhase = 64 let 65 namePaths = map (p: "${p.pname},${p}/${python3.sitePackages}") withExtensions; 66 in 67 '' 68 for line in ${lib.concatStringsSep " " namePaths}; do 69 name=$(echo $line | cut -d',' -f1) 70 path=$(echo $line | cut -d',' -f2) 71 mkdir -p $out/$name 72 for f in $(ls $path); do 73 ln -s $path/$f $out/$name/$f 74 done 75 done 76 ''; 77 }; 78in 79 80py.pkgs.toPythonApplication (py.pkgs.buildAzureCliPackage rec { 81 pname = "azure-cli"; 82 inherit version src; 83 84 sourceRoot = "${src.name}/src/azure-cli"; 85 86 nativeBuildInputs = [ 87 installShellFiles 88 ]; 89 90 propagatedBuildInputs = with py.pkgs; [ 91 antlr4-python3-runtime 92 applicationinsights 93 argcomplete 94 asn1crypto 95 azure-appconfiguration 96 azure-batch 97 azure-cli-core 98 azure-cli-telemetry 99 azure-common 100 azure-core 101 azure-cosmos 102 azure-data-tables 103 azure-datalake-store 104 azure-graphrbac 105 azure-keyvault-administration 106 azure-keyvault-certificates 107 azure-keyvault-keys 108 azure-keyvault-secrets 109 azure-loganalytics 110 azure-mgmt-advisor 111 azure-mgmt-apimanagement 112 azure-mgmt-appconfiguration 113 azure-mgmt-appcontainers 114 azure-mgmt-applicationinsights 115 azure-mgmt-authorization 116 azure-mgmt-batch 117 azure-mgmt-batchai 118 azure-mgmt-billing 119 azure-mgmt-botservice 120 azure-mgmt-cdn 121 azure-mgmt-cognitiveservices 122 azure-mgmt-compute 123 azure-mgmt-consumption 124 azure-mgmt-containerinstance 125 azure-mgmt-containerregistry 126 azure-mgmt-containerservice 127 azure-mgmt-core 128 azure-mgmt-cosmosdb 129 azure-mgmt-databoxedge 130 azure-mgmt-datalake-nspkg 131 azure-mgmt-datalake-store 132 azure-mgmt-datamigration 133 azure-mgmt-devtestlabs 134 azure-mgmt-dns 135 azure-mgmt-eventgrid 136 azure-mgmt-eventhub 137 azure-mgmt-extendedlocation 138 azure-mgmt-hdinsight 139 azure-mgmt-imagebuilder 140 azure-mgmt-iotcentral 141 azure-mgmt-iothub 142 azure-mgmt-iothubprovisioningservices 143 azure-mgmt-keyvault 144 azure-mgmt-kusto 145 azure-mgmt-loganalytics 146 azure-mgmt-managementgroups 147 azure-mgmt-managedservices 148 azure-mgmt-maps 149 azure-mgmt-marketplaceordering 150 azure-mgmt-media 151 azure-mgmt-monitor 152 azure-mgmt-msi 153 azure-mgmt-netapp 154 azure-mgmt-policyinsights 155 azure-mgmt-privatedns 156 azure-mgmt-rdbms 157 azure-mgmt-recoveryservices 158 azure-mgmt-recoveryservicesbackup 159 azure-mgmt-redhatopenshift 160 azure-mgmt-redis 161 azure-mgmt-relay 162 azure-mgmt-resource 163 azure-mgmt-search 164 azure-mgmt-security 165 azure-mgmt-servicebus 166 azure-mgmt-servicefabric 167 azure-mgmt-servicefabricmanagedclusters 168 azure-mgmt-servicelinker 169 azure-mgmt-sql 170 azure-mgmt-signalr 171 azure-mgmt-sqlvirtualmachine 172 azure-mgmt-storage 173 azure-mgmt-synapse 174 azure-mgmt-trafficmanager 175 azure-mgmt-web 176 azure-multiapi-storage 177 azure-nspkg 178 azure-storage-common 179 azure-storage-blob 180 azure-synapse-accesscontrol 181 azure-synapse-artifacts 182 azure-synapse-managedprivateendpoints 183 azure-synapse-spark 184 bcrypt 185 certifi 186 cffi 187 chardet 188 colorama 189 cryptography 190 distro 191 fabric 192 humanfriendly 193 idna 194 invoke 195 isodate 196 javaproperties 197 jinja2 198 jmespath 199 jsondiff 200 knack 201 markupsafe 202 msal-extensions 203 msal 204 msrest 205 msrestazure 206 oauthlib 207 packaging 208 paramiko 209 pbr 210 pkginfo 211 portalocker 212 psutil 213 pycomposefile 214 pycparser 215 pygithub 216 pyjwt 217 pynacl 218 pyopenssl 219 python-dateutil 220 requests-oauthlib 221 requests 222 scp 223 semver 224 setuptools 225 six 226 sshtunnel 227 tabulate 228 urllib3 229 wcwidth 230 websocket-client 231 xmltodict 232 ] ++ lib.optionals (!withImmutableConfig) [ 233 # pip is required to install extensions locally, but it's not needed if 234 # we're using the default immutable configuration. 235 pip 236 ]; 237 238 postInstall = '' 239 substituteInPlace az.completion.sh \ 240 --replace register-python-argcomplete ${py.pkgs.argcomplete}/bin/register-python-argcomplete 241 installShellCompletion --bash --name az.bash az.completion.sh 242 installShellCompletion --zsh --name _az az.completion.sh 243 '' + lib.optionalString withImmutableConfig '' 244 export HOME=$TMPDIR 245 $out/bin/az --version 246 mkdir -p $out/etc/azure 247 mv $TMPDIR/.azure/commandIndex.json $out/etc/azure/commandIndex.json 248 mv $TMPDIR/.azure/versionCheck.json $out/etc/azure/versionCheck.json 249 '' + '' 250 # remove garbage 251 rm $out/bin/az.bat 252 rm $out/bin/az.completion.sh 253 ''; 254 255 # wrap the executable so that the python packages are available 256 # it's just a shebang script which calls `python -m azure.cli "$@"` 257 postFixup = '' 258 wrapProgram $out/bin/az \ 259 '' + lib.optionalString withImmutableConfig '' 260 --set AZURE_IMMUTABLE_DIR $out/etc/azure \ 261 '' + lib.optionalString (withExtensions != [ ]) '' 262 --set AZURE_EXTENSION_DIR ${extensionDir} \ 263 '' + '' 264 --set PYTHONPATH "${python3.pkgs.makePythonPath propagatedBuildInputs}:$out/${python3.sitePackages}" 265 ''; 266 267 doInstallCheck = true; 268 installCheckPhase = '' 269 export HOME=$TMPDIR 270 271 $out/bin/az --version 272 $out/bin/az self-test 273 ''; 274 275 # ensure these namespaces are able to be accessed 276 pythonImportsCheck = [ 277 "azure.batch" 278 "azure.cli.core" 279 "azure.cli.telemetry" 280 "azure.cosmos" 281 "azure.datalake.store" 282 "azure.graphrbac" 283 "azure.keyvault" 284 "azure.loganalytics" 285 "azure.mgmt.advisor" 286 "azure.mgmt.apimanagement" 287 "azure.mgmt.applicationinsights" 288 "azure.mgmt.appconfiguration" 289 "azure.mgmt.appcontainers" 290 "azure.mgmt.authorization" 291 "azure.mgmt.batch" 292 "azure.mgmt.batchai" 293 "azure.mgmt.billing" 294 "azure.mgmt.botservice" 295 "azure.mgmt.cdn" 296 "azure.mgmt.cognitiveservices" 297 "azure.mgmt.compute" 298 "azure.mgmt.consumption" 299 "azure.mgmt.containerinstance" 300 "azure.mgmt.containerregistry" 301 "azure.mgmt.containerservice" 302 "azure.mgmt.cosmosdb" 303 "azure.mgmt.datalake.store" 304 "azure.mgmt.datamigration" 305 "azure.mgmt.devtestlabs" 306 "azure.mgmt.dns" 307 "azure.mgmt.eventgrid" 308 "azure.mgmt.eventhub" 309 "azure.mgmt.hdinsight" 310 "azure.mgmt.imagebuilder" 311 "azure.mgmt.iotcentral" 312 "azure.mgmt.iothub" 313 "azure.mgmt.iothubprovisioningservices" 314 "azure.mgmt.keyvault" 315 "azure.mgmt.kusto" 316 "azure.mgmt.loganalytics" 317 "azure.mgmt.managedservices" 318 "azure.mgmt.managementgroups" 319 "azure.mgmt.maps" 320 "azure.mgmt.marketplaceordering" 321 "azure.mgmt.media" 322 "azure.mgmt.monitor" 323 "azure.mgmt.msi" 324 "azure.mgmt.netapp" 325 "azure.mgmt.policyinsights" 326 "azure.mgmt.privatedns" 327 "azure.mgmt.rdbms" 328 "azure.mgmt.recoveryservices" 329 "azure.mgmt.recoveryservicesbackup" 330 "azure.mgmt.redis" 331 "azure.mgmt.relay" 332 "azure.mgmt.resource" 333 "azure.mgmt.search" 334 "azure.mgmt.security" 335 "azure.mgmt.servicebus" 336 "azure.mgmt.servicefabric" 337 "azure.mgmt.signalr" 338 "azure.mgmt.sql" 339 "azure.mgmt.sqlvirtualmachine" 340 "azure.mgmt.storage" 341 "azure.mgmt.trafficmanager" 342 "azure.mgmt.web" 343 "azure.storage.blob" 344 "azure.storage.common" 345 ]; 346 347 passthru = { 348 inherit extensions; 349 withExtensions = extensions: azure-cli.override { withExtensions = extensions; }; 350 }; 351 352 meta = with lib; { 353 homepage = "https://github.com/Azure/azure-cli"; 354 description = "Next generation multi-platform command line experience for Azure"; 355 downloadPage = "https://github.com/Azure/azure-cli/releases/tag/azure-cli-${version}"; 356 longDescription = '' 357 The Azure Command-Line Interface (CLI) is a cross-platform 358 command-line tool to connect to Azure and execute administrative 359 commands on Azure resources. It allows the execution of commands 360 through a terminal using interactive command-line prompts or a script. 361 362 `azure-cli` has extension support. For example, to install the `aks-preview` extension, use 363 364 ```nix 365 environment.systemPackages = [ 366 (azure-cli.withExtensions [ azure-cli.extensions.aks-preview ]) 367 ]; 368 ``` 369 370 To make the `azure-cli` immutable and prevent clashes in case `azure-cli` is also installed via other package managers, 371 some configuration files were moved into the derivation. This can be disabled by overriding `withImmutableConfig = false` 372 when building `azure-cli`. 373 ''; 374 changelog = "https://github.com/MicrosoftDocs/azure-docs-cli/blob/main/docs-ref-conceptual/release-notes-azure-cli.md"; 375 sourceProvenance = [ sourceTypes.fromSource ]; 376 license = licenses.mit; 377 mainProgram = "az"; 378 maintainers = with maintainers; [ jonringer ]; 379 platforms = platforms.all; 380 }; 381})