kubenix/flake.nix

115 lines
3.7 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 = {
2022-04-02 15:40:44 -07:00
flake-compat.url = "github:edolstra/flake-compat";
flake-compat.flake = false;
2021-04-03 21:57:02 -07:00
flake-utils.url = "github:numtide/flake-utils";
2022-04-02 15:40:44 -07:00
flake-utils.inputs.nixpkgs.follows = "nixpgks";
2022-04-02 13:18:09 -07:00
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
2022-04-02 15:40:44 -07:00
2022-04-02 13:18:09 -07:00
devshell.url = "github:numtide/devshell";
2022-04-02 15:40:44 -07:00
devshell.inputs.nixpkgs.follows = "nixpkgs";
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,
2022-04-02 13:18:09 -07:00
...
} @ inputs:
2022-04-02 14:42:22 -07:00
(inputs.flake-utils.lib.eachSystem ["x86_64-linux"] (
2022-04-02 14:41:57 -07:00
#inputs.flake-utils.lib.eachDefaultSystem (
2022-04-02 12:40:35 -07:00
system: let
2022-04-02 13:32:40 -07:00
pkgs = import inputs.nixpkgs {
overlays = [
self.overlays.default
inputs.devshell.overlay
];
config.allowUnsupportedSystem = true;
inherit system;
};
2022-04-02 13:43:57 -07:00
inherit (pkgs) lib;
2021-05-28 20:26:17 -05:00
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};
2022-04-02 13:18:09 -07:00
modules = self.nixosModules.kubenix;
2021-05-28 20:26:17 -05:00
};
# 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
2022-04-02 13:41:07 -07:00
lib' = lib.extend (lib: _self: import ./lib/upstreamables.nix {inherit lib pkgs;});
2022-04-02 12:40:35 -07:00
attrs' = builtins.removeAttrs attrs ["module"];
in
2021-05-28 20:26:17 -05:00
lib'.evalModules (lib.recursiveUpdate
{
2022-04-02 13:28:07 -07:00
modules =
modules
++ [
{
2022-04-02 16:12:17 -07:00
config._module.args = {
2022-04-02 13:28:07 -07:00
inherit pkgs;
name = "default";
};
}
];
specialArgs = {
inherit kubenix;
inherit pkgs;
};
2021-05-28 20:26:17 -05:00
}
attrs');
2022-04-02 12:40:35 -07:00
in {
2022-04-02 14:41:57 -07:00
inherit evalModules pkgs;
2021-05-28 20:26:17 -05:00
2022-04-02 12:40:35 -07:00
jobs = import ./jobs {inherit pkgs;};
2021-05-28 20:26:17 -05:00
2022-04-02 15:31:14 -07:00
devShells.default = import ./devshell {inherit pkgs inputs;};
2022-04-02 13:18:09 -07:00
packages = inputs.flake-utils.lib.flattenTree {
inherit (pkgs) kubernetes kubectl;
};
2021-05-28 20:26:17 -05:00
checks = let
wasSuccess = suite:
2022-04-02 13:43:57 -07:00
if suite.success
2021-05-28 20:26:17 -05:00
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:
2022-08-11 23:07:20 -04:00
(import ./docs/examples {inherit evalModules;})
2022-04-02 14:42:22 -07:00
({registry = "docker.io/gatehub";} // attrs);
2022-04-02 14:07:05 -07:00
mkK8STests = attrs:
(import ./tests {inherit evalModules;})
2022-04-02 14:42:22 -07:00
({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;
2022-04-02 14:07:05 -07:00
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";});
2022-04-02 15:09:21 -07:00
tests-k8s-1_23 = wasSuccess (mkK8STests {k8sVersion = "1.23";});
2022-08-11 23:18:44 -04:00
tests-k8s-1_24 = wasSuccess (mkK8STests {k8sVersion = "1.24";});
2021-05-28 20:26:17 -05:00
};
}
))
2022-04-02 12:40:35 -07:00
// {
2022-04-02 13:18:09 -07:00
nixosModules.kubenix = import ./modules;
2022-04-02 13:41:07 -07:00
overlays.default = _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 13:18:09 -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
}