diff --git a/.reuse/dep5 b/.reuse/dep5 index d166b88..bfb99e1 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -18,6 +18,7 @@ Files: go.sum LATEST VERSION + flake.lock Copyright: 2021 SAP SE or an SAP affiliate company and Gardener contributors License: Apache-2.0 diff --git a/README.md b/README.md index 25d3eab..f0d6cb1 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,25 @@ brew install gardener/tap/gardenlogin # Chocolatey (Windows) choco install gardenlogin ``` +### Install using Nix + +Nix with [Flakes](https://nixos.wiki/wiki/Flakes) (prerequisite: [Nix](https://nixos.org/download), the package manager): + +```bash +# Nix (macOS, Linux, and Windows) + +# development version +nix profile install github:gardener/gardenlogin +# or release +nix profile install github:gardener/gardenlogin/ + +#check installation +nix profile list | grep gardenlogin + +# optionally, open a new shell and verify that cmd completion works +gardenlogin --help +kubectl gardenlogin --help +``` ### Install from Github Release diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..c755842 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1704874635, + "narHash": "sha256-YWuCrtsty5vVZvu+7BchAxmcYzTMfolSPP5io8+WYCg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3dc440faeee9e889fe2d1b4d25ad0f430d449356", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..c6f3346 --- /dev/null +++ b/flake.nix @@ -0,0 +1,122 @@ +/* +SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors + +SPDX-License-Identifier: Apache-2.0 +*/ +{ + description = "Nix flake for gardenlogin"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; + }; + + outputs = { + self, + nixpkgs, + ... + }: let + pname = "gardenlogin"; + + # 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.buildGo120Module 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-vmU0WrrEvfAHuWWrT9anZmQN+YNJIvrgjVUufws0X3s="; + + 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; + + # subPackages = [ + # ]; + nativeBuildInputs = [pkgs.installShellFiles]; + + postInstall = '' + ln -s $out/bin/${pname} $out/bin/kubectl-${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 = "gardenlogin is a kubectl credential plugin for Gardener"; + longDescription = '' + gardenlogin is a kubectl credential plugin that facilitates Gardener managed cluster admin authentication. + It is used to generate kubeconfigs for clusters with short-lived certificates, to access the cluster as cluster-admin. + ''; + homepage = "https://github.com/gardener/gardenlogin"; + 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_20 + gopls + gotools + go-tools + gnumake + ]; + }; + }); + + # The default package for 'nix build' + defaultPackage = forAllSystems (system: self.packages.${system}.${pname}); + }; +}