devbox icon indicating copy to clipboard operation
devbox copied to clipboard

[Question] Support for `google-cloud-sdk` `withExtraComponents` option?

Open gdahia opened this issue 3 years ago • 7 comments

I tried many ways to obtain the result of installing google-cloud-sdk.withExtraComponents [google-cloud-sdk.components.gke-gcloud-auth-plugin], including manually editing the devbox.json file, to no avail.

It seems like the only way to properly use google-cloud-sdk and kubectl as of today.

Is there a way to achieve this using devbox? Thanks!

gdahia avatar Sep 22 '23 10:09 gdahia

Hey @gdahia

Currently, this can be done using our Flake Support. The steps to do this are:

  1. Create a subdirectory called gcloud in your project
  2. Within that subdirectory, create a flake.nix file and add the following:
{
  description = "Google Cloud SDK with GKE auth plugin";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils}:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
        };
      in {
        packages = {
          google-cloud-sdk = pkgs.google-cloud-sdk.withExtraComponents [pkgs.google-cloud-sdk.components.gke-gcloud-auth-plugin];
        };
      }
    );
}
  1. Add the flake package to your devbox.json by running devbox add path:gcloud#google-cloud-sdk, or adding the following to your devbox.json:
"packages": [
    "<other packages>"
    "path:gcloud#google-cloud-sdk"
]
  1. Now when you run devbox shell, Devbox will install the SDK with the extra components.

Let me know if this works for you. We should look into making this easier, or finding a way to better customize packages in your devbox.json

Lagoja avatar Sep 25 '23 22:09 Lagoja

Thanks for the reply. For my particular setup, I wanted this for devbox global. How could I adapt these instructions for that setting?

Also, I would be willing to help to implement this in my free time. Unfortunately, I have zero experience with the project and would need some light guidance to do that.

gdahia avatar Sep 26 '23 17:09 gdahia

@gdahia This can be added to devbox global by adding the subdirecory and flake in your Devbox global path (print this out by running devbox global path in your terminal) as described above.

You can then add the flake to your global profile using devbox global add path:gcloud#google-cloud-sdk

Lagoja avatar Oct 10 '23 01:10 Lagoja

Thanks, this worked perfectly!

gdahia avatar Oct 23 '23 21:10 gdahia

Thanks for the solution @Lagoja.

Any suggestion on how to pin the version? I'm sorry I haven't researched a solution yet. I'm using devbox to avoid Flakes. Would we need to return additional attributes pkgs?

"packages": [
    "<other packages>"
    "path:[email protected]#[email protected]"
]
Error: error installing package path:./gcloud#[email protected]
source: nix path-info exit code: 1, output: error: flake 'path:/Users/work/Development/GitHub/PHACDataHub/sci-portal/gcloud' does not provide attribute '[email protected]', '[email protected]' or '[email protected]'
, err: exit status 1

seanpoulter avatar May 03 '24 13:05 seanpoulter

@Lagoja 's solution worked for me. Thank you ! There are another person who also used this solution - https://github.com/vfarcic/crossplane-kubernetes/blob/main/devbox.json

ovitente avatar Jul 19 '24 18:07 ovitente

@seanpoulter or anyone else found a syntax to pin the google-cloud-sdk version ?

gberche-orange avatar Feb 03 '26 14:02 gberche-orange