From 200730320f4d42e4d6236b3dcf63d3cbf4225d22 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Sun, 13 Aug 2023 21:09:10 -0400 Subject: [PATCH] Init CockroachDB Service --- examples/cockroachdb/devenv.nix | 7 +++++ examples/cockroachdb/devenv.yaml | 3 ++ src/modules/services/cockroachdb.nix | 43 ++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 examples/cockroachdb/devenv.nix create mode 100644 examples/cockroachdb/devenv.yaml create mode 100644 src/modules/services/cockroachdb.nix diff --git a/examples/cockroachdb/devenv.nix b/examples/cockroachdb/devenv.nix new file mode 100644 index 000000000..65a2e365e --- /dev/null +++ b/examples/cockroachdb/devenv.nix @@ -0,0 +1,7 @@ +{ ... }: + +{ + services.cockroachdb = { + enable = true; + }; +} diff --git a/examples/cockroachdb/devenv.yaml b/examples/cockroachdb/devenv.yaml new file mode 100644 index 000000000..c7cb5ceda --- /dev/null +++ b/examples/cockroachdb/devenv.yaml @@ -0,0 +1,3 @@ +inputs: + nixpkgs: + url: github:NixOS/nixpkgs/nixpkgs-unstable diff --git a/src/modules/services/cockroachdb.nix b/src/modules/services/cockroachdb.nix new file mode 100644 index 000000000..01c656be5 --- /dev/null +++ b/src/modules/services/cockroachdb.nix @@ -0,0 +1,43 @@ +{ pkgs, lib, config, ... }: + +let + cfg = config.services.cockroachdb; + types = lib.types; +in +{ + options.services.cockroachdb = { + enable = lib.mkEnableOption '' + Add CockroachDB process. + ''; + + listen_addr = lib.mkOption { + type = types.str; + default = "localhost:26257"; + description = '' + The address/hostname and port to listen on. + ''; + }; + + http_addr = lib.mkOption { + type = types.str; + default = "localhost:8080"; + description = '' + The hostname or IP address to bind to for HTTP requests. + ''; + }; + + package = lib.mkOption { + default = pkgs.cockroachdb-bin; + }; + }; + + config = lib.mkIf cfg.enable { + packages = [ cfg.package ]; + + env.COCKROACH_DATA = config.env.DEVENV_STATE + "/cockroachdb"; + + processes.cockroachdb = { + exec = "${cfg.package}/bin/cockroachdb start-single-node --insecure --listen-addr=${cfg.listen_addr} --http-addr=${cfg.http_addr} --store=path=$COCKROACH_DATA"; + }; + }; +}