wip: figuring out how to do multiple envs and stuff

This commit is contained in:
2024-10-14 07:51:07 +02:00
parent 768cb1ddef
commit 91b56423f2
10 changed files with 131 additions and 37 deletions
+2 -2
View File
@@ -1,9 +1,9 @@
{ lib, config, ... }: { lib, config, ... }:
let let
cfg = config.services.atlantis; cfg = config.apps.atlantis;
in in
{ {
options.services.atlantis = { options.apps.atlantis = {
enable = lib.mkOption { enable = lib.mkOption {
type = lib.types.bool; type = lib.types.bool;
default = true; default = true;
-18
View File
@@ -4,22 +4,4 @@
./atlantis.nix ./atlantis.nix
./openfga.nix ./openfga.nix
]; ];
config = {
services = {
atlantis = {
enable = true;
autoSync = true;
prune = false;
};
openfga = {
enable = true;
autoSync = true;
prune = false;
};
};
};
} }
+19 -5
View File
@@ -1,18 +1,31 @@
{ lib, applib, config, ... }: { lib, applib, config, ... }:
let let
cfg = config.services.openfga; cfg = config.apps.openfga;
env = config.apps.env;
namespace = "${env}-openfga"; namespace = "${env}-openfga";
env = "prod";
project = "aux"; project = "aux";
cluster = "https://kubernetes.default.svc"; cluster = "https://kubernetes.default.svc";
vs = ../values/openfga;
# values = applib.appValues ../values/openfga {};
values = with lib;
attrsets.mergeAttrsList (lists.flatten [
(kube.fromYAML (builtins.readFile "${vs}/values.yaml"))
(kube.fromYAML (builtins.readFile "${vs}/values-${env}.yaml"))
[ cfg.values ]
]);
kustomize = r:
if r.kind == "Job" then
lib.attrsets.recursiveUpdate r { spec.backoffLimit = 2; }
else r;
values = lib.attrsets.recursiveUpdate {} cfg.values;
in in
{ {
options.services.openfga = applib.appOptions {}; options.apps.openfga = applib.appOptions {};
config = applib.appConfig cfg "${cfg.env}-openfga" { config = applib.appConfig cfg "${env}-openfga" {
inherit namespace; inherit namespace;
inherit project; inherit project;
@@ -26,6 +39,7 @@ in
version = "0.2.12"; version = "0.2.12";
chartHash = "sha256-7yLcw9/oNPvCePrtTJwKAG88t0Ym5Dl/S83Gz+gQdDU="; chartHash = "sha256-7yLcw9/oNPvCePrtTJwKAG88t0Ym5Dl/S83Gz+gQdDU=";
}; };
transformer = rs: builtins.map (x: kustomize x) rs;
}; };
annotations = {}; annotations = {};
+13
View File
@@ -0,0 +1,13 @@
_:
{
config = {
apps = {
env = "prod";
autoSync = false;
prune = false;
atlantis.enable = true;
openfga.enable = true;
};
};
}
+17
View File
@@ -0,0 +1,17 @@
_:
{
config = {
apps = {
env = "staging";
autoSync = true;
prune = true;
atlantis = {
enable = true;
autoSync = true;
prune = false;
};
openfga.enable = true;
};
};
}
+6 -5
View File
@@ -44,19 +44,20 @@
applib = import ./modules/lib.nix { inherit pkgs; }; applib = import ./modules/lib.nix { inherit pkgs; };
in in
{ {
nixidyEnvs = { nixidyEnvs = nixidy.lib.mkEnvs {
prod = nixidy.lib.mkEnv {
inherit pkgs; inherit pkgs;
extraSpecialArgs = { inherit applib; }; extraSpecialArgs = { inherit applib; };
charts = nixhelm.chartsDerivations.${system}; charts = nixhelm.chartsDerivations.${system};
modules = [ modules = [
./modules ./modules
./apps ./apps
./policies/oceanbox/network ./policies
# ./policies/oceanbox/kyverno
]; ];
envs = {
prod.modules = [ ./envs/prod.nix ];
staging.modules = [ ./envs/staging.nix ];
};
}; };
};
checks = { checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run { pre-commit-check = pre-commit-hooks.lib.${system}.run {
+2 -2
View File
@@ -12,6 +12,6 @@ build target=default:
switch target=default: switch target=default:
nix run .#nixidy -- switch .#{{target}} nix run .#nixidy -- switch .#{{target}}
generate target=default: generate:
nix build .#generators.cilium nix build .#generators.cilium
# nix build .#generators.kyverno nix build .#generators.kyverno
+40 -5
View File
@@ -1,6 +1,41 @@
{ lib, ... }: { lib, config, ... }:
let
cfg = config.apps;
in
{ {
imports = [ ]; imports = [];
options.apps = with lib; {
env = mkOption {
type = types.string;
default = "prod";
description = "Enable";
};
autoSync = mkOption {
type = types.bool;
default = true;
description = "Auto sync";
};
prune = mkOption {
type = types.bool;
default = false;
description = "Prune";
};
selfHeal = mkOption {
type = types.bool;
default = false;
description = "Self-heal";
};
serverSideDiff = mkOption {
type = types.bool;
default = true;
description = "Enable server-side diffing";
};
};
config = { config = {
nixidy = { nixidy = {
@@ -20,9 +55,9 @@
defaults = { defaults = {
syncPolicy = { syncPolicy = {
autoSync = { autoSync = {
enabled = true; enabled = cfg.autoSync;
prune = false; prune = cfg.prune;
selfHeal = false; selfHeal = cfg.selfHeal;
}; };
}; };
+25
View File
@@ -25,6 +25,24 @@
description = "Enable server-side diffing"; description = "Enable server-side diffing";
}; };
namespace = mkOption {
type = types.string;
default = null;
description = "Namespace";
};
project = mkOption {
type = types.string;
default = "default";
description = "Project";
};
cluster = mkOption {
type = types.string;
default = "https://kubernetes.default.svc";
description = "Cluster";
};
values = mkOption { values = mkOption {
type = types.attrsOf types.anything; type = types.attrsOf types.anything;
default = {}; default = {};
@@ -55,4 +73,11 @@
}; };
in mkIf cfg.enable { applications.${name} = app; }; in mkIf cfg.enable { applications.${name} = app; };
appValues = with pkgs.lib; vs: values:
attrsets.mergeAttrsList (lists.flatten [
(lib.kube.fromYAML (builtins.readFile "${vs}/values.yaml"))
(lib.kube.fromYAML (builtins.readFile "${vs}/values-${env}.yaml"))
[ values ]
]);
} }
+7
View File
@@ -0,0 +1,7 @@
{ ... }:
{
imports = [
./oceanbox/network
# ./oceanbox/kyverno
];
}