From ba81fba6b24ec5eb24010384bad03d8a727b0fc5 Mon Sep 17 00:00:00 2001 From: technofab Date: Sat, 13 Apr 2024 16:26:57 +0200 Subject: [PATCH] feat: add surrealdb nixlet --- flake.nix | 1 + nixlets/surrealdb/default.nix | 6 ++++ nixlets/surrealdb/deployment.nix | 56 +++++++++++++++++++++++++++++ nixlets/surrealdb/service.nix | 17 +++++++++ nixlets/surrealdb/values.nix | 60 ++++++++++++++++++++++++++++++++ 5 files changed, 140 insertions(+) create mode 100644 nixlets/surrealdb/default.nix create mode 100644 nixlets/surrealdb/deployment.nix create mode 100644 nixlets/surrealdb/service.nix create mode 100644 nixlets/surrealdb/values.nix diff --git a/flake.nix b/flake.nix index 640925d..1107a6c 100644 --- a/flake.nix +++ b/flake.nix @@ -25,6 +25,7 @@ attic = utils.mkNixlet ./nixlets/attic; postgres = utils.mkNixlet ./nixlets/postgres; tikv = utils.mkNixlet ./nixlets/tikv; + surrealdb = utils.mkNixlet ./nixlets/surrealdb; }; }; perSystem = { diff --git a/nixlets/surrealdb/default.nix b/nixlets/surrealdb/default.nix new file mode 100644 index 0000000..4fd6c52 --- /dev/null +++ b/nixlets/surrealdb/default.nix @@ -0,0 +1,6 @@ +{...}: { + imports = [ + ./deployment.nix + ./service.nix + ]; +} diff --git a/nixlets/surrealdb/deployment.nix b/nixlets/surrealdb/deployment.nix new file mode 100644 index 0000000..400d055 --- /dev/null +++ b/nixlets/surrealdb/deployment.nix @@ -0,0 +1,56 @@ +{ + values, + lib, + ... +}: { + kubernetes.resources = { + deployments."${values.uniqueName}" = { + spec = { + replicas = values.replicaCount; + selector.matchLabels.app = "${values.uniqueName}"; + template = { + metadata.labels.app = "${values.uniqueName}"; + spec = { + securityContext = { + fsGroup = 1000; + runAsUser = 1000; + runAsGroup = 1000; + }; + containers."surrealdb" = rec { + image = "${values.image.repository}:${values.image.tag}"; + imagePullPolicy = values.image.pullPolicy; + args = ["start"]; + env = [ + { + name = "SURREAL_NO_BANNER"; + value = "true"; + } + { + name = "SURREAL_PATH"; + value = values.surrealdb.path; + } + { + name = "SURREAL_LOG"; + value = values.surrealdb.log; + } + { + name = "SURREAL_BIND"; + value = "0.0.0.0:8000"; + } + ]; + envFrom = [ + {secretRef.name = "${values.uniqueName}-env";} + ]; + ports."http".containerPort = 8000; + livenessProbe.httpGet = { + path = "/health"; + port = "http"; + }; + readinessProbe = livenessProbe; + }; + }; + }; + }; + }; + }; +} diff --git a/nixlets/surrealdb/service.nix b/nixlets/surrealdb/service.nix new file mode 100644 index 0000000..9e985b9 --- /dev/null +++ b/nixlets/surrealdb/service.nix @@ -0,0 +1,17 @@ +{values, ...}: { + kubernetes.resources = { + services."${values.uniqueName}" = { + spec = { + selector.app = "${values.uniqueName}"; + ports = [ + { + name = "http"; + targetPort = "http"; + port = values.service.port; + } + ]; + type = values.service.type; + }; + }; + }; +} diff --git a/nixlets/surrealdb/values.nix b/nixlets/surrealdb/values.nix new file mode 100644 index 0000000..96b48fc --- /dev/null +++ b/nixlets/surrealdb/values.nix @@ -0,0 +1,60 @@ +{ + lib, + utils, + project, + ... +}: +with lib; { + # for some basic values see https://github.com/helm/examples/blob/4888ba8fb8180dd0c36d1e84c1fcafc6efd81532/charts/hello-world/values.yaml + options = { + replicaCount = mkOption { + type = types.int; + default = 1; + }; + image = utils.mkNestedOption { + repository = mkOption { + type = types.str; + default = "surrealdb/surrealdb"; + }; + pullPolicy = mkOption { + type = types.str; + default = "IfNotPresent"; + }; + tag = mkOption { + type = types.str; + default = "latest"; + }; + }; + service = utils.mkNestedOption { + port = mkOption { + type = types.int; + default = 8000; + }; + type = mkOption { + type = types.str; + default = "ClusterIP"; + }; + }; + surrealdb = utils.mkNestedOption { + log = mkOption { + type = types.str; + default = "info"; + }; + path = mkOption { + type = types.str; + default = "memory"; + description = '' + Path to database. + Examples: "memory", "file://", "tikv://:2379" + ''; + }; + }; + + # internal + uniqueName = mkOption { + internal = true; + type = types.str; + default = "${project}-surrealdb"; + }; + }; +}