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

kns: init @ 86502949c31432bd95895cfb26d1c5893c533d5c #193995

Closed
wants to merge 9 commits into from
6 changes: 6 additions & 0 deletions maintainers/maintainer-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2992,6 +2992,12 @@
fingerprint = "2017 E152 BB81 5C16 955C E612 45BC C1E2 709B 1788";
}];
};
crutonjohn = {
email = "[email protected]";
github = "crutonjohn";
githubId = 19677342;
name = "Curtis Ray John";
};
cryptix = {
email = "[email protected]";
github = "cryptix";
Expand Down
35 changes: 35 additions & 0 deletions pkgs/applications/networking/cluster/kns/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{ stdenvNoCC, lib, fetchFromGitHub, fzf, kubectl }:

stdenvNoCC.mkDerivation rec {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use the finalAttrs pattern here.

The finalAttrs pattern will let you remove the rec keyword (see its implementation in Nix).

Why is this pattern preferred to rec ?

Let's take this simple code example:

mkDerivation rec {
   foo = 1;
   bar = foo + 1;
}

and then .overrideAttrs(old: { foo = 2; }), you'll get { foo = 2; bar = 2; } while with finalAttrs pattern, it would work correctly because it's a real fixed point.

Let me share a couple of useful links regarding the finalAttrs pattern:

  1. History: https://discourse.nixos.org/t/avoid-rec-expresions-in-nixpkgs/8293
  2. Documentation: https://nixos.org/manual/nixpkgs/unstable/#mkderivation-recursive-attributes
  3. Recent example of implementation: https://github.com/NixOS/nixpkgs/compare/17f96f7b978e61576cfe16136eb418f74fab9952..9e6ea843e473d34d4f379b8b0d8ef0425a06defe

Feel free to reach out if you need some assistance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I get rid of repo = pname then I don't need rec at all, nor finalAttrs, 2 birds with one stone!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bingo ! :)

pname = "kns";
version = "unstable-2022-04-25";

src = fetchFromGitHub {
owner = "blendle";
repo = pname;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use this.

repo = pname; is nice for DRY but creates a binding that goes too far.

See further information about this here: nix-community/nixpkgs-lint#21

rev = "86502949c31432bd95895cfb26d1c5893c533d5c";
sha256 = "sha256-8AR/fEKPAfiKCZrp/AyJo3Ic8dH7SfncYZSdQA2GywQ=";
};

strictDeps = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildInputs = [ fzf kubectl ];


buildInputs = [ fzf kubectl ];

installPhase = ''
runHook preInstall

substituteInPlace bin/kns bin/ktx --replace fzf ${fzf}/bin/fzf --replace kubectl ${kubectl}/bin/kubectl
install -D -m755 -t $out/bin bin/kns bin/ktx

runHook postInstall
'';

meta = with lib; {
description = "Kubernetes namespace switcher";
homepage = "https://github.com/blendle/kns";
license = licenses.isc;
maintainers = with maintainers; [ crutonjohn ];
platforms = platforms.linux;
};
}

2 changes: 2 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30378,6 +30378,8 @@ with pkgs;

kn = callPackage ../applications/networking/cluster/kn { };

kns = callPackage ../applications/networking/cluster/kns { };

kondo = callPackage ../applications/misc/kondo { };

kooha = callPackage ../applications/video/kooha { };
Expand Down