94 lines
2.2 KiB
Nix
94 lines
2.2 KiB
Nix
{ pkgs, kube }:
|
|
{
|
|
appOptions = opts: with pkgs.lib; {
|
|
enable = mkOption {
|
|
type = types.bool;
|
|
default = true;
|
|
description = "Enable";
|
|
};
|
|
|
|
autoSync = mkOption {
|
|
type = types.bool;
|
|
default = true;
|
|
description = "Auto sync";
|
|
};
|
|
|
|
prune = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = "Prune";
|
|
};
|
|
|
|
serverSideDiff = mkOption {
|
|
type = types.bool;
|
|
default = true;
|
|
description = "Enable server-side diffing";
|
|
};
|
|
|
|
name = mkOption {
|
|
type = types.nullOr types.str;
|
|
default = null;
|
|
description = "Application name";
|
|
};
|
|
|
|
namespace = mkOption {
|
|
type = types.nullOr types.str;
|
|
default = null;
|
|
description = "Namespace";
|
|
};
|
|
|
|
project = mkOption {
|
|
type = types.str;
|
|
default = "default";
|
|
description = "Project";
|
|
};
|
|
|
|
cluster = mkOption {
|
|
type = types.str;
|
|
default = "https://kubernetes.default.svc";
|
|
description = "Cluster";
|
|
};
|
|
|
|
values = mkOption {
|
|
type = types.attrsOf types.anything;
|
|
default = {};
|
|
description = "Values";
|
|
};
|
|
} // opts;
|
|
|
|
appConfig = cfg: name: conf:
|
|
with pkgs.lib;
|
|
let
|
|
app = conf // {
|
|
name = if builtins.isNull cfg.name then name else cfg.name;
|
|
project = cfg.project;
|
|
|
|
destination.server = cfg.cluster;
|
|
|
|
createNamespace = true;
|
|
|
|
compareOptions = {
|
|
serverSideDiff = cfg.serverSideDiff;
|
|
};
|
|
|
|
syncPolicy = {
|
|
syncOptions = {
|
|
applyOutOfSyncOnly = true;
|
|
};
|
|
|
|
autoSync = mkIf cfg.autoSync {
|
|
prune = cfg.prune;
|
|
selfHeal = false;
|
|
};
|
|
};
|
|
} // (if builtins.isNull cfg.namespace then {} else { namespace = cfg.namespace; });
|
|
in mkIf cfg.enable { applications.${name} = app; };
|
|
|
|
appValues = with pkgs.lib; { env, base, extraValues}:
|
|
attrsets.mergeAttrsList (lists.flatten [
|
|
(kube.fromYAML (builtins.readFile "${base}/values.yaml"))
|
|
(kube.fromYAML (builtins.readFile "${base}/values-${env}.yaml"))
|
|
[ extraValues ]
|
|
]);
|
|
}
|