diff options
author | Sandro <sandro.jaeckel@gmail.com> | 2022-12-16 22:38:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-16 22:38:35 +0100 |
commit | c338bf32445bc1a136a30dd3f765ac11e20ccd0f (patch) | |
tree | 095631083b8669e68b5374dddce9967a62308e05 /nixos/modules/services | |
parent | 2e24b998cea6447db29a3a1ab9578bae136541c9 (diff) | |
parent | 67b35bfcf00261bddeaf3635e8bb09d1656ce34b (diff) | |
download | nixpkgs-c338bf32445bc1a136a30dd3f765ac11e20ccd0f.tar nixpkgs-c338bf32445bc1a136a30dd3f765ac11e20ccd0f.tar.gz nixpkgs-c338bf32445bc1a136a30dd3f765ac11e20ccd0f.tar.bz2 nixpkgs-c338bf32445bc1a136a30dd3f765ac11e20ccd0f.tar.lz nixpkgs-c338bf32445bc1a136a30dd3f765ac11e20ccd0f.tar.xz nixpkgs-c338bf32445bc1a136a30dd3f765ac11e20ccd0f.tar.zst nixpkgs-c338bf32445bc1a136a30dd3f765ac11e20ccd0f.zip |
Merge pull request #205712 from devusb/atuin-server
Diffstat (limited to 'nixos/modules/services')
-rw-r--r-- | nixos/modules/services/misc/atuin.nix | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/nixos/modules/services/misc/atuin.nix b/nixos/modules/services/misc/atuin.nix new file mode 100644 index 00000000000..c94852e3aad --- /dev/null +++ b/nixos/modules/services/misc/atuin.nix @@ -0,0 +1,85 @@ +{ config, pkgs, lib, ... }: + +with lib; + +let + cfg = config.services.atuin; +in +{ + options = { + services.atuin = { + enable = mkEnableOption (mdDoc "Enable server for shell history sync with atuin."); + + openRegistration = mkOption { + type = types.bool; + default = false; + description = mdDoc "Allow new user registrations with the atuin server."; + }; + + path = mkOption { + type = types.str; + default = ""; + description = mdDoc "A path to prepend to all the routes of the server."; + }; + + host = mkOption { + type = types.str; + default = "127.0.0.1"; + description = mdDoc "The host address the atuin server should listen on."; + }; + + port = mkOption { + type = types.port; + default = 8888; + description = mdDoc "The port the atuin server should listen on."; + }; + + openFirewall = mkOption { + type = types.bool; + default = false; + description = mdDoc "Open ports in the firewall for the atuin server."; + }; + + }; + }; + + config = mkIf cfg.enable { + + # enable postgres to host atuin db + services.postgresql = { + enable = true; + ensureUsers = [{ + name = "atuin"; + ensurePermissions = { + "DATABASE atuin" = "ALL PRIVILEGES"; + }; + }]; + ensureDatabases = [ "atuin" ]; + }; + + systemd.services.atuin = { + description = "atuin server"; + after = [ "network.target" "postgresql.service" ]; + wantedBy = [ "multi-user.target" ]; + + serviceConfig = { + ExecStart = "${pkgs.atuin}/bin/atuin server start"; + RuntimeDirectory = "atuin"; + RuntimeDirectoryMode = "0700"; + DynamicUser = true; + }; + + environment = { + ATUIN_HOST = cfg.host; + ATUIN_PORT = toString cfg.port; + ATUIN_OPEN_REGISTRATION = boolToString cfg.openRegistration; + ATUIN_DB_URI = "postgresql:///atuin"; + 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 ]; + + }; +} |