Google-cloud-sdk and installing extra components?

I tried installing extra components to gcloud and got this error:

$ gcloud components install app-engine-python
ERROR: (gcloud.components.install) You cannot perform this action because this Cloud SDK installation is managed by an external package manager.
Please consider using a separate installation of the Cloud SDK created through the default mechanism described at: https://cloud.google.com/sdk/

I expected something like this, and went to https://github.com/NixOS/nixpkgs/tree/master/pkgs/tools/admin/google-cloud-sdk to see if there’s already a way to specify which extra components to install, but I couldn’t see any. I found this open issue without any comments: google-cloud-sdk - install additional components: gcloud components install cloud-build-local · Issue #99280 · NixOS/nixpkgs · GitHub. My question is this: Is there a way to install gcloud with extra components already? Or is there an alternative to use gcloud with extra components on NixOS?

4 Likes

Does anyone knows a way to do this?

I’m actually trying to figure this out myself as I’ve encountered a bug with the app-gradle-plugin for GCE and the suggested workaround was to install the app-engine-java component: https://github.com/GoogleCloudPlatform/app-gradle-plugin/issues/393

I ran into this as well.

As a workaround I use the following shell.nix:

{ pkgs ? import <nixpkgs> {} }:

(pkgs.buildFHSUserEnv {
  name = "google-cloud-sdk";

  targetPkgs = pkgs: [
    pkgs.python3
  ];
  
}).env

and inside that shell use the ‘regular’ gcloud tool downloaded from Install the gcloud CLI  |  Google Cloud CLI Documentation

I would also love a declarative way to do this though :wink:

2 Likes

It seems there is a way to accomplish this now, by this comment added yesterday:

FYI this was just added to nixpkgs. You can do the following:

google-cloud-sdk.withExtraComponents ([google-cloud-sdk.components.cloud-build-local])

I tried applying it, but failed. I’m using home-manager on elementaryos, can someone help me understand how to apply this in this context? Thanks!

2 Likes

As of the time of your comment, that change hasn’t landed on nixpkgs-unstable yet. That is likely why it is failing for you. Consider including error messages next time.

2 Likes

I’m using home-manager and the following line works for me:

home.packages = with pkgs; [
  # ...
  (google-cloud-sdk.withExtraComponents [google-cloud-sdk.components.gke-gcloud-auth-plugin])
  # ...
]
4 Likes