Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nix flake enablement for gardenctl-v2 #366

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Files:
go.sum
LATEST
VERSION
flake.lock
Copyright: 2020-2021 SAP SE or an SAP affiliate company and Gardener contributors
License: Apache-2.0

Expand Down
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ gardenctl is a command-line client for the Gardener. It facilitates the administ

## Installation

Install the latest release from [Homebrew](https://brew.sh/), [Chocolatey](https://chocolatey.org/packages/gardenctl-v2) or [GitHub Releases](https://github.com/gardener/gardenctl-v2/releases).
Install the latest release from [Homebrew](https://brew.sh/), [Chocolatey](https://chocolatey.org/packages/gardenctl-v2), [Nix](https://nixos.org), or [GitHub Releases](https://github.com/gardener/gardenctl-v2/releases).

### Install using Package Managers

Expand All @@ -27,6 +27,25 @@ choco install gardenctl-v2

Attention `brew` users: `gardenctl-v2` uses the same binary name as the legacy `gardenctl` (`gardener/gardenctl`) CLI. If you have an existing installation you should remove it with `brew uninstall gardenctl` before attempting to install `gardenctl-v2`. Alternatively, you can choose to link the binary using a different name. If you try to install without removing or relinking the old installation, brew will run into an error and provide instructions how to resolve it.

### Install using Nix (with [Flakes](https://nixos.wiki/wiki/Flakes))

```bash
# Nix (macOS, Linux, and Windows)
# ad hoc cmd execution
nix run github:gardener/gardenctl-v2 -- --help

# install development version
nix profile install github:gardener/gardenctl-v2
# or release <version>
nix profile install github:gardener/gardenctl-v2/<version>

#check installation
nix profile list | grep gardenctl

# optionally, open a new shell and verify that cmd completion works
gardenctl --help
```

### Install from Github Release

If you install via GitHub releases, you need to
Expand Down
27 changes: 27 additions & 0 deletions flake.lock

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

120 changes: 120 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
SPDX-FileCopyrightText: 2021 SAP SE or an SAP affiliate company and Gardener contributors

SPDX-License-Identifier: Apache-2.0
*/
{
description = "Nix flake for gardenctl-v2";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
};

outputs = {
self,
nixpkgs,
...
}: let
pname = "gardenctl";

# System types to support.
supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];

# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;

# Nixpkgs instantiated for supported system types.
nixpkgsFor = forAllSystems (system: import nixpkgs {inherit system;});
in {
# Provide some binary packages for selected system types.
packages = forAllSystems (system: let
pkgs = nixpkgsFor.${system};
inherit (pkgs) stdenv lib;
in {
${pname} = pkgs.buildGo121Module rec {
inherit pname self;
version = lib.fileContents ./VERSION;
splitVersion = lib.versions.splitVersion version;
major = if ((lib.elemAt splitVersion 0) == "v") then
lib.elemAt splitVersion 1
else
lib.elemAt splitVersion 0;
minor = if ((lib.elemAt splitVersion 0) == "v") then
lib.elemAt splitVersion 2
else
lib.elemAt splitVersion 1;
gitCommit = if (self ? rev) then
self.rev
else
self.dirtyRev;
state = if (self ? rev) then
"clean"
else
"dirty";

# This vendorHash represents a dervative of all go.mod dependancies and needs to be adjusted with every change
vendorHash = "sha256-YE6Xtm7OsY82AxnHuJFaV5tpOqMKftZr1Xiws+43uVA=";

src = ./.;

ldflags = [
"-s"
"-w"
"-X k8s.io/component-base/version.gitMajor=${major}"
"-X k8s.io/component-base/version.gitMinor=${minor}"
"-X k8s.io/component-base/version.gitVersion=${version}"
"-X k8s.io/component-base/version.gitTreeState=${state}"
"-X k8s.io/component-base/version.gitCommit=${gitCommit}"
"-X k8s.io/component-base/version/verflag.programName=${pname}"
# "-X k8s.io/component-base/version.buildDate=1970-01-01T0:00:00+0000"
];

CGO_ENABLED = 0;
doCheck = false;
subPackages = [
"/"
];
nativeBuildInputs = [pkgs.installShellFiles];

postInstall = ''
mv $out/bin/${pname}-v2 $out/bin/${pname}
installShellCompletion --cmd ${pname} \
--zsh <($out/bin/${pname} completion zsh) \
--bash <($out/bin/${pname} completion bash) \
--fish <($out/bin/${pname} completion fish)
'';

meta = with lib; {
description = "gardenctl facilitates the administration of one or many garden, seed and shoot clusters";
longDescription = ''
gardenctl is a command-line client for the Gardener.
It facilitates the administration of one or many garden, seed and shoot clusters.
Use this tool to configure access to clusters and configure cloud provider CLI tools.
It also provides support for accessing cluster nodes via ssh.
'';
homepage = "https://github.com/gardener/gardenctl-v2";
license = licenses.asl20;
platforms = supportedSystems;
};
};
});

# Add dependencies that are only needed for development
devShells = forAllSystems (system: let
pkgs = nixpkgsFor.${system};
in {
default = pkgs.mkShell {
buildInputs = with pkgs; [
go_1_21 # golang 1.21
gopls # go language server
gotools # go imports
go-tools # static checks
gnumake # standard make
];
};
});

# The default package for 'nix build'
defaultPackage = forAllSystems (system: self.packages.${system}.${pname});
};
}