mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-10-26 08:48:38 +03:00
nixos/atuin: fix database.createLocally
behaviour
Co-authored-by: Andrew Marshall <andrew@johnandrewmarshall.com>
This commit is contained in:
parent
025b5d4875
commit
fd01b3f59c
@ -1,14 +1,12 @@
|
|||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
let
|
let
|
||||||
|
inherit (lib) mkOption types mdDoc mkIf;
|
||||||
cfg = config.services.atuin;
|
cfg = config.services.atuin;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
services.atuin = {
|
services.atuin = {
|
||||||
enable = mkEnableOption (mdDoc "Enable server for shell history sync with atuin");
|
enable = lib.mkEnableOption (mdDoc "Enable server for shell history sync with atuin");
|
||||||
|
|
||||||
openRegistration = mkOption {
|
openRegistration = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
@ -50,16 +48,28 @@ in
|
|||||||
createLocally = mkOption {
|
createLocally = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = true;
|
default = true;
|
||||||
description = lib.mdDoc "Create the database and database user locally.";
|
description = mdDoc "Create the database and database user locally.";
|
||||||
|
};
|
||||||
|
|
||||||
|
uri = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "postgresql:///atuin?host=/run/postgresql";
|
||||||
|
example = "postgresql://atuin@localhost:5432/atuin";
|
||||||
|
description = mdDoc "URI to the database";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
assertions = [
|
||||||
|
{
|
||||||
|
assertion = cfg.database.createLocally -> config.services.postgresql.enable;
|
||||||
|
message = "Postgresql must be enabled to create a local database";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
# enable postgres to host atuin db
|
services.postgresql = mkIf cfg.database.createLocally {
|
||||||
services.postgresql = {
|
|
||||||
enable = true;
|
enable = true;
|
||||||
ensureUsers = [{
|
ensureUsers = [{
|
||||||
name = "atuin";
|
name = "atuin";
|
||||||
@ -73,7 +83,7 @@ in
|
|||||||
systemd.services.atuin = {
|
systemd.services.atuin = {
|
||||||
description = "atuin server";
|
description = "atuin server";
|
||||||
requires = lib.optionals cfg.database.createLocally [ "postgresql.service" ];
|
requires = lib.optionals cfg.database.createLocally [ "postgresql.service" ];
|
||||||
after = [ "network.target" ] ++ lib.optionals cfg.database.createLocally [ "postgresql.service" ] ;
|
after = [ "network.target" ] ++ lib.optionals cfg.database.createLocally [ "postgresql.service" ];
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
@ -87,14 +97,13 @@ in
|
|||||||
ATUIN_HOST = cfg.host;
|
ATUIN_HOST = cfg.host;
|
||||||
ATUIN_PORT = toString cfg.port;
|
ATUIN_PORT = toString cfg.port;
|
||||||
ATUIN_MAX_HISTORY_LENGTH = toString cfg.maxHistoryLength;
|
ATUIN_MAX_HISTORY_LENGTH = toString cfg.maxHistoryLength;
|
||||||
ATUIN_OPEN_REGISTRATION = boolToString cfg.openRegistration;
|
ATUIN_OPEN_REGISTRATION = lib.boolToString cfg.openRegistration;
|
||||||
ATUIN_DB_URI = mkIf cfg.database.createLocally "postgresql:///atuin";
|
ATUIN_DB_URI = cfg.database.uri;
|
||||||
ATUIN_PATH = cfg.path;
|
ATUIN_PATH = cfg.path;
|
||||||
ATUIN_CONFIG_DIR = "/run/atuin"; # required to start, but not used as configuration is via environment variables
|
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 ];
|
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@ in
|
|||||||
server =
|
server =
|
||||||
{ ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
|
services.postgresql.enable = true;
|
||||||
|
|
||||||
services.atuin = {
|
services.atuin = {
|
||||||
enable = true;
|
enable = true;
|
||||||
port = testPort;
|
port = testPort;
|
||||||
|
Loading…
Reference in New Issue
Block a user