at 23.11-pre 2.5 kB view raw
1{ config, pkgs, lib, ... }: 2 3with lib; 4 5let 6 cfg = config.services.atuin; 7in 8{ 9 options = { 10 services.atuin = { 11 enable = mkEnableOption (mdDoc "Enable server for shell history sync with atuin"); 12 13 openRegistration = mkOption { 14 type = types.bool; 15 default = false; 16 description = mdDoc "Allow new user registrations with the atuin server."; 17 }; 18 19 path = mkOption { 20 type = types.str; 21 default = ""; 22 description = mdDoc "A path to prepend to all the routes of the server."; 23 }; 24 25 host = mkOption { 26 type = types.str; 27 default = "127.0.0.1"; 28 description = mdDoc "The host address the atuin server should listen on."; 29 }; 30 31 maxHistoryLength = mkOption { 32 type = types.int; 33 default = 8192; 34 description = mdDoc "The max length of each history item the atuin server should store."; 35 }; 36 37 port = mkOption { 38 type = types.port; 39 default = 8888; 40 description = mdDoc "The port the atuin server should listen on."; 41 }; 42 43 openFirewall = mkOption { 44 type = types.bool; 45 default = false; 46 description = mdDoc "Open ports in the firewall for the atuin server."; 47 }; 48 49 }; 50 }; 51 52 config = mkIf cfg.enable { 53 54 # enable postgres to host atuin db 55 services.postgresql = { 56 enable = true; 57 ensureUsers = [{ 58 name = "atuin"; 59 ensurePermissions = { 60 "DATABASE atuin" = "ALL PRIVILEGES"; 61 }; 62 }]; 63 ensureDatabases = [ "atuin" ]; 64 }; 65 66 systemd.services.atuin = { 67 description = "atuin server"; 68 after = [ "network.target" "postgresql.service" ]; 69 wantedBy = [ "multi-user.target" ]; 70 71 serviceConfig = { 72 ExecStart = "${pkgs.atuin}/bin/atuin server start"; 73 RuntimeDirectory = "atuin"; 74 RuntimeDirectoryMode = "0700"; 75 DynamicUser = true; 76 }; 77 78 environment = { 79 ATUIN_HOST = cfg.host; 80 ATUIN_PORT = toString cfg.port; 81 ATUIN_MAX_HISTORY_LENGTH = toString cfg.maxHistoryLength; 82 ATUIN_OPEN_REGISTRATION = boolToString cfg.openRegistration; 83 ATUIN_DB_URI = "postgresql:///atuin"; 84 ATUIN_PATH = cfg.path; 85 ATUIN_CONFIG_DIR = "/run/atuin"; # required to start, but not used as configuration is via environment variables 86 }; 87 }; 88 89 networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ]; 90 91 }; 92}