wip: getting there, slowly

This commit is contained in:
Jonas Juselius
2024-10-14 15:47:14 +02:00
parent 372c11c31e
commit ed26ad8af2
5 changed files with 72 additions and 52 deletions
+8 -20
View File
@@ -1,21 +1,14 @@
{ lib, applib, config, ... }: { lib, config, ... }:
let let
cfg = config.apps.openfga; cfg = config.apps.openfga;
env = config.apps.env; env = config.apps.env;
namespace = "${env}-openfga";
project = "aux";
cluster = "https://kubernetes.default.svc";
vs = ../values/openfga;
# values = applib.appValues ../values/openfga {}; values = lib.apps.appValues {
inherit env;
base = ../values/openfga;
extraValues = {};
};
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: kustomize = r:
if r.kind == "Job" then if r.kind == "Job" then
lib.attrsets.recursiveUpdate r { spec.backoffLimit = 2; } lib.attrsets.recursiveUpdate r { spec.backoffLimit = 2; }
@@ -23,14 +16,9 @@ let
in in
{ {
options.apps.openfga = applib.appOptions {}; options.apps.openfga = lib.apps.appOptions {};
config = applib.appConfig cfg "${env}-openfga" {
inherit namespace;
inherit project;
destination.server = cluster;
config = lib.apps.appConfig cfg "openfga" {
helm.releases."${env}-openfga" = { helm.releases."${env}-openfga" = {
inherit values; inherit values;
chart = lib.helm.downloadHelmChart { chart = lib.helm.downloadHelmChart {
Generated
+32 -17
View File
@@ -278,22 +278,37 @@
"type": "github" "type": "github"
} }
}, },
"nix-kube-generators_3": {
"locked": {
"lastModified": 1708155396,
"narHash": "sha256-A/BIeJjiRS7sBYP6tFJa/WHDPHe7DGTCkSEKXttYeAQ=",
"owner": "farcaller",
"repo": "nix-kube-generators",
"rev": "14dbd5e5b40615937900f71d9a9851b59b4d9a88",
"type": "github"
},
"original": {
"owner": "farcaller",
"repo": "nix-kube-generators",
"type": "github"
}
},
"nixhelm": { "nixhelm": {
"inputs": { "inputs": {
"flake-utils": "flake-utils_2", "flake-utils": "flake-utils_2",
"haumea": "haumea", "haumea": "haumea",
"nix-kube-generators": "nix-kube-generators", "nix-kube-generators": "nix-kube-generators_2",
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
], ],
"poetry2nix": "poetry2nix" "poetry2nix": "poetry2nix"
}, },
"locked": { "locked": {
"lastModified": 1728522957, "lastModified": 1728868745,
"narHash": "sha256-5/2Q/aVVCgd/pL94KFnnH5h36se3UqT+oxXPTYnVjtY=", "narHash": "sha256-ZuaxkAtUL1visOmVMxgHk3j+H8/bMmm82tJfE1s35VY=",
"owner": "farcaller", "owner": "farcaller",
"repo": "nixhelm", "repo": "nixhelm",
"rev": "6fc421b792250c65aa39d121f3c67a26cc7dd2ea", "rev": "f901d2ba3ce1bd0086d50efdcce3cc76bce04d80",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -306,23 +321,22 @@
"inputs": { "inputs": {
"flake-utils": "flake-utils_4", "flake-utils": "flake-utils_4",
"kubenix": "kubenix", "kubenix": "kubenix",
"nix-kube-generators": "nix-kube-generators_2", "nix-kube-generators": "nix-kube-generators_3",
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
] ]
}, },
"locked": { "locked": {
"lastModified": 1726669031, "dirtyRev": "6e20193c95a0aaca444289d7c69f4eb329d25234-dirty",
"narHash": "sha256-iNh3jgB/vrltSUquE9Q3lbGIRqiyayglnSHtB5KbW+M=", "dirtyShortRev": "6e20193-dirty",
"owner": "arnarg", "lastModified": 1728815994,
"repo": "nixidy", "narHash": "sha256-0fNVuZdg7vNn47NBcStHzVzWfpSM2cdh7k2kiTcUal8=",
"rev": "b8abf95f1d4b1a7f5e70ffba926be571a778c540", "type": "git",
"type": "github" "url": "file:///home/jonas/src/OceanBox/nixidy"
}, },
"original": { "original": {
"owner": "arnarg", "type": "git",
"repo": "nixidy", "url": "file:///home/jonas/src/OceanBox/nixidy"
"type": "github"
} }
}, },
"nixpkgs": { "nixpkgs": {
@@ -408,11 +422,11 @@
"nixpkgs-stable": "nixpkgs-stable" "nixpkgs-stable": "nixpkgs-stable"
}, },
"locked": { "locked": {
"lastModified": 1728092656, "lastModified": 1728778939,
"narHash": "sha256-eMeCTJZ5xBeQ0f9Os7K8DThNVSo9gy4umZLDfF5q6OM=", "narHash": "sha256-WybK5E3hpGxtCYtBwpRj1E9JoiVxe+8kX83snTNaFHE=",
"owner": "cachix", "owner": "cachix",
"repo": "pre-commit-hooks.nix", "repo": "pre-commit-hooks.nix",
"rev": "1211305a5b237771e13fcca0c51e60ad47326a9a", "rev": "ff68f91754be6f3427e4986d7949e6273659be1d",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -424,6 +438,7 @@
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"nix-kube-generators": "nix-kube-generators",
"nixhelm": "nixhelm", "nixhelm": "nixhelm",
"nixidy": "nixidy", "nixidy": "nixidy",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
+10 -3
View File
@@ -6,7 +6,8 @@
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
nixidy = { nixidy = {
url = "github:arnarg/nixidy"; # url = "github:juselius/nixidy";
url = "/home/jonas/src/OceanBox/nixidy";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
@@ -20,6 +21,8 @@
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
nix-kube-generators.url = "github:farcaller/nix-kube-generators";
yaml2nix = { yaml2nix = {
url = "github:euank/yaml2nix"; url = "github:euank/yaml2nix";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
@@ -36,17 +39,21 @@
nixhelm, nixhelm,
yaml2nix, yaml2nix,
pre-commit-hooks, pre-commit-hooks,
nix-kube-generators,
}: }:
(flake-utils.lib.eachDefaultSystem ( (flake-utils.lib.eachDefaultSystem (
system: system:
let let
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
applib = import ./modules/lib.nix { inherit pkgs; }; kube = nix-kube-generators.lib { inherit pkgs; };
lib = {
apps = import ./modules/lib.nix { inherit pkgs kube;};
};
in in
{ {
nixidyEnvs = nixidy.lib.mkEnvs { nixidyEnvs = nixidy.lib.mkEnvs {
inherit pkgs; inherit pkgs;
extraSpecialArgs = { inherit applib; }; extraSpecialArgs = { inherit lib; };
charts = nixhelm.chartsDerivations.${system}; charts = nixhelm.chartsDerivations.${system};
modules = [ modules = [
./modules ./modules
+2 -2
View File
@@ -7,7 +7,7 @@ in
options.apps = with lib; { options.apps = with lib; {
env = mkOption { env = mkOption {
type = types.string; type = types.str;
default = "prod"; default = "prod";
description = "Enable"; description = "Enable";
}; };
@@ -42,7 +42,7 @@ in
target = { target = {
repository = "https://gitlab.com/oveanbox/manifests.git"; repository = "https://gitlab.com/oveanbox/manifests.git";
branch = "main"; branch = "main";
rootPath = "_manifests"; rootPath = "_manifests/${config.apps.env}";
}; };
resourceImports = [ resourceImports = [
+20 -10
View File
@@ -1,4 +1,4 @@
{ pkgs }: { pkgs, kube }:
{ {
appOptions = opts: with pkgs.lib; { appOptions = opts: with pkgs.lib; {
enable = mkOption { enable = mkOption {
@@ -25,20 +25,26 @@
description = "Enable server-side diffing"; description = "Enable server-side diffing";
}; };
name = mkOption {
type = types.nullOr types.str;
default = null;
description = "Application name";
};
namespace = mkOption { namespace = mkOption {
type = types.string; type = types.nullOr types.str;
default = null; default = null;
description = "Namespace"; description = "Namespace";
}; };
project = mkOption { project = mkOption {
type = types.string; type = types.str;
default = "default"; default = "default";
description = "Project"; description = "Project";
}; };
cluster = mkOption { cluster = mkOption {
type = types.string; type = types.str;
default = "https://kubernetes.default.svc"; default = "https://kubernetes.default.svc";
description = "Cluster"; description = "Cluster";
}; };
@@ -54,6 +60,11 @@
with pkgs.lib; with pkgs.lib;
let let
app = conf // { app = conf // {
name = if builtins.isNull cfg.name then "${cfg.env}-${name}" else cfg.name;
project = cfg.project;
destination.server = cfg.cluster;
createNamespace = true; createNamespace = true;
compareOptions = { compareOptions = {
@@ -70,14 +81,13 @@
selfHeal = false; selfHeal = false;
}; };
}; };
}; } // (if builtins.isNull cfg.namespace then {} else { namespace = cfg.namespace; });
in mkIf cfg.enable { applications.${name} = app; }; in mkIf cfg.enable { applications.${name} = app; };
appValues = with pkgs.lib; vs: values: appValues = with pkgs.lib; { env, base, extraValues}:
attrsets.mergeAttrsList (lists.flatten [ attrsets.mergeAttrsList (lists.flatten [
(lib.kube.fromYAML (builtins.readFile "${vs}/values.yaml")) (kube.fromYAML (builtins.readFile "${base}/values.yaml"))
(lib.kube.fromYAML (builtins.readFile "${vs}/values-${env}.yaml")) (kube.fromYAML (builtins.readFile "${base}/values-${env}.yaml"))
[ values ] [ extraValues ]
]); ]);
} }