flake: format

This commit is contained in:
Bryton Hall 2023-06-12 02:36:52 -04:00
parent ea8fe3bd9c
commit 9492528225
3 changed files with 34 additions and 36 deletions

View file

@ -21,11 +21,11 @@ For example, to patch the deployment created by the release above:
kubernetes.resources.deployments.nginx = { kubernetes.resources.deployments.nginx = {
# be sure to match the corresponding namespace as well # be sure to match the corresponding namespace as well
metadata.namespace = "default"; metadata.namespace = "default";
# here we can configure anything and are no longer bound by `values.yaml` # here we can configure anything and are no longer bound by `values.yaml`
spec.template.spec.containers.nginx.env = [{ spec.template.spec.containers.nginx.env = [{
name = "MY_VARIABLE"; name = "MY_VARIABLE";
value = "100"; value = "100";
}]; }];
}; };
} }
``` ```

View file

@ -5,7 +5,7 @@ As such, on a server node, we can write kubenix's output there.
```nix ```nix
{ {
# let's write `resultYAML` to an arbitrary file under `/etc` # let's write `resultYAML` to an arbitrary file under `/etc`
environment.etc."kubenix.yaml".source = environment.etc."kubenix.yaml".source =
(kubenix.evalModules.x86_64-linux { (kubenix.evalModules.x86_64-linux {
module = { kubenix, ... }: { module = { kubenix, ... }: {
imports = [ kubenix.modules.k8s ]; imports = [ kubenix.modules.k8s ];
@ -20,6 +20,7 @@ As such, on a server node, we can write kubenix's output there.
''; '';
} }
``` ```
{{< hint danger >}} {{< hint danger >}}
**WARN**: this will write all manifests to the nix store and is therefore not suitable for inline sensitive data. **WARN**: this will write all manifests to the nix store and is therefore not suitable for inline sensitive data.
{{< /hint >}} {{< /hint >}}

View file

@ -13,35 +13,33 @@
}; };
}; };
outputs = inputs @ { self, ... }: outputs = inputs @ {self, ...}:
(inputs.flake-utils.lib.eachDefaultSystem ( (inputs.flake-utils.lib.eachDefaultSystem (
system: system: let
let
pkgs = import inputs.nixpkgs { pkgs = import inputs.nixpkgs {
inherit system; inherit system;
overlays = [ self.overlays.default ]; overlays = [self.overlays.default];
config.allowUnsupportedSystem = true; config.allowUnsupportedSystem = true;
}; };
inherit (pkgs) lib; inherit (pkgs) lib;
kubenix = { kubenix = {
lib = import ./lib { inherit lib pkgs; }; lib = import ./lib {inherit lib pkgs;};
evalModules = self.evalModules.${system}; evalModules = self.evalModules.${system};
modules = self.nixosModules.kubenix; modules = self.nixosModules.kubenix;
}; };
# evalModules with same interface as lib.evalModules and kubenix as # evalModules with same interface as lib.evalModules and kubenix as
# special argument # special argument
evalModules = evalModules = attrs @ {
attrs @ { module ? null module ? null,
, modules ? [ module ] modules ? [module],
, ... ...
}: }: let
let lib' = lib.extend (lib: _self: import ./lib/upstreamables.nix {inherit lib pkgs;});
lib' = lib.extend (lib: _self: import ./lib/upstreamables.nix { inherit lib pkgs; }); attrs' = builtins.removeAttrs attrs ["module"];
attrs' = builtins.removeAttrs attrs [ "module" ]; in
in
lib'.evalModules (lib.recursiveUpdate lib'.evalModules (lib.recursiveUpdate
{ {
modules = modules =
@ -60,8 +58,7 @@
}; };
} }
attrs'); attrs');
in in {
{
inherit evalModules pkgs; inherit evalModules pkgs;
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
@ -136,9 +133,9 @@
packages = packages =
inputs.flake-utils.lib.flattenTree inputs.flake-utils.lib.flattenTree
{ {
inherit (pkgs) kubernetes kubectl; inherit (pkgs) kubernetes kubectl;
} }
// { // {
cli = pkgs.callPackage ./pkgs/kubenix.nix { cli = pkgs.callPackage ./pkgs/kubenix.nix {
inherit (self.packages.${system}); inherit (self.packages.${system});
@ -152,25 +149,25 @@
# the submodules module currently doesn't evaluate: # the submodules module currently doesn't evaluate:
# error: No module found name/latest # error: No module found name/latest
# not sure how important that documentation is a this time # not sure how important that documentation is a this time
self.nixosModules.kubenix [ "submodule" "submodules" ]); self.nixosModules.kubenix ["submodule" "submodules"]);
}).options; })
.options;
}; };
} }
// import ./jobs { // import ./jobs {
inherit pkgs; inherit pkgs;
}; };
checks = checks = let
let wasSuccess = suite:
wasSuccess = suite: if suite.success
if suite.success then pkgs.runCommandNoCC "testing-suite-config-assertions-for-${suite.name}-succeeded" {} "echo success > $out"
then pkgs.runCommandNoCC "testing-suite-config-assertions-for-${suite.name}-succeeded" { } "echo success > $out" else pkgs.runCommandNoCC "testing-suite-config-assertions-for-${suite.name}-failed" {} "exit 1";
else pkgs.runCommandNoCC "testing-suite-config-assertions-for-${suite.name}-failed" { } "exit 1"; examples = import ./docs/content/examples;
examples = import ./docs/content/examples; mkK8STests = attrs:
mkK8STests = attrs: (import ./tests {inherit evalModules;})
(import ./tests { inherit evalModules; }) ({registry = "docker.io/gatehub";} // attrs);
({ registry = "docker.io/gatehub"; } // attrs); in
in
{ {
# TODO: access "success" derivation with nice testing utils for nice output # TODO: access "success" derivation with nice testing utils for nice output
testing = wasSuccess examples.testing.config.testing; testing = wasSuccess examples.testing.config.testing;
@ -178,7 +175,7 @@
// builtins.listToAttrs (builtins.map // builtins.listToAttrs (builtins.map
(v: { (v: {
name = "test-k8s-${builtins.replaceStrings ["."] ["_"] v}"; name = "test-k8s-${builtins.replaceStrings ["."] ["_"] v}";
value = wasSuccess (mkK8STests { k8sVersion = v; }); value = wasSuccess (mkK8STests {k8sVersion = v;});
}) })
(import ./versions.nix).versions); (import ./versions.nix).versions);
} }