about summary refs log tree commit diff
path: root/pkgs/by-name/az/azure-cli/package.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/by-name/az/azure-cli/package.nix')
-rw-r--r--pkgs/by-name/az/azure-cli/package.nix94
1 files changed, 66 insertions, 28 deletions
diff --git a/pkgs/by-name/az/azure-cli/package.nix b/pkgs/by-name/az/azure-cli/package.nix
index 2a73b3da9fac..4744b7d109ee 100644
--- a/pkgs/by-name/az/azure-cli/package.nix
+++ b/pkgs/by-name/az/azure-cli/package.nix
@@ -10,6 +10,11 @@
   python3,
   writeScriptBin,
 
+  black,
+  isort,
+  mypy,
+  makeWrapper,
+
   # Whether to include patches that enable placing certain behavior-defining
   # configuration files in the Nix store.
   withImmutableConfig ? true,
@@ -21,14 +26,14 @@
 }:
 
 let
-  version = "2.64.0";
+  version = "2.65.0";
 
   src = fetchFromGitHub {
     name = "azure-cli-${version}-src";
     owner = "Azure";
     repo = "azure-cli";
     rev = "azure-cli-${version}";
-    hash = "sha256-1FnrUvRpAkZ0nAxen3seam2S49tBkK5N37ZD99OkvB0=";
+    hash = "sha256-IeiAB0AI6KNpXwx2Iv55LBARcwemakbblFlbfLheuGE=";
   };
 
   # put packages that needs to be overridden in the py package scope
@@ -41,14 +46,14 @@ let
       pname,
       version,
       url,
-      sha256,
+      hash,
       description,
       ...
     }@args:
     python3.pkgs.buildPythonPackage (
       {
         format = "wheel";
-        src = fetchurl { inherit url sha256; };
+        src = fetchurl { inherit url hash; };
         meta = {
           inherit description;
           inherit (azure-cli.meta) platforms maintainers;
@@ -60,18 +65,20 @@ let
       }
       // (removeAttrs args [
         "url"
-        "sha256"
+        "hash"
         "description"
         "meta"
       ])
     );
 
-  extensions =
-    callPackages ./extensions-generated.nix { inherit mkAzExtension; }
-    // callPackages ./extensions-manual.nix {
-      inherit mkAzExtension;
-      python3Packages = python3.pkgs;
-    };
+  extensions-generated = lib.mapAttrs (name: ext: mkAzExtension ext) (
+    builtins.fromJSON (builtins.readFile ./extensions-generated.json)
+  );
+  extensions-manual = callPackages ./extensions-manual.nix {
+    inherit mkAzExtension;
+    python3Packages = python3.pkgs;
+  };
+  extensions = extensions-generated // extensions-manual;
 
   extensionDir = stdenvNoCC.mkDerivation {
     name = "azure-cli-extensions";
@@ -100,7 +107,10 @@ py.pkgs.toPythonApplication (
 
     sourceRoot = "${src.name}/src/azure-cli";
 
-    nativeBuildInputs = [ installShellFiles ];
+    nativeBuildInputs = [
+      installShellFiles
+      py.pkgs.argcomplete
+    ];
 
     # Dependencies from:
     # https://github.com/Azure/azure-cli/blob/azure-cli-2.62.0/src/azure-cli/setup.py#L52
@@ -191,7 +201,7 @@ py.pkgs.toPythonApplication (
         chardet
         colorama
       ]
-      ++ lib.optional stdenv.isLinux distro
+      ++ lib.optional stdenv.hostPlatform.isLinux distro
       ++ [
         fabric
         javaproperties
@@ -221,11 +231,11 @@ py.pkgs.toPythonApplication (
       ++ lib.concatMap (extension: extension.propagatedBuildInputs) withExtensions;
 
     postInstall =
-      ''
-        substituteInPlace az.completion.sh \
-          --replace-fail register-python-argcomplete ${py.pkgs.argcomplete}/bin/register-python-argcomplete
-        installShellCompletion --bash --name az.bash az.completion.sh
-        installShellCompletion --zsh --name _az az.completion.sh
+      lib.optionalString (stdenvNoCC.buildPlatform.canExecute stdenvNoCC.hostPlatform) ''
+        installShellCompletion --cmd az \
+          --bash <(register-python-argcomplete az --shell bash) \
+          --zsh <(register-python-argcomplete az --shell zsh) \
+          --fish <(register-python-argcomplete az --shell fish)
       ''
       + lib.optionalString withImmutableConfig ''
         export HOME=$TMPDIR
@@ -370,20 +380,48 @@ py.pkgs.toPythonApplication (
             ${lib.getExe az} --version || exit 1
             touch $out
           '';
+
+        # Ensure the extensions-tool builds.
+        inherit (azure-cli) extensions-tool;
       };
 
       generate-extensions = writeScriptBin "${pname}-update-extensions" ''
-        export FILE=extensions-generated.nix
-        echo "# This file is automatically generated. DO NOT EDIT! Read README.md" > $FILE
-        echo "{ mkAzExtension }:" >> $FILE
-        echo "{" >> $FILE
-        ${./query-extension-index.sh} --requirements=false --download --nix --cli-version=${version} \
-          | xargs -n1 -d '\n' echo " " >> $FILE
-        echo "" >> $FILE
-        echo "}" >> $FILE
-        echo "Extension was saved to \"extensions-generated.nix\" file."
-        echo "Move it to \"{nixpkgs}/pkgs/by-name/az/azure-cli/extensions-generated.nix\"."
+        ${lib.getExe azure-cli.extensions-tool} --cli-version ${azure-cli.version} --commit
       '';
+
+      extensions-tool =
+        runCommand "azure-cli-extensions-tool"
+          {
+            src = ./extensions-tool.py;
+            nativeBuildInputs = [
+              black
+              isort
+              makeWrapper
+              mypy
+              python3
+            ];
+            meta.mainProgram = "extensions-tool";
+          }
+          ''
+            black --check --diff $src
+            # mypy --strict $src
+            isort --profile=black --check --diff $src
+
+            install -Dm755 $src $out/bin/extensions-tool
+
+            patchShebangs --build $out
+            wrapProgram $out/bin/extensions-tool \
+              --set PYTHONPATH "${
+                python3.pkgs.makePythonPath (
+                  with python3.pkgs;
+                  [
+                    packaging
+                    semver
+                    gitpython
+                  ]
+                )
+              }"
+          '';
     };
 
     meta = {