diff --git a/apps/default.nix b/apps/default.nix index 3acac358..563e75cc 100644 --- a/apps/default.nix +++ b/apps/default.nix @@ -7,11 +7,19 @@ config = { services = { + atlantis = { enable = true; autoSync = true; prune = false; }; + + openfga = { + enable = true; + autoSync = true; + prune = false; + }; + }; }; } diff --git a/apps/openfga.nix b/apps/openfga.nix index 1240c260..1e1adb17 100644 --- a/apps/openfga.nix +++ b/apps/openfga.nix @@ -1,8 +1,8 @@ -{ lib, config, charts, ... }: +{ lib, applib, config, ... }: let cfg = config.services.openfga; - namespace = "openfga"; + namespace = "${env}-openfga"; env = "prod"; project = "aux"; cluster = "https://kubernetes.default.svc"; @@ -10,37 +10,15 @@ let values = lib.attrsets.recursiveUpdate {} cfg.values; in { - options.services.openfga = { - enable = lib.mkOption { - type = lib.types.bool; - default = true; - description = "Enable"; - }; - autoSync = lib.mkOption { - type = lib.types.bool; - default = true; - description = "Auto sync"; - }; - prune = lib.mkOption { - type = lib.types.bool; - default = false; - description = "Prune"; - }; - values = lib.mkOption { - type = lib.types.attrsOf lib.types.anything; - default = {}; - }; - }; + options.services.openfga = applib.appOptions {}; - config = lib.mkIf cfg.enable { - applications.openfga = { + config = applib.appConfig cfg "${cfg.env}-openfga" { inherit namespace; inherit project; - name = "${env}-openfga"; destination.server = cluster; - helm.releases.openfga = { + helm.releases."${env}-openfga" = { inherit values; chart = lib.helm.downloadHelmChart { repo = "https://openfga.github.io/helm-charts"; @@ -50,21 +28,10 @@ in }; }; - annotations = { - "argocd.argoproj.io/compare-options" = "ServerSideDiff=true"; - }; - - syncPolicy = { - syncOptions = { - applyOutOfSyncOnly = true; - }; - autoSync = lib.mkIf cfg.autoSync { - prune = cfg.prune; - selfHeal = false; + annotations = {}; + resources = { + services.poop.spec = { }; }; - - resources = {}; }; - }; } diff --git a/flake.nix b/flake.nix index 77939084..4bca7076 100644 --- a/flake.nix +++ b/flake.nix @@ -40,14 +40,14 @@ (flake-utils.lib.eachDefaultSystem ( system: let - pkgs = import nixpkgs { - inherit system; - }; + pkgs = import nixpkgs { inherit system; }; + applib = import ./modules/lib.nix { inherit pkgs; }; in { nixidyEnvs = { prod = nixidy.lib.mkEnv { inherit pkgs; + extraSpecialArgs = { inherit applib; }; charts = nixhelm.chartsDerivations.${system}; modules = [ ./modules diff --git a/modules/lib.nix b/modules/lib.nix new file mode 100644 index 00000000..ee83a9be --- /dev/null +++ b/modules/lib.nix @@ -0,0 +1,58 @@ +{ pkgs }: +{ + 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"; + }; + + values = mkOption { + type = types.attrsOf types.anything; + default = {}; + description = "Values"; + }; + } // opts; + + appConfig = cfg: name: conf: + with pkgs.lib; + let + app = conf // { + createNamespace = true; + + compareOptions = { + serverSideDiff = cfg.serverSideDiff; + }; + + syncPolicy = { + syncOptions = { + applyOutOfSyncOnly = true; + }; + + autoSync = mkIf cfg.autoSync { + prune = cfg.prune; + selfHeal = false; + }; + }; + }; + + in mkIf cfg.enable { applications.${name} = app; }; +}