summary refs log tree commit diff
path: root/nixos/modules/services/databases
diff options
context:
space:
mode:
authorJulien Malka <julien@malka.sh>2023-10-15 10:36:04 +0200
committerYureka <yuka@yuka.dev>2023-10-16 10:15:30 +0200
commitc54ab7d6438d459b57442f6d823ae0ea1f16908b (patch)
treebf5d34ef1972063272fbc56837dc9bde92450184 /nixos/modules/services/databases
parentdb7ab703d0bb20977be848500fd264e27a5f816b (diff)
downloadnixpkgs-c54ab7d6438d459b57442f6d823ae0ea1f16908b.tar
nixpkgs-c54ab7d6438d459b57442f6d823ae0ea1f16908b.tar.gz
nixpkgs-c54ab7d6438d459b57442f6d823ae0ea1f16908b.tar.bz2
nixpkgs-c54ab7d6438d459b57442f6d823ae0ea1f16908b.tar.lz
nixpkgs-c54ab7d6438d459b57442f6d823ae0ea1f16908b.tar.xz
nixpkgs-c54ab7d6438d459b57442f6d823ae0ea1f16908b.tar.zst
nixpkgs-c54ab7d6438d459b57442f6d823ae0ea1f16908b.zip
nixos/ferretdb: init
Diffstat (limited to 'nixos/modules/services/databases')
-rw-r--r--nixos/modules/services/databases/ferretdb.nix79
1 files changed, 79 insertions, 0 deletions
diff --git a/nixos/modules/services/databases/ferretdb.nix b/nixos/modules/services/databases/ferretdb.nix
new file mode 100644
index 00000000000..5b2cc59d8c0
--- /dev/null
+++ b/nixos/modules/services/databases/ferretdb.nix
@@ -0,0 +1,79 @@
+{ config, pkgs, lib, ... }:
+
+with lib;
+
+let
+  cfg = config.services.ferretdb;
+in
+{
+
+  meta.maintainers = with lib.maintainers; [ julienmalka camillemndn ];
+
+  options = {
+    services.ferretdb = {
+      enable = mkEnableOption "FerretDB, an Open Source MongoDB alternative.";
+
+      package = mkOption {
+        type = types.package;
+        example = literalExpression "pkgs.ferretdb";
+        default = pkgs.ferretdb;
+        defaultText = "pkgs.ferretdb";
+        description = "FerretDB package to use.";
+      };
+
+      settings = lib.mkOption {
+        type =
+          lib.types.submodule { freeformType = with lib.types; attrsOf str; };
+        example = {
+          FERRETDB_LOG_LEVEL = "warn";
+          FERRETDB_MODE = "normal";
+        };
+        description = ''
+          Additional configuration for FerretDB, see
+          <https://docs.ferretdb.io/flags/>
+          for supported values.
+        '';
+      };
+    };
+  };
+
+  config = mkIf cfg.enable
+    {
+
+      services.ferretdb.settings = {
+        FERRETDB_HANDLER = lib.mkDefault "sqlite";
+        FERRETDB_SQLITE_URL = lib.mkDefault "file:/var/lib/ferretdb/";
+      };
+
+      systemd.services.ferretdb = {
+        description = "FerretDB";
+        after = [ "network.target" ];
+        wantedBy = [ "multi-user.target" ];
+        environment = cfg.settings;
+        serviceConfig = {
+          Type = "simple";
+          StateDirectory = "ferretdb";
+          WorkingDirectory = "/var/lib/ferretdb";
+          ExecStart = "${cfg.package}/bin/ferretdb";
+          Restart = "on-failure";
+          ProtectHome = true;
+          ProtectSystem = "strict";
+          PrivateTmp = true;
+          PrivateDevices = true;
+          ProtectHostname = true;
+          ProtectClock = true;
+          ProtectKernelTunables = true;
+          ProtectKernelModules = true;
+          ProtectKernelLogs = true;
+          ProtectControlGroups = true;
+          NoNewPrivileges = true;
+          RestrictRealtime = true;
+          RestrictSUIDSGID = true;
+          RemoveIPC = true;
+          PrivateMounts = true;
+          DynamicUser = true;
+        };
+      };
+    };
+}
+