kubenix/flake.nix

100 lines
3.1 KiB
Nix
Raw Normal View History

2020-12-29 11:16:27 +01:00
{
description = "Kubernetes resource builder using nix";
2021-04-03 21:57:02 -07:00
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs";
2021-05-13 01:18:12 -07:00
devshell-flake.url = "github:numtide/devshell";
2021-04-03 21:57:02 -07:00
};
2020-12-29 11:16:27 +01:00
2022-04-02 12:40:35 -07:00
outputs = {
self,
nixpkgs,
flake-utils,
devshell-flake,
}:
(flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
overlays = [
self.overlay
devshell-flake.overlay
];
2022-04-02 12:40:35 -07:00
config = {allowUnsupportedSystem = true;};
};
2021-05-28 20:26:17 -05:00
lib = pkgs.lib;
kubenix = {
2022-04-02 12:40:35 -07:00
lib = import ./lib {inherit lib pkgs;};
2021-05-28 20:26:17 -05:00
evalModules = self.evalModules.${system};
modules = self.modules;
};
# evalModules with same interface as lib.evalModules and kubenix as
# special argument
2022-04-02 12:40:35 -07:00
evalModules = attrs @ {
module ? null,
modules ? [module],
...
}: let
lib' = lib.extend (lib: self: import ./lib/upstreamables.nix {inherit lib pkgs;});
attrs' = builtins.removeAttrs attrs ["module"];
in
2021-05-28 20:26:17 -05:00
lib'.evalModules (lib.recursiveUpdate
{
inherit modules;
2022-04-02 12:40:35 -07:00
specialArgs = {inherit kubenix;};
2021-05-28 20:26:17 -05:00
args = {
inherit pkgs;
name = "default";
};
}
attrs');
2022-04-02 12:40:35 -07:00
in {
2021-05-28 20:26:17 -05:00
inherit evalModules;
2022-04-02 12:40:35 -07:00
jobs = import ./jobs {inherit pkgs;};
2021-05-28 20:26:17 -05:00
2022-04-02 12:40:35 -07:00
devShell = with pkgs;
devshell.mkShell
{imports = [(devshell.importTOML ./devshell.toml)];};
packages = flake-utils.lib.flattenTree {
inherit (pkgs) kubernetes kubectl;
};
2021-05-28 20:26:17 -05:00
checks = let
wasSuccess = suite:
if suite.success == true
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";
2022-04-02 12:40:35 -07:00
mkExamples = attrs:
(import ./examples {inherit evalModules;})
({registry = "docker.io/gatehub";} // attrs);
mkK8STests = attrs:
(import ./tests {inherit evalModules;})
({registry = "docker.io/gatehub";} // attrs);
2021-05-28 20:26:17 -05:00
in {
# TODO: access "success" derivation with nice testing utils for nice output
2022-04-02 12:40:35 -07:00
nginx-example = wasSuccess (mkExamples {}).nginx-deployment.config.testing;
tests-k8s-1_19 = wasSuccess (mkK8STests {k8sVersion = "1.19";});
tests-k8s-1_20 = wasSuccess (mkK8STests {k8sVersion = "1.20";});
tests-k8s-1_21 = wasSuccess (mkK8STests {k8sVersion = "1.21";});
2021-05-28 20:26:17 -05:00
};
}
))
2022-04-02 12:40:35 -07:00
// {
2021-05-28 20:26:17 -05:00
modules = import ./modules;
2021-04-03 21:57:02 -07:00
overlay = final: prev: {
2021-05-28 20:26:17 -05:00
kubenix.evalModules = self.evalModules.${prev.system};
2021-04-29 17:13:33 -05:00
# up to date versions of their nixpkgs equivalents
2022-04-02 12:40:35 -07:00
kubernetes =
prev.callPackage ./pkgs/applications/networking/cluster/kubernetes
{};
kubectl = prev.callPackage ./pkgs/applications/networking/cluster/kubectl {};
2021-04-03 21:57:02 -07:00
};
};
2020-12-29 11:16:27 +01:00
}