···
{ config, pkgs, lib, ... }:
3
+
inherit (lib) mkOption types mdDoc mkIf;
cfg = config.services.atuin;
11
-
enable = mkEnableOption (mdDoc "Enable server for shell history sync with atuin");
9
+
enable = lib.mkEnableOption (mdDoc "Enable server for shell history sync with atuin");
openRegistration = mkOption {
···
createLocally = mkOption {
53
-
description = lib.mdDoc "Create the database and database user locally.";
51
+
description = mdDoc "Create the database and database user locally.";
56
+
default = "postgresql:///atuin?host=/run/postgresql";
57
+
example = "postgresql://atuin@localhost:5432/atuin";
58
+
description = mdDoc "URI to the database";
config = mkIf cfg.enable {
67
+
assertion = cfg.database.createLocally -> config.services.postgresql.enable;
68
+
message = "Postgresql must be enabled to create a local database";
61
-
# enable postgres to host atuin db
62
-
services.postgresql = {
72
+
services.postgresql = mkIf cfg.database.createLocally {
···
systemd.services.atuin = {
description = "atuin server";
requires = lib.optionals cfg.database.createLocally [ "postgresql.service" ];
76
-
after = [ "network.target" ] ++ lib.optionals cfg.database.createLocally [ "postgresql.service" ] ;
86
+
after = [ "network.target" ] ++ lib.optionals cfg.database.createLocally [ "postgresql.service" ];
wantedBy = [ "multi-user.target" ];
···
ATUIN_PORT = toString cfg.port;
ATUIN_MAX_HISTORY_LENGTH = toString cfg.maxHistoryLength;
90
-
ATUIN_OPEN_REGISTRATION = boolToString cfg.openRegistration;
91
-
ATUIN_DB_URI = mkIf cfg.database.createLocally "postgresql:///atuin";
100
+
ATUIN_OPEN_REGISTRATION = lib.boolToString cfg.openRegistration;
101
+
ATUIN_DB_URI = cfg.database.uri;
ATUIN_CONFIG_DIR = "/run/atuin"; # required to start, but not used as configuration is via environment variables
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];