18 # Whether to include patches that enable placing certain behavior-defining
19 # configuration files in the Nix store.
20 withImmutableConfig ? true,
22 # List of extensions/plugins to include.
31 src = fetchFromGitHub {
32 name = "azure-cli-${version}-src";
35 rev = "azure-cli-${version}";
36 hash = "sha256-IeiAB0AI6KNpXwx2Iv55LBARcwemakbblFlbfLheuGE=";
39 # put packages that needs to be overridden in the py package scope
40 py = callPackage ./python-packages.nix { inherit src version python3; };
42 # Builder for Azure CLI extensions. Extensions are Python wheels that
43 # outside of nix would be fetched by the CLI itself from various sources.
53 python3.pkgs.buildPythonPackage (
56 src = fetchurl { inherit url hash; };
59 inherit (azure-cli.meta) platforms maintainers;
60 homepage = "https://github.com/Azure/azure-cli-extensions";
61 changelog = "https://github.com/Azure/azure-cli-extensions/blob/main/src/${pname}/HISTORY.rst";
62 license = lib.licenses.mit;
63 sourceProvenance = [ lib.sourceTypes.fromSource ];
64 } // args.meta or { };
66 // (removeAttrs args [
74 extensions-generated = lib.mapAttrs (name: ext: mkAzExtension ext) (
75 builtins.fromJSON (builtins.readFile ./extensions-generated.json)
77 extensions-manual = callPackages ./extensions-manual.nix {
78 inherit mkAzExtension;
79 python3Packages = python3.pkgs;
81 extensions = extensions-generated // extensions-manual;
83 extensionDir = stdenvNoCC.mkDerivation {
84 name = "azure-cli-extensions";
88 namePaths = map (p: "${p.pname},${p}/${python3.sitePackages}") withExtensions;
91 for line in ${lib.concatStringsSep " " namePaths}; do
92 name=$(echo $line | cut -d',' -f1)
93 path=$(echo $line | cut -d',' -f2)
95 for f in $(ls $path); do
96 ln -s $path/$f $out/$name/$f
103 py.pkgs.toPythonApplication (
104 py.pkgs.buildAzureCliPackage rec {
108 sourceRoot = "${src.name}/src/azure-cli";
110 nativeBuildInputs = [
116 # https://github.com/Azure/azure-cli/blob/azure-cli-2.62.0/src/azure-cli/setup.py#L52
117 # Please, keep ordered by upstream file order. It facilitates reviews.
118 propagatedBuildInputs =
121 antlr4-python3-runtime
122 azure-appconfiguration
129 azure-keyvault-administration
130 azure-keyvault-certificates
132 azure-keyvault-secrets
134 azure-mgmt-apimanagement
135 azure-mgmt-appconfiguration
136 azure-mgmt-appcontainers
137 azure-mgmt-applicationinsights
138 azure-mgmt-authorization
142 azure-mgmt-botservice
144 azure-mgmt-cognitiveservices
146 azure-mgmt-containerinstance
147 azure-mgmt-containerregistry
148 azure-mgmt-containerservice
150 azure-mgmt-databoxedge
151 azure-mgmt-datamigration
152 azure-mgmt-devtestlabs
156 azure-mgmt-extendedlocation
158 azure-mgmt-imagebuilder
159 azure-mgmt-iotcentral
161 azure-mgmt-iothubprovisioningservices
164 azure-mgmt-loganalytics
165 azure-mgmt-managedservices
166 azure-mgmt-managementgroups
168 azure-mgmt-marketplaceordering
173 azure-mgmt-policyinsights
174 azure-mgmt-privatedns
176 azure-mgmt-recoveryservicesbackup
177 azure-mgmt-recoveryservices
179 azure-mgmt-redhatopenshift
183 azure-mgmt-servicebus
184 azure-mgmt-servicefabricmanagedclusters
185 azure-mgmt-servicelinker
186 azure-mgmt-servicefabric
188 azure-mgmt-sqlvirtualmachine
192 azure-mgmt-trafficmanager
195 azure-multiapi-storage
197 azure-synapse-accesscontrol
198 azure-synapse-artifacts
199 azure-synapse-managedprivateendpoints
204 ++ lib.optional stdenv.hostPlatform.isLinux distro
223 pyopenssl # Used at: https://github.com/Azure/azure-cli/blob/azure-cli-2.62.0/src/azure-cli/azure/cli/command_modules/servicefabric/custom.py#L11
224 setuptools # ModuleNotFoundError: No module named 'pkg_resources'
226 ++ lib.optionals (!withImmutableConfig) [
227 # pip is required to install extensions locally, but it's not needed if
228 # we're using the default immutable configuration.
231 ++ lib.concatMap (extension: extension.propagatedBuildInputs) withExtensions;
234 lib.optionalString (stdenvNoCC.buildPlatform.canExecute stdenvNoCC.hostPlatform) ''
235 installShellCompletion --cmd az \
236 --bash <(register-python-argcomplete az --shell bash) \
237 --zsh <(register-python-argcomplete az --shell zsh) \
238 --fish <(register-python-argcomplete az --shell fish)
240 + lib.optionalString withImmutableConfig ''
242 $out/bin/az --version
243 mkdir -p $out/etc/azure
244 mv $TMPDIR/.azure/commandIndex.json $out/etc/azure/commandIndex.json
245 mv $TMPDIR/.azure/versionCheck.json $out/etc/azure/versionCheck.json
250 rm $out/bin/az.completion.sh
253 # wrap the executable so that the python packages are available
254 # it's just a shebang script which calls `python -m azure.cli "$@"`
257 wrapProgram $out/bin/az \
259 + lib.optionalString withImmutableConfig ''
260 --set AZURE_IMMUTABLE_DIR $out/etc/azure \
262 + lib.optionalString (withExtensions != [ ]) ''
263 --set AZURE_EXTENSION_DIR ${extensionDir} \
266 --set PYTHONPATH "${python3.pkgs.makePythonPath propagatedBuildInputs}:$out/${python3.sitePackages}"
269 doInstallCheck = true;
270 installCheckPhase = ''
273 $out/bin/az --version
274 $out/bin/az self-test
277 # ensure these namespaces are able to be accessed
278 pythonImportsCheck = [
281 "azure.cli.telemetry"
283 "azure.datalake.store"
287 "azure.mgmt.apimanagement"
288 "azure.mgmt.applicationinsights"
289 "azure.mgmt.appconfiguration"
290 "azure.mgmt.appcontainers"
291 "azure.mgmt.authorization"
295 "azure.mgmt.botservice"
297 "azure.mgmt.cognitiveservices"
299 "azure.mgmt.containerinstance"
300 "azure.mgmt.containerregistry"
301 "azure.mgmt.containerservice"
302 "azure.mgmt.cosmosdb"
303 "azure.mgmt.datamigration"
304 "azure.mgmt.devtestlabs"
306 "azure.mgmt.eventgrid"
307 "azure.mgmt.eventhub"
308 "azure.mgmt.hdinsight"
309 "azure.mgmt.imagebuilder"
310 "azure.mgmt.iotcentral"
312 "azure.mgmt.iothubprovisioningservices"
313 "azure.mgmt.keyvault"
315 "azure.mgmt.loganalytics"
316 "azure.mgmt.managedservices"
317 "azure.mgmt.managementgroups"
319 "azure.mgmt.marketplaceordering"
324 "azure.mgmt.policyinsights"
325 "azure.mgmt.privatedns"
327 "azure.mgmt.recoveryservices"
328 "azure.mgmt.recoveryservicesbackup"
330 "azure.mgmt.resource"
332 "azure.mgmt.security"
333 "azure.mgmt.servicebus"
334 "azure.mgmt.servicefabric"
337 "azure.mgmt.sqlvirtualmachine"
339 "azure.mgmt.trafficmanager"
341 "azure.monitor.query"
342 "azure.storage.common"
347 withExtensions = extensions: azure-cli.override { withExtensions = extensions; };
349 # Test the package builds with some extensions configured, and the
350 # wanted extensions are recognized by the CLI and listed in the output.
353 extensions = with azure-cli.extensions; [
358 extensionNames = map (ext: ext.pname) extensions;
359 az = (azure-cli.withExtensions extensions);
361 runCommand "test-az-with-extensions" { } ''
363 ${lib.getExe az} extension list > $out
364 for ext in ${lib.concatStringsSep " " extensionNames}; do
365 if ! grep -q $ext $out; then
366 echo "Extension $ext not found in list"
371 # Test the package builds with mutable config.
372 # TODO: Maybe we can install an extension from local python wheel to
373 # check mutable extension install still works.
374 azWithMutableConfig =
376 az = azure-cli.override { withImmutableConfig = false; };
378 runCommand "test-az-with-immutable-config" { } ''
380 ${lib.getExe az} --version || exit 1
384 # Ensure the extensions-tool builds.
385 inherit (azure-cli) extensions-tool;
388 generate-extensions = writeScriptBin "${pname}-update-extensions" ''
389 ${lib.getExe azure-cli.extensions-tool} --cli-version ${azure-cli.version} --commit
393 runCommand "azure-cli-extensions-tool"
395 src = ./extensions-tool.py;
396 nativeBuildInputs = [
403 meta.mainProgram = "extensions-tool";
406 black --check --diff $src
408 isort --profile=black --check --diff $src
410 install -Dm755 $src $out/bin/extensions-tool
412 patchShebangs --build $out
413 wrapProgram $out/bin/extensions-tool \
415 python3.pkgs.makePythonPath (
428 homepage = "https://github.com/Azure/azure-cli";
429 description = "Next generation multi-platform command line experience for Azure";
430 downloadPage = "https://github.com/Azure/azure-cli/releases/tag/azure-cli-${version}";
432 The Azure Command-Line Interface (CLI) is a cross-platform
433 command-line tool to connect to Azure and execute administrative
434 commands on Azure resources. It allows the execution of commands
435 through a terminal using interactive command-line prompts or a script.
437 `azure-cli` has extension support. For example, to install the `aks-preview` extension, use
440 environment.systemPackages = [
441 (azure-cli.withExtensions [ azure-cli.extensions.aks-preview ])
445 To make the `azure-cli` immutable and prevent clashes in case `azure-cli` is also installed via other package managers,
446 some configuration files were moved into the derivation. This can be disabled by overriding `withImmutableConfig = false`
447 when building `azure-cli`.
449 changelog = "https://github.com/MicrosoftDocs/azure-docs-cli/blob/main/docs-ref-conceptual/release-notes-azure-cli.md";
450 sourceProvenance = [ lib.sourceTypes.fromSource ];
451 license = lib.licenses.mit;
453 maintainers = with lib.maintainers; [ katexochen ] ++ lib.teams.stridtech.members;
454 platforms = lib.platforms.all;