diff options
author | h7x4 <h7x4@nani.wtf> | 2023-07-26 22:20:53 +0200 |
---|---|---|
committer | Yt <happysalada@tuta.io> | 2023-08-01 18:17:37 +0800 |
commit | fd01b3f59c33fa4cd17cad256df92798f076678f (patch) | |
tree | b6a5fbf579a662d58b187b9eec19ba04f63de499 /nixos/modules/services/misc/atuin.nix | |
parent | 025b5d48756828c1beec7a55b0007d62dd390c2c (diff) | |
download | nixpkgs-fd01b3f59c33fa4cd17cad256df92798f076678f.tar nixpkgs-fd01b3f59c33fa4cd17cad256df92798f076678f.tar.gz nixpkgs-fd01b3f59c33fa4cd17cad256df92798f076678f.tar.bz2 nixpkgs-fd01b3f59c33fa4cd17cad256df92798f076678f.tar.lz nixpkgs-fd01b3f59c33fa4cd17cad256df92798f076678f.tar.xz nixpkgs-fd01b3f59c33fa4cd17cad256df92798f076678f.tar.zst nixpkgs-fd01b3f59c33fa4cd17cad256df92798f076678f.zip |
nixos/atuin: fix `database.createLocally` behaviour
Co-authored-by: Andrew Marshall <andrew@johnandrewmarshall.com>
Diffstat (limited to 'nixos/modules/services/misc/atuin.nix')
-rw-r--r-- | nixos/modules/services/misc/atuin.nix | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/nixos/modules/services/misc/atuin.nix b/nixos/modules/services/misc/atuin.nix index 202bd4dfca1..8b6821ab892 100644 --- a/nixos/modules/services/misc/atuin.nix +++ b/nixos/modules/services/misc/atuin.nix @@ -1,14 +1,12 @@ { config, pkgs, lib, ... }: - -with lib; - let + inherit (lib) mkOption types mdDoc mkIf; cfg = config.services.atuin; in { options = { 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 { type = types.bool; @@ -50,16 +48,28 @@ in createLocally = mkOption { type = types.bool; 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 { - - # enable postgres to host atuin db - services.postgresql = { + assertions = [ + { + assertion = cfg.database.createLocally -> config.services.postgresql.enable; + message = "Postgresql must be enabled to create a local database"; + } + ]; + + services.postgresql = mkIf cfg.database.createLocally { enable = true; ensureUsers = [{ name = "atuin"; @@ -73,7 +83,7 @@ in systemd.services.atuin = { description = "atuin server"; 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" ]; serviceConfig = { @@ -87,14 +97,13 @@ in ATUIN_HOST = cfg.host; ATUIN_PORT = toString cfg.port; ATUIN_MAX_HISTORY_LENGTH = toString cfg.maxHistoryLength; - ATUIN_OPEN_REGISTRATION = boolToString cfg.openRegistration; - ATUIN_DB_URI = mkIf cfg.database.createLocally "postgresql:///atuin"; + ATUIN_OPEN_REGISTRATION = lib.boolToString cfg.openRegistration; + ATUIN_DB_URI = cfg.database.uri; ATUIN_PATH = cfg.path; 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 ]; - }; } |