init cli, add start of target docs

This commit is contained in:
Bryton Hall 2022-08-12 09:44:00 -04:00
parent d41bceaa4c
commit 612fa7d53c
3 changed files with 81 additions and 14 deletions

View file

@ -10,13 +10,11 @@ Kubernetes resource management with Nix
## Usage ## Usage
See [./docs/examples/](./docs/examples/) for now. Apply all resources with
<!-- Apply all resources with nix run github:hall/kubenix . -- apply
nix run github:hall/kubenix > **HINT**: run `nix run github:hall/kubenix . -- --help` for more commands
> **HINT**: run `nix run github:hall/kubenix -- --help` for more commands
A minimal example flake: A minimal example flake:
@ -24,15 +22,20 @@ A minimal example flake:
{ {
inputs.kubenix = "github:hall/kubenix"; inputs.kubenix = "github:hall/kubenix";
outputs = {self, ...}@inputs: { outputs = {self, ...}@inputs: {
# nixosConfigurations.hostname = { nixosConfigurations.hostname = {
# modules = [ inputs.kubenix.nixosModule ]; modules = [ inputs.kubenix.nixosModule ];
# }; };
kubernetes.cluster.resources.pod.test.spec.containers.nginx.image = "nginx"; kubernetes.resources.pods."app" = {
spec.containers."app" = {
name = "app";
image = "nginx";
};
};
} }
} }
``` ```
A more complete example config: <!-- A more complete example config:
```nix ```nix
{ {
@ -42,7 +45,6 @@ A more complete example config:
helm = { helm = {
releases = {}; releases = {};
}; };
docker = {};
} }
} }
``` --> ``` -->

View file

@ -74,9 +74,14 @@
devShells.default = import ./devshell {inherit pkgs inputs;}; devShells.default = import ./devshell {inherit pkgs inputs;};
packages = inputs.flake-utils.lib.flattenTree { packages =
inherit (pkgs) kubernetes kubectl; inputs.flake-utils.lib.flattenTree {
}; inherit (pkgs) kubernetes kubectl;
}
// {
cli = pkgs.callPackage ./pkgs/kubenix.nix {};
default = self.packages.${system}.cli;
};
checks = let checks = let
wasSuccess = suite: wasSuccess = suite:

60
pkgs/kubenix.nix Normal file
View file

@ -0,0 +1,60 @@
{
lib,
writeShellScriptBin,
coreutils,
nix,
jq,
}: let
name = "kubenix";
in
lib.recursiveUpdate
(writeShellScriptBin name ''
set -Eeuo pipefail
NAME=${name}
function help() {
echo "
kubenix - Kubernetes resource management with Nix
commands:
apply - create resources in target cluster
render - print resource manifests to stdout
"
}
function apply() {
echo not impremented
}
function render() {
${nix}/bin/nix eval '.#kubernetes' # | ${jq}/bin/jq 'fromjson'
}
while test $# -gt 0; do
case "$1" in
apply|"")
shift
apply
;;
render)
shift
render
;;
-h|--help)
help
exit 0
;;
-v|--verbose)
shift
set -x
;;
*)
help
exit 1
;;
esac
done
'')
{meta.description = "";}