Skip to content

Commit

Permalink
initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
nicknovitski committed Oct 10, 2024
0 parents commit 22132bb
Show file tree
Hide file tree
Showing 14 changed files with 439 additions and 0 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake ./dev
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
13 changes: 13 additions & 0 deletions .github/workflows/new-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Release new version
on:
release:
types: [released]
permissions:
contents: write
jobs:
update-major-tag:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
source-tag: ${{ github.event.release.tag_name }}
9 changes: 9 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
on:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@V27
- run: ./test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/examples/*/flake.lock
/.direnv/
90 changes: 90 additions & 0 deletions OPTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Options

These are the options currently declared by `gcloud-nix`.

## Basic options

### `gcloud.enable`

If true, the Google Cloud SDK and any defined `extra-components` are added to the environment.

Default value: false

### `gcloud.extra-components`

An array of IDs of SDK components to add to the environment, if `gcloud.enable` is true. Run `gcloud components list` to see the list of available components and their IDs.

Default value: `[]`

## Configuration options

These options deal with *named configurations*. For more information, run `gcloud topics configuration`.

### `gcloud.properties`

An attribute set of attribute sets, whose values are either non-empty strings, `true`, or `false`. Each nested attribute represents a configuration property to set in the enironment, with the top-level attribute names being the section.

For example, the option declaration `gcloud.properties.core.project = "myproject";` will add the environment variable `CLOUDSDK_CORE_PROJECT=myproject` to the environment, causing the property `core/project` to be set to `myproject` for all commands, while the declaration `gcloud.properties.context-aware.use-client-certificate = true;` will create the variable `CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATE=1` which will set the property `context_aware/use_client_certificate` to `True`.

NOTE: section and property names may include the underscore character `_`. Corresponding option names may instead use include the dash character `-`.

Default value: empty

### `gcloud.config-directory`

A non-empty string representing the path to the directory in which to store configuration for the Google Cloud SDK's when it is invoked in the environment. If the option is defined, the environment variable `CLOUDSDK_CONFIG` is defined in the environment with the same value.

If no directory exists at that path, it will be created. If the directory exists but the user does not have write permissions on it, the Google Cloud SDK may not work correctly.

Default value: not defined

### `gcloud.active-configuration-name`

A non-empty string representing the name of the configuration to use in the environment.

Default value: not defined

## Node.js

[https://nodejs.org/en](https://nodejs.org/en)

### javascript.node.corepack-shims

An array of strings which, if `javascript.node.enable` is true, are passed to `corepack enable`, creating [corepack](https://nodejs.org/api/corepack.html) package manager shims.

Currently, supported values are `"yarn"`, `"pnpm"`, and `"npm"`.

Default value: `[]`

### javascript.node.enable

Whether to add the Node.js runtime to the environment.

Default value: false

### javascript.node.env

If set, then the `NODE_ENV` variable is set to this value in the environment. The only valid values are `"production"`, `"development"`, and `"test"`.

Default value: unset

### javascript.node.package

If `javascript.volta.enable` is true, this package is added to the environment. There are [several alternative packages in nixpkgs](https://search.nixos.org/packages?from=0&size=50&sort=relevance&type=packages&query=nodejs-), such as `nodejs-slim` (which lacks npm), or `nodejs_22` (the latest version in the 22.x line).

Default value: `pkgs.nodejs`

## Volta

[The Hassle-Free JavaScript Tool Manager](https://volta.sh/)

### javascript.volta.enable

Whether to add volta to the environment.

Default value: false
### javascript.volta.home

A non-empty string. If `javascript.volta.enable` is true, the `VOLTA_HOME` variable is set to this value in the environment.

Default value: `"$HOME/.volta"`
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# gcloud-nix

A [make-shell](https://github.com/nicknovitski/make-shell) module for the Google Cloud SDK, or `gcloud` CLI tool.

## Why?

`make-shell` is a modular interface for making nix derivations intended for use by the `nix develop` command. It has it's own lengthy [WHY document](https://github.com/nicknovitski/make-shell/blob/main/WHY.md).

The Google Cloud SDK nix package has a


This is a module for `make-shell` that lets you

I work on projects which attempts to explain how it might be useful, but I thought that creating this repository might also give an indirect explanation.

## Installation

First make sure that you've [installed `make-shell` in your flake](https://github.com/nicknovitski/make-shell/tree/main?tab=readme-ov-file#installation).

Then, add `gcloud` to your flake inputs. Maybe they'd look like this:
```nix
inputs = {
gcloud-nix.url = "github:nicknovitski/gcloud-nix";
make-shell.url = "github:nicknovitski/make-shell";
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};
```

Then, add the shell module to your shell's imports. It'll look something like this:
```nix
devShells.default = pkgs.make-shell = {
imports = [inputs.gcloud-nix.shellModules.default]; # add option declarations...
javascript.gcloud.enable = true; # ...and definitions!
}
# or, if you're using flake-parts...
make-shell.imports = [gcloud-nix.shellModules.default]; # shared imports for all `make-shells` attributes
make-shells.default = {gcloud.enable = true;};
```

## Usage

The options this module declares are documented [the OPTIONS.md file](OPTIONS.md). Although if you know even a little nix, I bet you can read the declarations directly from [the module itself](shell-modules/default.nix) directory.

## Examples

See [example/flake.nix](example/flake.nix).
74 changes: 74 additions & 0 deletions dev/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions dev/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
make-shell.url = "github:nicknovitski/make-shell";
};

outputs =
inputs@{ flake-parts, make-shell, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
"x86_64-darwin"
];
imports = [ make-shell.flakeModules.default ];
perSystem =
{ ... }:
{
make-shells.default =
{ pkgs, ... }:
{
packages = [ pkgs.nixfmt-rfc-style ];
};
};
};
}
44 changes: 44 additions & 0 deletions example/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
description = "An example usage of the gcloud-nix shell modules, with flake-parts";

inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
gcloud-nix.url = "github:nicknovitski/gcloud-nix";
make-shell.url = "github:nicknovitski/make-shell";
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};

outputs =
inputs@{
flake-parts,
make-shell,
gcloud-nix,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
"x86_64-darwin"
];
imports = [ make-shell.flakeModules.default ];
perSystem =
{ ... }:
{
make-shell.imports = [ gcloud-nix.shellModules.default ];
make-shells.default =
{ pkgs, ... }:
{
gcloud = {
enable = true;
extra-components = [
"gke-gcloud-auth-plugin"
"kubectl"
];
properties.core.project = "my-gcp-project";
};
};
};
};
}
23 changes: 23 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
description = "";

outputs = _: {
shellModules.default = {
imports = [ ./shell-modules ];
};
};
}
Loading

0 comments on commit 22132bb

Please sign in to comment.