Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1# Azure CLI 2 3## Updating the CLI 4 5- Update `version` and `src.hash` in package.nix 6- Check out the changes made to the azure-cli [setup.py](https://github.com/Azure/azure-cli/blob/dev/src/azure-cli/setup.py) since the last release 7- Try build the CLI, will likely fail with `ModuleNotFoundError`, for example 8 ``` 9 ModuleNotFoundError: No module named 'azure.mgmt.storage.v2023_05_01' 10 ``` 11 Sometimes it will also fail with other import errors. 12- Check the referenced module (`azure-mgmt-storage`) in the setup.py 13- Find the actual version required, for example 14 ``` 15 'azure-mgmt-storage==21.2.0', 16 ``` 17- Update version and hash of this dependency in python-packages.nix 18- Repeat until it builds 19 20## Extensions 21 22There are two sets of extensions: 23 24- `extensions-generated.nix` are extensions with no external requirements, which can be regenerated running: 25 > nix run .#azure-cli.passthru.generate-extensions 26 27- `extensions-manual.nix` are extensions with requirements, which need to be manually packaged and maintained. 28 29### Adding an extension to `extensions-manual.nix` 30 31To manually add a missing extension, first query its metadata from the extension index. 32Use the following command, use the current version of azure-cli in nixpkgs as `cli-version` 33and the name of the extension you want to package as `extension`: 34 35```sh 36nix run .#azure-cli.extension-tool -- \ 37 --cli-version=2.61.0 \ 38 --extension=azure-devops \ 39 --init 40``` 41 42The output should look something like this: 43 44```json 45{ 46 "pname": "azure-devops", 47 "version": "1.0.2", 48 "url": "https://github.com/Azure/azure-devops-cli-extension/releases/download/20250624.2/azure_devops-1.0.2-py2.py3-none-any.whl", 49 "hash": "sha256-4rDeAqOnRRKMP26MJxG4u9vBuos6/SQIoVgfNbBpulk=", 50 "description": "Tools for managing Azure DevOps", 51 "license": "MIT", 52 "requirements": [ 53 "distro (>=1.6.0)" 54 ] 55} 56``` 57 58Based on this, you can add an attribute to `extensions-manual.nix`: 59 60```nix 61{ 62 azure-devops = mkAzExtension { 63 pname = "azure-devops"; 64 version = "1.0.2"; 65 url = "https://github.com/Azure/azure-devops-cli-extension/releases/download/20250624.2/azure_devops-${version}-py2.py3-none-any.whl"; 66 hash = "sha256-4rDeAqOnRRKMP26MJxG4u9vBuos6/SQIoVgfNbBpulk="; 67 description = "Tools for managing Azure DevOps"; 68 propagatedBuildInputs = with python3Packages; [ distro ]; 69 meta.maintainers = with lib.maintainers; [ katexochen ]; 70 }; 71} 72``` 73 74* The attribute name should be the same as `pname`. 75* Replace the version in `url` with `${version}`. 76* The json output `requirements` must be transformed into package `requirements`. 77* If `license` is `"MIT"`, it can be left out in the nix expression, as the builder defaults to that license. 78* Add yourself as maintainer in `meta.maintainers`. 79 80### Testing extensions 81 82You can build azure-cli with an extension on the command line by running the following command at the root of this repository: 83 84```sh 85nix build --impure --expr 'with (import ./. {}); azure-cli.withExtensions [ azure-cli.extensions.azure-devops ]' 86``` 87 88Check if the desired functionality was added. 89 90You can check if the extensions was recognized by running: 91 92```sh 93./result/bin/az extension list 94``` 95 96The output should show the extension like this: 97 98```sh 99[ 100 { 101 "experimental": false, 102 "extensionType": "whl", 103 "name": "azure-devops", 104 "path": "/nix/store/azbgnpg5nh5rb8wfvp0r9bmcx83mqrj5-azure-cli-extensions/azure-devops", 105 "preview": false, 106 "version": "1.0.0" 107 } 108] 109``` 110 111### Removing an extension 112 113If extensions are removed upstream, an alias is added to the end of `extensions-manual.nix` 114(see `# Removed extensions`). This alias should throw an error and be of similar structure as 115this example: 116 117```nix 118{ 119 blockchain = throw "The 'blockchain' extension for azure-cli was deprecated upstream"; # Added 2024-04-26 120} 121```